more whitespace -remove trailing spaces
[civicrm-core.git] / sql / GenerateReportData.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35
36 /*******************************************************
37 * This class generates data for the schema located in Contact.sql
38 *
39 * each public method generates data for the concerned table.
40 * so for example the addContactDomain method generates and adds
41 * data to the contact_domain table
42 *
43 * Data generation is a bit tricky since the data generated
44 * randomly in one table could be used as a FKEY in another
45 * table.
46 *
47 * In order to ensure that a randomly generated FKEY matches
48 * a field in the referened table, the field in the referenced
49 * table is always generated linearly.
50 *
51 *
52 *
53 *
54 * Some numbers
55 *
56 * Domain ID's - 1 to NUM_DOMAIN
57 *
58 * Context - 3/domain
59 *
60 * Contact - 1 to NUM_CONTACT
61 * 75% - Individual
62 * 15% - Household
63 * 10% - Organization
64 *
65 * Contact to Domain distribution should be equal.
66 *
67 *
68 * Contact Individual = 1 to 0.75*NUM_CONTACT
69 *
70 * Contact Household = 0.75*NUM_CONTACT to 0.9*NUM_CONTACT
71 *
72 * Contact Organization = 0.9*NUM_CONTACT to NUM_CONTACT
73 *
74 * Contact Location = 15% for Households, 10% for Organizations, (75-(15*4))% for Individuals.
75 * (Assumption is that each household contains 4 individuals)
76 *
77 *******************************************************/
78
79 /*******************************************************
80 *
81 * Note: implication of using of mt_srand(1) in constructor
82 * The data generated will be done in a consistent manner
83 * so as to give the same data during each run (but this
84 * would involve populating the entire db at one go - since
85 * mt_srand(1) is in the constructor, if one needs to be able
86 * to get consistent random numbers then the mt_srand(1) shld
87 * be in each function that adds data to each table.
88 *
89 *******************************************************/
90
91
92 require_once '../civicrm.config.php';
93
94 require_once 'CRM/Core/Config.php';
95 require_once 'CRM/Core/Error.php';
96 require_once 'CRM/Core/I18n.php';
97
98 require_once 'CRM/Core/DAO/Address.php';
99 require_once 'CRM/Core/DAO.php';
100 require_once 'CRM/Core/DAO/Phone.php';
101 require_once 'CRM/Core/DAO/Email.php';
102 require_once 'CRM/Core/DAO/EntityTag.php';
103 require_once 'CRM/Core/DAO/Note.php';
104 require_once 'CRM/Core/DAO/Domain.php';
105
106 require_once 'CRM/Contact/DAO/Group.php';
107 require_once 'CRM/Contact/DAO/GroupContact.php';
108 require_once 'CRM/Contact/DAO/SubscriptionHistory.php';
109 require_once 'CRM/Contact/DAO/Contact.php';
110 require_once 'CRM/Contact/DAO/Relationship.php';
111 require_once 'CRM/Event/DAO/Participant.php';
112 require_once 'CRM/Contribute/DAO/ContributionSoft.php';
113 require_once 'CRM/Member/DAO/MembershipPayment.php';
114
115 /**
116 * Class CRM_GCD
117 */
118 class CRM_GCD {
119
120 /*******************************************************
121 * constants
122 *******************************************************/
123 CONST DATA_FILENAME = "sample_data.xml";
124 CONST NUM_DOMAIN = 1;
125 CONST NUM_CONTACT = 5000;
126 CONST NUM_CONTRIBUTION = 2000;
127 CONST NUM_MEMBERSHIP = 2000;
128 CONST NUM_PARTICIPANT = 2000;
129 CONST INDIVIDUAL_PERCENT = 75;
130 CONST HOUSEHOLD_PERCENT = 15;
131 CONST ORGANIZATION_PERCENT = 10;
132 CONST NUM_INDIVIDUAL_PER_HOUSEHOLD = 4;
133 CONST NUM_ACTIVITY = 150;
134
135 // relationship types from the table crm_relationship_type
136 CONST CHILD_OF = 1;
137 CONST SPOUSE_OF = 2;
138 CONST SIBLING_OF = 3;
139 CONST HEAD_OF_HOUSEHOLD = 6;
140 CONST MEMBER_OF_HOUSEHOLD = 7;
141
142
143 // location types from the table crm_location_type
144 CONST HOME = 1;
145 CONST WORK = 2;
146 CONST MAIN = 3;
147 CONST OTHER = 4;
148 CONST ADD_TO_DB = TRUE;
149 //const ADD_TO_DB=FALSE;
150 CONST DEBUG_LEVEL = 1;
151
152 /*********************************
153 * private members
154 *********************************/
155
156 // enum's from database
157 private $preferredCommunicationMethod = array('1', '2', '3', '4', '5');
158 private $contactType = array('Individual', 'Household', 'Organization');
159 private $phoneType = array('1', '2', '3', '4');
160
161 // customizable enums (foreign keys)
162 private $prefix = array(1 => 'Mrs', 2 => 'Ms', 3 => 'Mr', 4 => 'Dr');
163 private $suffix = array(1 => 'Jr', 2 => 'Sr');
164 private $gender = array(1 => 'Female', 2 => 'Male');
165 private $greetingType = array(1 => 'Dear [first]', 2 => 'Dear [prefix] [first] [last]', 3 => 'Dear [prefix] [last]');
166
167 // store domain id's
168 private $domain = array();
169
170 // store contact id's
171 private $contact = array();
172 private $individual = array();
173 private $household = array();
174 private $organization = array();
175
176
177 // store names, firstnames, street 1, street2
178 private $firstName = array();
179 private $lastName = array();
180 private $streetName = array();
181 private $supplementalAddress1 = array();
182 private $city = array();
183 private $state = array();
184 private $country = array();
185 private $addressDirection = array();
186 private $streetType = array();
187 private $emailDomain = array();
188 private $emailTLD = array();
189 private $organizationName = array();
190 private $organizationField = array();
191 private $organizationType = array();
192 private $group = array();
193 private $note = array();
194 private $activity_type = array();
195 private $module = array();
196 private $callback = array();
197 private $party_registration = array();
198 private $degree = array();
199 private $school = array();
200
201 // stores the strict individual id and household id to individual id mapping
202 private $strictIndividual = array();
203 private $householdIndividual = array();
204
205 // sample data in xml format
206 private $sampleData = NULL;
207
208 // private vars
209 private $numIndividual = 0;
210 private $numHousehold = 0;
211 private $numOrganization = 0;
212 private $numStrictIndividual = 0;
213
214 private $CSC = array(
215 // united states
216 1228 => array(
217 // california
218 1004 => array('San Francisco', 'Los Angeles', 'Palo Alto'),
219 // new york
220 1031 => array('New York', 'Albany'),
221 ),
222 // india
223 1101 => array(
224 // maharashtra
225 1113 => array('Mumbai', 'Pune', 'Nasik'),
226 // karnataka
227 1114 => array('Bangalore', 'Mangalore', 'Udipi'),
228 ),
229 // poland
230 1172 => array(
231 // mazowieckie
232 1115 => array('Warszawa', 'PÅ‚ock'),
233 // pomorskie
234 1116 => array('Gdańsk', 'Gdynia'),
235 ),
236 );
237
238 private $groupMembershipStatus = array('Added', 'Removed', 'Pending');
239 private $subscriptionHistoryMethod = array('Admin', 'Email');
240
241 /*********************************
242 * private methods
243 *********************************/
244
245 // get a randomly generated string
246 private function _getRandomString($size = 32) {
247 $string = "";
248
249 // get an ascii code for each character
250 for ($i = 0; $i < $size; $i++) {
251 $random_int = mt_rand(65, 122);
252 if (($random_int < 97) && ($random_int > 90)) {
253 // if ascii code between 90 and 97 substitute with space
254 $random_int = 32;
255 }
256 $random_char = chr($random_int);
257 $string .= $random_char;
258 }
259 return $string;
260 }
261
262 /**
263 * @return string
264 */
265 private function _getRandomChar() {
266 return chr(mt_rand(65, 90));
267 }
268
269 /**
270 * @return int
271 */
272 private function getRandomBoolean() {
273 return mt_rand(0, 1);
274 }
275
276 /**
277 * @param $array1
278 *
279 * @return mixed
280 */
281 private function _getRandomElement(&$array1) {
282 return $array1[mt_rand(1, count($array1)) - 1];
283 }
284
285 /**
286 * @param $array1
287 *
288 * @return int
289 */
290 private function _getRandomIndex(&$array1) {
291 return mt_rand(1, count($array1));
292 }
293
294
295 // country state city combo
296 /**
297 * @return array
298 */
299 private function _getRandomCSC() {
300 $array1 = array();
301
302 // $c = array_rand($this->CSC);
303 $c = 1228;
304
305 // the state array now
306 $s = array_rand($this->CSC[$c]);
307
308 // the city
309 $ci = array_rand($this->CSC[$c][$s]);
310 $city = $this->CSC[$c][$s][$ci];
311
312 $array1[] = $c;
313 $array1[] = $s;
314 $array1[] = $city;
315
316 return $array1;
317 }
318
319 /**
320 * Generate a random date.
321 *
322 * If both $startDate and $endDate are defined generate
323 * date between them.
324 *
325 * If only startDate is specified then date generated is
326 * between startDate + 1 year.
327 *
328 * if only endDate is specified then date generated is
329 * between endDate - 1 year.
330 *
331 * if none are specified - date is between today - 1year
332 * and today
333 *
334 * @param int $startDate Start Date in Unix timestamp
335 * @param int $endDate End Date in Unix timestamp
336 * @access private
337 *
338 * @return string randomly generated date in the format "Ymd"
339 *
340 */
341 private function _getRandomDate($startDate = 0, $endDate = 0) {
342
343 // number of seconds per year
344 // $numSecond = 31536000;
345 // number of seconds for 2 year
346 $numSecond = 63072000;
347
348 $dateFormat = "Ymdhis";
349 $today = time();
350
351 // both are defined
352 if ($startDate && $endDate) {
353 return date($dateFormat, mt_rand($startDate, $endDate));
354 }
355
356 // only startDate is defined
357 if ($startDate) {
358 // $nextYear = mktime(0, 0, 0, date("m", $startDate), date("d", $startDate), date("Y")+1);
359 return date($dateFormat, mt_rand($startDate, $startDate + $numSecond));
360 }
361
362 // only endDate is defined
363 if ($startDate) {
364 return date($dateFormat, mt_rand($endDate - $numSecond, $endDate));
365 }
366
367 // none are defined
368 return date($dateFormat, mt_rand($today - $numSecond, $today));
369 }
370
371
372 // insert data into db's
373 /**
374 * @param $dao
375 */
376 private function _insert(&$dao) {
377 if (self::ADD_TO_DB) {
378 if (!$dao->insert()) {
379 echo "ERROR INSERT: " . mysql_error() . "\n";
380 print_r($dao);
381 exit(1);
382 }
383 }
384 }
385
386 // update data into db's
387 /**
388 * @param $dao
389 */
390 private function _update($dao) {
391 if (self::ADD_TO_DB) {
392 if (!$dao->update()) {
393 echo "ERROR UPDATE: " . mysql_error() . "\n";
394 print_r($dao);
395 exit(1);
396 }
397 }
398 }
399
400 /**
401 * Insert a note
402 *
403 * Helper function which randomly populates "note" and
404 * "date_modified" and inserts it.
405 *
406 * @param CRM_DAO_Note DAO object for Note
407 * @access private
408 *
409 * @return none
410 *
411 */
412 private function _insertNote($note) {
413 $note->note = $this->_getRandomElement($this->note);
414 $note->modified_date = $this->_getRandomDate();
415 $this->_insert($note);
416 }
417
418 /*******************************************************
419 *
420 * Start of public functions
421 *
422 *******************************************************/
423 // constructor
424 function __construct() {
425
426 // initialize all the vars
427 $this->numIndividual = self::INDIVIDUAL_PERCENT * self::NUM_CONTACT / 100;
428 $this->numHousehold = self::HOUSEHOLD_PERCENT * self::NUM_CONTACT / 100;
429 $this->numOrganization = self::ORGANIZATION_PERCENT * self::NUM_CONTACT / 100;
430 $this->numStrictIndividual = $this->numIndividual - ($this->numHousehold * self::NUM_INDIVIDUAL_PER_HOUSEHOLD);
431 }
432
433 public function parseDataFile() {
434
435 $sampleData = simplexml_load_file(self::DATA_FILENAME);
436
437 // first names
438 foreach ($sampleData->first_names->first_name as $first_name) {
439 $this->firstName[] = trim($first_name);
440 }
441
442 // last names
443 foreach ($sampleData->last_names->last_name as $last_name) {
444 $this->lastName[] = trim($last_name);
445 }
446
447 // street names
448 foreach ($sampleData->street_names->street_name as $street_name) {
449 $this->streetName[] = trim($street_name);
450 }
451
452 // supplemental address 1
453 foreach ($sampleData->supplemental_addresses_1->supplemental_address_1 as $supplemental_address_1) {
454 $this->supplementalAddress1[] = trim($supplemental_address_1);
455 }
456
457 // cities
458 foreach ($sampleData->cities->city as $city) {
459 $this->city[] = trim($city);
460 }
461
462 // address directions
463 foreach ($sampleData->address_directions->address_direction as $address_direction) {
464 $this->addressDirection[] = trim($address_direction);
465 }
466
467 // street types
468 foreach ($sampleData->street_types->street_type as $street_type) {
469 $this->streetType[] = trim($street_type);
470 }
471
472 // email domains
473 foreach ($sampleData->email_domains->email_domain as $email_domain) {
474 $this->emailDomain[] = trim($email_domain);
475 }
476
477 // email top level domain
478 foreach ($sampleData->email_tlds->email_tld as $email_tld) {
479 $this->emailTLD[] = trim($email_tld);
480 }
481
482 // organization name
483 foreach ($sampleData->organization_names->organization_name as $organization_name) {
484 $this->organization_name[] = trim($organization_name);
485 }
486
487 // organization field
488 foreach ($sampleData->organization_fields->organization_field as $organization_field) {
489 $this->organizationField[] = trim($organization_field);
490 }
491
492 // organization type
493 foreach ($sampleData->organization_types->organization_type as $organization_type) {
494 $this->organizationType[] = trim($organization_type);
495 }
496
497 // group
498 foreach ($sampleData->groups->group as $group) {
499 $this->group[] = trim($group);
500 }
501
502 // notes
503 foreach ($sampleData->notes->note as $note) {
504 $this->note[] = trim($note);
505 }
506
507 // activity type
508 foreach ($sampleData->activity_types->activity_type as $activity_type) {
509 $this->activity_type[] = trim($activity_type);
510 }
511
512
513 // module
514 foreach ($sampleData->modules->module as $module) {
515 $this->module[] = trim($module);
516 }
517
518 // callback
519 foreach ($sampleData->callbacks->callback as $callback) {
520 $this->callback[] = trim($callback);
521 }
522
523 // custom data - party registration
524 foreach ($sampleData->party_registrations->party_registration as $party_registration) {
525 $this->party_registration[] = trim($party_registration);
526 }
527
528 // custom data - degrees
529 foreach ($sampleData->degrees->degree as $degree) {
530 $this->degree[] = trim($degree);
531 }
532
533 // custom data - schools
534 foreach ($sampleData->schools->school as $school) {
535 $this->school[] = trim($school);
536 }
537
538 // custom data - issue
539 foreach ($sampleData->issue->status as $status) {
540 $this->issue[] = trim($status);
541 }
542
543 // custom data - gotv
544 require_once 'CRM/Core/BAO/CustomOption.php';
545 foreach ($sampleData->gotv->status as $status) {
546 $this->gotv[] = CRM_Core_DAO::VALUE_SEPARATOR . trim($status) . CRM_Core_DAO::VALUE_SEPARATOR;
547 }
548
549 // custom data - marital_status
550 foreach ($sampleData->marital_status->status as $status) {
551 $this->marital_status[] = trim($status);
552 }
553 }
554
555 /**
556 * @param $id
557 *
558 * @return string
559 */
560 public function getContactType($id) {
561 if (in_array($id, $this->individual)) {
562 return 'Individual';
563 }
564 if (in_array($id, $this->household)) {
565 return 'Household';
566 }
567 if (in_array($id, $this->organization)) {
568 return 'Organization';
569 }
570 }
571
572
573 public function initDB() {
574 $config = CRM_Core_Config::singleton();
575 }
576
577 /*******************************************************
578 *
579 * this function creates arrays for the following
580 *
581 * domain id
582 * contact id
583 * contact_location id
584 * contact_contact_location id
585 * contact_email uuid
586 * contact_phone_uuid
587 * contact_instant_message uuid
588 * contact_relationship uuid
589 * contact_task uuid
590 * contact_note uuid
591 *
592 *******************************************************/
593 public function initID() {
594
595 // may use this function in future if needed to get
596 // a consistent pattern of random numbers.
597
598 // get the domain and contact id arrays
599 $this->domain = range(1, self::NUM_DOMAIN);
600 shuffle($this->domain);
601 $this->contact = range(2, self::NUM_CONTACT + 1);
602 shuffle($this->contact);
603
604 // get the individual, household and organizaton contacts
605 $offset = 0;
606 $this->individual = array_slice($this->contact, $offset, $this->numIndividual);
607 $offset += $this->numIndividual;
608 $this->household = array_slice($this->contact, $offset, $this->numHousehold);
609 $offset += $this->numHousehold;
610 $this->organization = array_slice($this->contact, $offset, $this->numOrganization);
611
612 // get the strict individual contacts (i.e individual contacts not belonging to any household)
613 $this->strictIndividual = array_slice($this->individual, 0, $this->numStrictIndividual);
614
615 // get the household to individual mapping array
616 $this->householdIndividual = array_diff($this->individual, $this->strictIndividual);
617 $this->householdIndividual = array_chunk($this->householdIndividual, self::NUM_INDIVIDUAL_PER_HOUSEHOLD);
618 $this->householdIndividual = array_combine($this->household, $this->householdIndividual);
619 }
620
621 /*******************************************************
622 *
623 * addDomain()
624 *
625 * This method adds NUM_DOMAIN domains and then adds NUM_REVISION
626 * revisions for each domain with the latest revision being the last one..
627 *
628 *******************************************************/
629 public function addDomain() {
630
631 /* Add a location for domain 1 */
632
633 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
634 // $this->_addLocation(self::MAIN, 1, true);
635
636 $domain = new CRM_Core_DAO_Domain();
637 for ($id = 2; $id <= self::NUM_DOMAIN; $id++) {
638 // domain name is pretty simple. it is "Domain $id"
639 $domain->name = "Domain $id";
640 $domain->description = "Description $id";
641 $domain->contact_name = $this->randomName();
642
643 // insert domain
644 $this->_insert($domain);
645 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
646 // $this->_addLocation(self::MAIN, $id, true);
647 }
648 }
649
650 /**
651 * @return string
652 */
653 public function randomName() {
654 $prefix = $this->_getRandomIndex($this->prefix);
655 $first_name = ucfirst($this->_getRandomElement($this->firstName));
656 $middle_name = ucfirst($this->_getRandomChar());
657 $last_name = ucfirst($this->_getRandomElement($this->lastName));
658 $suffix = $this->_getRandomIndex($this->suffix);
659
660 return $this->prefix[$prefix] . " $first_name $middle_name $last_name " . $this->suffix[$suffix];
661 }
662
663 /*******************************************************
664 *
665 * addContact()
666 *
667 * This method adds data to the contact table
668 *
669 * id - from $contact
670 * contact_type 'Individual' 'Household' 'Organization'
671 * preferred_communication (random 1 to 3)
672 *
673 *******************************************************/
674 public function addContact() {
675
676 // add contacts
677 $contact = new CRM_Contact_DAO_Contact();
678
679 for ($id = 1; $id <= self::NUM_CONTACT; $id++) {
680 $contact->contact_type = $this->getContactType($id + 1);
681 $contact->do_not_phone = mt_rand(0, 1);
682 $contact->do_not_email = mt_rand(0, 1);
683 $contact->do_not_post = mt_rand(0, 1);
684 $contact->do_not_trade = mt_rand(0, 1);
685 $contact->preferred_communication_method = $this->_getRandomElement($this->preferredCommunicationMethod);
686 $this->_insert($contact);
687 }
688 }
689
690 /*******************************************************
691 *
692 * addIndividual()
693 *
694 * This method adds individual's data to the contact table
695 *
696 * The following fields are generated and added.
697 *
698 * contact_uuid - individual
699 * contact_rid - latest one
700 * first_name 'First Name $contact_uuid'
701 * middle_name 'Middle Name $contact_uuid'
702 * last_name 'Last Name $contact_uuid'
703 * job_title 'Job Title $contact_uuid'
704 * greeting_type - randomly select from the enum values
705 * custom_greeting - "custom greeting $contact_uuid'
706 *
707 *******************************************************/
708 public function addIndividual() {
709
710 $contact = new CRM_Contact_DAO_Contact();
711
712 for ($id = 1; $id <= $this->numIndividual; $id++) {
713 $contact->first_name = ucfirst($this->_getRandomElement($this->firstName));
714 $contact->middle_name = ucfirst($this->_getRandomChar());
715 $contact->last_name = ucfirst($this->_getRandomElement($this->lastName));
716 $contact->prefix_id = $this->_getRandomIndex($this->prefix);
717 $contact->suffix_id = $this->_getRandomIndex($this->suffix);
718 $contact->greeting_type_id = $this->_getRandomIndex($this->greetingType);
719 $contact->gender_id = $this->_getRandomIndex($this->gender);
720 $contact->birth_date = date("Ymd", mt_rand(0, time()));
721 $contact->is_deceased = mt_rand(0, 1);
722
723 $contact->id = $this->individual[($id - 1)];
724
725 // also update the sort name for the contact id.
726 $contact->display_name = trim($this->prefix[$contact->prefix_id] . " $contact->first_name $contact->middle_name $contact->last_name " . $this->suffix[$contact->suffix_id]);
727 $contact->sort_name = $contact->last_name . ', ' . $contact->first_name;
728 $contact->hash = crc32($contact->sort_name);
729 $this->_update($contact);
730 }
731 }
732
733 /*******************************************************
734 *
735 * addHousehold()
736 *
737 * This method adds household's data to the contact table
738 *
739 * The following fields are generated and added.
740 *
741 * contact_uuid - household_individual
742 * contact_rid - latest one
743 * household_name 'household $contact_uuid primary contact $primary_contact_uuid'
744 * nick_name 'nick $contact_uuid'
745 * primary_contact_uuid = $household_individual[$contact_uuid][0];
746 *
747 *******************************************************/
748 public function addHousehold() {
749
750 $contact = new CRM_Contact_DAO_Contact();
751 for ($id = 1; $id <= $this->numHousehold; $id++) {
752 $cid = $this->household[($id - 1)];
753 $contact->primary_contact_id = $this->householdIndividual[$cid][0];
754
755 // get the last name of the primary contact id
756 $individual = new CRM_Contact_DAO_Contact();
757 $individual->id = $contact->primary_contact_id;
758 $individual->find(TRUE);
759 $firstName = $individual->first_name;
760 $lastName = $individual->last_name;
761
762 // need to name the household and nick name appropriately
763 $contact->household_name = "$firstName $lastName" . "'s home";
764 $contact->nick_name = "$lastName" . "'s home";
765
766 $contact->id = $this->household[($id - 1)];
767 // need to update the sort name for the main contact table
768 $contact->display_name = $contact->sort_name = $contact->household_name;
769 $contact->hash = crc32($contact->sort_name);
770 $this->_update($contact);
771 }
772 }
773
774 /*******************************************************
775 *
776 * addOrganization()
777 *
778 * This method adds organization data to the contact table
779 *
780 * The following fields are generated and added.
781 *
782 * contact_uuid - organization
783 * contact_rid - latest one
784 * organization_name 'organization $contact_uuid'
785 * legal_name 'legal $contact_uuid'
786 * nick_name 'nick $contact_uuid'
787 * sic_code 'sic $contact_uuid'
788 * primary_contact_id - random individual contact uuid
789 *
790 *******************************************************/
791 public function addOrganization() {
792
793 $contact = new CRM_Contact_DAO_Contact();
794
795 for ($id = 1; $id <= $this->numOrganization; $id++) {
796 $contact->id = $this->organization[($id - 1)];
797 $name = $this->_getRandomElement($this->organization_name) . " " . $this->_getRandomElement($this->organization_field) . " " . $this->_getRandomElement($this->organization_type);
798 $contact->organization_name = $name;
799 $contact->primary_contact_id = $this->_getRandomElement($this->strict_individual);
800
801 // need to update the sort name for the main contact table
802 $contact->display_name = $contact->sort_name = $contact->organization_name;
803 $contact->hash = crc32($contact->sort_name);
804 $this->_update($contact);
805 }
806 }
807
808 /*******************************************************
809 *
810 * addRelationship()
811 *
812 * This method adds data to the contact_relationship table
813 *
814 * it adds the following fields
815 *
816 *******************************************************/
817 public function addRelationship() {
818
819 $relationship = new CRM_Contact_DAO_Relationship();
820
821 // all active for now.
822 $relationship->is_active = 1;
823
824 foreach ($this->householdIndividual as $household_id => $household_member) {
825 // add child_of relationship
826 // 2 for each child
827 $relationship->relationship_type_id = self::CHILD_OF;
828 $relationship->contact_id_a = $household_member[2];
829 $relationship->contact_id_b = $household_member[0];
830 $this->_insert($relationship);
831 $relationship->contact_id_a = $household_member[3];
832 $relationship->contact_id_b = $household_member[0];
833 $this->_insert($relationship);
834 $relationship->contact_id_a = $household_member[2];
835 $relationship->contact_id_b = $household_member[1];
836 $this->_insert($relationship);
837 $relationship->contact_id_a = $household_member[3];
838 $relationship->contact_id_b = $household_member[1];
839 $this->_insert($relationship);
840
841 // add spouse_of relationship 1 for both the spouses
842 $relationship->relationship_type_id = self::SPOUSE_OF;
843 $relationship->contact_id_a = $household_member[1];
844 $relationship->contact_id_b = $household_member[0];
845 $this->_insert($relationship);
846
847 // add sibling_of relationship 1 for both the siblings
848 $relationship->relationship_type_id = self::SIBLING_OF;
849 $relationship->contact_id_a = $household_member[3];
850 $relationship->contact_id_b = $household_member[2];
851 $this->_insert($relationship);
852
853 // add head_of_household relationship 1 for head of house
854 $relationship->relationship_type_id = self::HEAD_OF_HOUSEHOLD;
855 $relationship->contact_id_a = $household_member[0];
856 $relationship->contact_id_b = $household_id;
857 $this->_insert($relationship);
858
859 // add member_of_household relationship 3 for all other members
860 $relationship->relationship_type_id = self::MEMBER_OF_HOUSEHOLD;
861 $relationship->contact_id_a = $household_member[1];
862 $this->_insert($relationship);
863 $relationship->contact_id_a = $household_member[2];
864 $this->_insert($relationship);
865 $relationship->contact_id_a = $household_member[3];
866 $this->_insert($relationship);
867 }
868 }
869
870 /*******************************************************
871 *
872 * addLocation()
873 *
874 * This method adds data to the location table
875 *
876 *******************************************************/
877 public function addLocation() {
878 // strict individuals
879 foreach ($this->strictIndividual as $contactId) {
880 $this->_addLocation(self::HOME, $contactId);
881 }
882
883 //household
884 foreach ($this->household as $contactId) {
885 $this->_addLocation(self::HOME, $contactId);
886 }
887
888 //organization
889 foreach ($this->organization as $contactId) {
890 $this->_addLocation(self::MAIN, $contactId);
891 }
892
893 // some individuals.
894 $someIndividual = array_diff($this->individual, $this->strictIndividual);
895 $someIndividual = array_slice($someIndividual, 0, (int)(75 * ($this->numIndividual - $this->numStrictIndividual) / 100));
896 foreach ($someIndividual as $contactId) {
897 $this->_addLocation(self::HOME, $contactId, FALSE, TRUE);
898 }
899 }
900
901 /**
902 * @param $locationTypeId
903 * @param $contactId
904 * @param bool $domain
905 * @param bool $isPrimary
906 */
907 private function _addLocation($locationTypeId, $contactId, $domain = FALSE, $isPrimary = TRUE) {
908 $this->_addAddress($locationTypeId, $contactId, $isPrimary);
909
910 // add two phones for each location
911 $this->_addPhone($locationTypeId, $contactId, '1', $isPrimary);
912 $this->_addPhone($locationTypeId, $contactId, '2', FALSE);
913
914 // need to get sort name to generate email id
915 $contact = new CRM_Contact_DAO_Contact();
916 $contact->id = $contactId;
917 $contact->find(TRUE);
918 // get the sort name of the contact
919 $sortName = $contact->sort_name;
920 if (!empty($sortName)) {
921 // add 2 email for each location
922 for ($emailId = 1; $emailId <= 2; $emailId++) {
923 $this->_addEmail($locationTypeId, $contactId, $sortName, ($emailId == 1) && $isPrimary);
924 }
925 }
926 }
927
928 /**
929 * @param $locationTypeId
930 * @param $contactId
931 * @param bool $isPrimary
932 * @param null $locationBlockID
933 * @param int $offset
934 */
935 private function _addAddress($locationTypeId, $contactId, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
936 $addressDAO = new CRM_Core_DAO_Address();
937
938 // add addresses now currently we are adding only 1 address for each location
939 $addressDAO->location_type_id = $locationTypeId;
940 $addressDAO->contact_id = $contactId;
941 $addressDAO->is_primary = $isPrimary;
942
943 $addressDAO->street_number = mt_rand(1, 1000);
944 $addressDAO->street_number_suffix = ucfirst($this->_getRandomChar());
945 $addressDAO->street_number_predirectional = $this->_getRandomElement($this->addressDirection);
946 $addressDAO->street_name = ucwords($this->_getRandomElement($this->streetName));
947 $addressDAO->street_type = $this->_getRandomElement($this->streetType);
948 $addressDAO->street_number_postdirectional = $this->_getRandomElement($this->addressDirection);
949 $addressDAO->street_address = $addressDAO->street_number_predirectional . " " . $addressDAO->street_number . $addressDAO->street_number_suffix . " " . $addressDAO->street_name . " " . $addressDAO->street_type . " " . $addressDAO->street_number_postdirectional;
950 $addressDAO->supplemental_address_1 = ucwords($this->_getRandomElement($this->supplementalAddress1));
951
952 // some more random skips
953 // hack add lat / long for US based addresses
954 list($addressDAO->country_id, $addressDAO->state_province_id, $addressDAO->city,
955 $addressDAO->postal_code, $addressDAO->geo_code_1, $addressDAO->geo_code_2
956 ) = self::getZipCodeInfo();
957
958 //$addressDAO->county_id = 1;
959
960 $this->_insert($addressDAO);
961 }
962
963 /**
964 * @param $sortName
965 *
966 * @return mixed
967 */
968 private function _sortNameToEmail($sortName) {
969 $email = preg_replace("([^a-zA-Z0-9_-]*)", "", $sortName);
970 return $email;
971 }
972
973 /**
974 * @param $locationTypeId
975 * @param $contactId
976 * @param $phoneType
977 * @param bool $isPrimary
978 * @param null $locationBlockID
979 * @param int $offset
980 */
981 private function _addPhone($locationTypeId, $contactId, $phoneType, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
982 if ($contactId % 3) {
983 $phone = new CRM_Core_DAO_Phone();
984 $phone->location_type_id = $locationTypeId;
985 $phone->contact_id = $contactId;
986 $phone->is_primary = $isPrimary;
987 $phone->phone = mt_rand(11111111, 99999999);
988 $phone->phone_type_id = $phoneType;
989 $this->_insert($phone);
990 }
991 }
992
993 /**
994 * @param $locationTypeId
995 * @param $contactId
996 * @param $sortName
997 * @param bool $isPrimary
998 * @param null $locationBlockID
999 * @param int $offset
1000 */
1001 private function _addEmail($locationTypeId, $contactId, $sortName, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
1002 if ($contactId % 2) {
1003 $email = new CRM_Core_DAO_Email();
1004 $email->location_type_id = $locationTypeId;
1005 $email->contact_id = $contactId;
1006 $email->is_primary = $isPrimary;
1007
1008 $emailName = $this->_sortNameToEmail($sortName);
1009 $emailDomain = $this->_getRandomElement($this->emailDomain);
1010 $tld = $this->_getRandomElement($this->emailTLD);
1011 $email->email = strtolower($emailName . "@" . $emailDomain . "." . $tld);
1012 $this->_insert($email);
1013 }
1014 }
1015
1016 /*******************************************************
1017 *
1018 * addTagEntity()
1019 *
1020 * This method populates the crm_entity_tag table
1021 *
1022 *******************************************************/
1023 public function addEntityTag() {
1024
1025 $entity_tag = new CRM_Core_DAO_EntityTag();
1026
1027 // add categories 1,2,3 for Organizations.
1028 for ($i = 0; $i < $this->numOrganization; $i += 2) {
1029 $org_id = $this->organization[$i];
1030 // echo "org_id = $org_id\n";
1031 $entity_tag->contact_id = $this->organization[$i];
1032 $entity_tag->tag_id = mt_rand(1, 3);
1033 $this->_insert($entity_tag);
1034 }
1035
1036 // add categories 4,5 for Individuals.
1037 for ($i = 0; $i < $this->numIndividual; $i += 2) {
1038 $entity_tag->contact_id = $this->individual[$i];
1039 if (($entity_tag->contact_id) % 3) {
1040 $entity_tag->tag_id = mt_rand(4, 5);
1041 $this->_insert($entity_tag);
1042 }
1043 else {
1044 // some of the individuals are in both categories (4 and 5).
1045 $entity_tag->tag_id = 4;
1046 $this->_insert($entity_tag);
1047 $entity_tag->tag_id = 5;
1048 $this->_insert($entity_tag);
1049 }
1050 }
1051 }
1052
1053 /*******************************************************
1054 *
1055 * addGroup()
1056 *
1057 * This method populates the crm_entity_tag table
1058 *
1059 *******************************************************/
1060 public function addGroup() {
1061 // add the 3 groups first
1062 $numGroup = count($this->group);
1063 require_once 'CRM/Contact/BAO/Group.php';
1064 for ($i = 0; $i < $numGroup; $i++) {
1065 $group = new CRM_Contact_BAO_Group();
1066 $group->name = $this->group[$i];
1067 $group->title = $this->group[$i];
1068 $group->group_type = "\ 11\ 12\ 1";
1069 $group->visibility = 'Public Pages';
1070 $group->is_active = 1;
1071 $group->save();
1072 $group->buildClause();
1073 $group->save();
1074 }
1075
1076 // 60 are for newsletter
1077 for ($i = 0; $i < 60; $i++) {
1078 $groupContact = new CRM_Contact_DAO_GroupContact();
1079 // newsletter subscribers
1080 $groupContact->group_id = 2;
1081 $groupContact->contact_id = $this->individual[$i];
1082 // membership status
1083 $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus);
1084
1085
1086 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1087 $subscriptionHistory->contact_id = $groupContact->contact_id;
1088
1089 $subscriptionHistory->group_id = $groupContact->group_id;
1090 $subscriptionHistory->status = $groupContact->status;
1091 // method
1092 $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod);
1093 $subscriptionHistory->date = $this->_getRandomDate();
1094 if ($groupContact->status != 'Pending') {
1095 $this->_insert($groupContact);
1096 }
1097 $this->_insert($subscriptionHistory);
1098 }
1099
1100 // 15 volunteers
1101 for ($i = 0; $i < 15; $i++) {
1102 $groupContact = new CRM_Contact_DAO_GroupContact();
1103 // Volunteers
1104 $groupContact->group_id = 3;
1105 $groupContact->contact_id = $this->individual[$i + 60];
1106 // membership status
1107 $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus);
1108
1109 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1110 $subscriptionHistory->contact_id = $groupContact->contact_id;
1111 $subscriptionHistory->group_id = $groupContact->group_id;
1112 $subscriptionHistory->status = $groupContact->status;
1113 // method
1114 $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod);
1115 $subscriptionHistory->date = $this->_getRandomDate();
1116
1117 if ($groupContact->status != 'Pending') {
1118 $this->_insert($groupContact);
1119 }
1120 $this->_insert($subscriptionHistory);
1121 }
1122
1123 // 8 advisory board group
1124 for ($i = 0; $i < 8; $i++) {
1125 $groupContact = new CRM_Contact_DAO_GroupContact();
1126 // advisory board group
1127 $groupContact->group_id = 4;
1128 $groupContact->contact_id = $this->individual[$i * 7];
1129 // membership status
1130 $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus);
1131
1132 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1133 $subscriptionHistory->contact_id = $groupContact->contact_id;
1134 $subscriptionHistory->group_id = $groupContact->group_id;
1135 $subscriptionHistory->status = $groupContact->status;
1136 // method
1137 $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod);
1138 $subscriptionHistory->date = $this->_getRandomDate();
1139
1140 if ($groupContact->status != 'Pending') {
1141 $this->_insert($groupContact);
1142 }
1143 $this->_insert($subscriptionHistory);
1144 }
1145
1146 //In this function when we add groups that time we are cache the contact fields
1147 //But at the end of setup we are appending sample custom data, so for consistency
1148 //reset the cache.
1149 require_once 'CRM/Core/BAO/Cache.php';
1150 CRM_Core_BAO_Cache::deleteGroup('contact fields');
1151 }
1152
1153 /*******************************************************
1154 *
1155 * addNote()
1156 *
1157 * This method populates the crm_note table
1158 *
1159 *******************************************************/
1160 public function addNote() {
1161
1162 $note = new CRM_Core_DAO_Note();
1163 $note->entity_table = 'civicrm_contact';
1164 $note->contact_id = 1;
1165
1166 for ($i = 0; $i < self::NUM_CONTACT; $i++) {
1167 $note->entity_id = $this->contact[$i];
1168 if ($this->contact[$i] % 5 || $this->contact[$i] % 3 || $this->contact[$i] % 2) {
1169 $this->_insertNote($note);
1170 }
1171 }
1172 }
1173
1174 /*******************************************************
1175 *
1176 * addActivity()
1177 *
1178 * This method populates the crm_activity_history table
1179 *
1180 *******************************************************/
1181 public function addActivity() {
1182 $contactDAO = new CRM_Contact_DAO_Contact();
1183 $contactDAO->contact_type = 'Individual';
1184 $contactDAO->selectAdd();
1185 $contactDAO->selectAdd('id');
1186 $contactDAO->orderBy('sort_name');
1187 $contactDAO->find();
1188
1189 $count = 0;
1190 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
1191
1192 while ($contactDAO->fetch()) {
1193 if ($count++ > 2) {
1194 break;
1195 }
1196 for ($i = 0; $i < self::NUM_ACTIVITY; $i++) {
1197 $activityDAO = new CRM_Activity_DAO_Activity();
1198 $activityDAO->source_contact_id = $contactDAO->id;
1199 $activityTypeID = mt_rand(7, 10);
1200
1201 $activityDAO->activity_type_id = $activityTypeID;
1202 $activityDAO->subject = "Subject for $activity[$activityTypeID]";
1203 $activityDAO->activity_date_time = $this->_getRandomDate();
1204 $activityDAO->duration = mt_rand(1, 6);
1205 $activityDAO->status_id = 2;
1206 $this->_insert($activityDAO);
1207
1208 $activityContactDAO = new CRM_Activity_DAO_ActivityContact();
1209 $activityContactDAO->activity_id = $activityDAO->id;
1210 $activityContactDAO->contact_id = mt_rand(1, 101);
1211 $activityContactDAO->record_type_id = CRM_Utils_Array::key('Activity Source', $activityContacts);
1212 $this->_insert($activityContactDAO);
1213
1214 if (in_array($activityTypeID, array(
1215 6, 9))) {
1216 $activityTargetDAO = new CRM_Activity_DAO_ActivityContact();
1217 $activityTargetDAO->activity_id = $activityDAO->id;
1218 $activityTargetDAO->contact_id = mt_rand(1, 101);
1219 $activityTargetDAO->record_type_id = CRM_Utils_Array::key('Activity Targets', $activityContacts);
1220 $this->_insert($activityTargetDAO);
1221 }
1222
1223 if ($activityTypeID == 7) {
1224 $activityAssignmentDAO = new CRM_Activity_DAO_ActivityContact();
1225 $activityAssignmentDAO->activity_id = $activityDAO->id;
1226 $activityAssignmentDAO->contact_id = mt_rand(1, 101);
1227 $activityAssignmentDAO->record_type_id = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
1228 $this->_insert($activityAssignmentDAO);
1229 }
1230 }
1231 }
1232 }
1233
1234 /**
1235 * @return array
1236 */
1237 static function getZipCodeInfo() {
1238 $stateID = mt_rand(1000, 5132);
1239 $offset = mt_rand(1, 4132);
1240
1241 $query = "SELECT id, country_id from civicrm_state_province LIMIT $offset, 1";
1242 $dao = new CRM_Core_DAO();
1243 $dao->query($query);
1244 while ($dao->fetch()) {
1245 return array($dao->country_id, $dao->id);
1246 }
1247
1248 return array();
1249 }
1250
1251 /**
1252 * @param $zipCode
1253 *
1254 * @return array
1255 */
1256 static function getLatLong($zipCode) {
1257 $query = "http://maps.google.com/maps?q=$zipCode&output=js";
1258 $userAgent = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0";
1259
1260 $ch = curl_init();
1261 curl_setopt($ch, CURLOPT_URL, $query);
1262 curl_setopt($ch, CURLOPT_HEADER, FALSE);
1263 curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
1264 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1265
1266 // grab URL and pass it to the browser
1267 $outstr = curl_exec($ch);
1268
1269 // close CURL resource, and free up system resources
1270 curl_close($ch);
1271
1272 $preg = "/'(<\?xml.+?)',/s";
1273 preg_match($preg, $outstr, $matches);
1274 if ($matches[1]) {
1275 $xml = simplexml_load_string($matches[1]);
1276 $attributes = $xml->center->attributes();
1277 if (!empty($attributes)) {
1278 return array((float ) $attributes['lat'], (float ) $attributes['lng']);
1279 }
1280 }
1281 return array(NULL, NULL);
1282 }
1283
1284 function addMembershipType() {
1285 $organizationDAO = new CRM_Contact_DAO_Contact();
1286 $organizationDAO->id = 5;
1287 $organizationDAO->find(TRUE);
1288 $contact_id = $organizationDAO->contact_id;
1289
1290 $membershipType = "INSERT INTO civicrm_membership_type
1291 (name, description, member_of_contact_id, financial_type_id, minimum_fee, duration_unit, duration_interval, period_type, fixed_period_start_day, fixed_period_rollover_day, relationship_type_id, relationship_direction, visibility, weight, is_active)
1292 VALUES
1293 ('General', 'Regular annual membership.', " . $contact_id . ", 3, 100, 'year', 1, 'rolling',null, null, 7, 'b_a', 'Public', 1, 1),
1294 ('Student', 'Discount membership for full-time students.', " . $contact_id . ", 1, 50, 'year', 1, 'rolling', null, null, 7, 'b_a', 'Public', 2, 1),
1295 ('Lifetime', 'Lifetime membership.', " . $contact_id . ", 2, 1200, 'lifetime', 1, 'rolling', null, null, 7, 'b_a', 'Admin', 3, 1);
1296 ";
1297 CRM_Core_DAO::executeQuery($membershipType, CRM_Core_DAO::$_nullArray);
1298 }
1299
1300 function addMembership() {
1301 $contact = new CRM_Contact_DAO_Contact();
1302 $contact->query("SELECT id FROM civicrm_contact where contact_type = 'Individual'");
1303 while ($contact->fetch()) {
1304 $contacts[] = $contact->id;
1305 }
1306 shuffle($contacts);
1307
1308 $randomContacts = array_slice($contacts, 0, 350);
1309
1310 $sources = array('Payment', 'Donation', 'Check');
1311 $membershipTypes = array(2, 1);
1312 $membershipTypeNames = array('Student', 'General');
1313 $statuses = array(3, 4);
1314
1315 $membership = "
1316 INSERT INTO civicrm_membership
1317 (contact_id, membership_type_id, join_date, start_date, end_date, source, status_id)
1318 VALUES
1319 ";
1320 $activity = "
1321 INSERT INTO civicrm_activity
1322 (source_contact_id, source_record_id, activity_type_id, subject, activity_date_time, duration, location, phone_id, phone_number, details, priority_id,parent_id, is_test, status_id)
1323 VALUES
1324 ";
1325
1326 foreach ($randomContacts as $count => $dontCare) {
1327 $source = self::_getRandomElement($sources);
1328 $acititySourceId = $count + 1;
1329 if ((($count + 1) % 11 == 0)) {
1330 // lifetime membership, status can be anything
1331 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1332 $membership .= "( {$randomContacts[$count]}, 3, '{$startDate}', '{$startDate}', null, '{$source}', 1)";
1333 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'Lifetime', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1334 }
1335 elseif (($count + 1) % 5 == 0) {
1336 // Grace or expired, memberhsip type is random of 1 & 2
1337 $randId = array_rand($membershipTypes);
1338 $membershipType = self::_getRandomElement($membershipTypes);
1339 $startDate = date('Y-m-d', mktime(0, 0, 0,
1340 date('m'),
1341 (date('d') - ($count * ($randId + 1) * ($randId + 1) * ($randId + 1))),
1342 (date('Y') - ($randId + 1))
1343 ));
1344 $partOfDate = explode('-', $startDate);
1345 $endDate = date('Y-m-d', mktime(0, 0, 0,
1346 $partOfDate[1],
1347 ($partOfDate[2] - 1),
1348 ($partOfDate[0] + ($randId + 1))
1349 ));
1350 $membership .= "( {$randomContacts[$count]}, {$membershipType}, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', {$statuses[$randId]})";
1351 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, '{$membershipTypeNames[$randId]}', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1352 }
1353 elseif (($count + 1) % 2 == 0) {
1354 // membership type 2
1355 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1356 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), (date('Y') + 1)));
1357 $membership .= "( {$randomContacts[$count]}, 2, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1358 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'Student', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1359 }
1360 else {
1361 // membership type 1
1362 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1363 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), (date('Y') + 2)));
1364 $membership .= "( {$randomContacts[$count]}, 1, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1365 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'General', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1366 }
1367
1368 if ($count != 349) {
1369 $membership .= ",";
1370 $activity .= ",";
1371 }
1372 }
1373
1374 CRM_Core_DAO::executeQuery($membership, CRM_Core_DAO::$_nullArray);
1375
1376 CRM_Core_DAO::executeQuery($activity, CRM_Core_DAO::$_nullArray);
1377 }
1378
1379 /**
1380 * @param $date
1381 *
1382 * @return string
1383 */
1384 static function repairDate($date) {
1385 $dropArray = array('-' => '', ':' => '', ' ' => '');
1386 return strtr($date, $dropArray);
1387 }
1388
1389 function addMembershipLog() {
1390 $membership = new CRM_Member_DAO_Membership();
1391 $membership->query("SELECT id FROM civicrm_membership");
1392 while ($membership->fetch()) {
1393 $ids[] = $membership->id;
1394 }
1395 require_once 'CRM/Member/DAO/MembershipLog.php';
1396 foreach ($ids as $id) {
1397 $membership = new CRM_Member_DAO_Membership();
1398 $membership->id = $id;
1399 $membershipLog = new CRM_Member_DAO_MembershipLog();
1400 if ($membership->find(TRUE)) {
1401 $membershipLog->membership_id = $membership->id;
1402 $membershipLog->status_id = $membership->status_id;
1403 $membershipLog->start_date = self::repairDate($membership->start_date);
1404 $membershipLog->end_date = self::repairDate($membership->end_date);
1405 $membershipLog->modified_id = $membership->contact_id;
1406 $membershipLog->modified_date = date("Ymd");
1407 $membershipLog->save();
1408 }
1409 $membershipLog = NULL;
1410 }
1411 }
1412
1413 function createEvent() {
1414 $event = "INSERT INTO civicrm_address ( contact_id, location_type_id, is_primary, is_billing, street_address, street_number, street_number_suffix, street_number_predirectional, street_name, street_type, street_number_postdirectional, street_unit, supplemental_address_1, supplemental_address_2, supplemental_address_3, city, county_id, state_province_id, postal_code_suffix, postal_code, usps_adc, country_id, geo_code_1, geo_code_2, timezone)
1415 VALUES
1416 ( NULL, 1, 1, 1, 'S 14S El Camino Way E', 14, 'S', NULL, 'El Camino', 'Way', NULL, NULL, NULL, NULL, NULL, 'Collinsville', NULL, 1006, NULL, '6022', NULL, 1228, 41.8328, -72.9253, NULL),
1417 ( NULL, 1, 1, 1, 'E 11B Woodbridge Path SW', 11, 'B', NULL, 'Woodbridge', 'Path', NULL, NULL, NULL, NULL, NULL, 'Dayton', NULL, 1034, NULL, '45417', NULL, 1228, 39.7531, -84.2471, NULL),
1418 ( NULL, 1, 1, 1, 'E 581O Lincoln Dr SW', 581, 'O', NULL, 'Lincoln', 'Dr', NULL, NULL, NULL, NULL, NULL, 'Santa Fe', NULL, 1030, NULL, '87594', NULL, 1228, 35.5212, -105.982, NULL)
1419 ";
1420 CRM_Core_DAO::executeQuery($event, CRM_Core_DAO::$_nullArray);
1421
1422 $sql = "SELECT id from civicrm_address where street_address = 'S 14S El Camino Way E'";
1423 $eventAdd1 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1424 $sql = "SELECT id from civicrm_address where street_address = 'E 11B Woodbridge Path SW'";
1425 $eventAdd2 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1426 $sql = "SELECT id from civicrm_address where street_address = 'E 581O Lincoln Dr SW'";
1427 $eventAdd3 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1428
1429 $event = "INSERT INTO civicrm_email (contact_id, location_type_id, email, is_primary, is_billing, on_hold, hold_date, reset_date)
1430 VALUES
1431 (NULL, 1, 'development@example.org', 0, 0, 0, NULL, NULL),
1432 (NULL, 1, 'tournaments@example.org', 0, 0, 0, NULL, NULL),
1433 (NULL, 1, 'celebration@example.org', 0, 0, 0, NULL, NULL)
1434 ";
1435 CRM_Core_DAO::executeQuery($event, CRM_Core_DAO::$_nullArray);
1436
1437 $sql = "SELECT id from civicrm_email where email = 'development@example.org'";
1438 $eventEmail1 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1439 $sql = "SELECT id from civicrm_email where email = 'tournaments@example.org'";
1440 $eventEmail2 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1441 $sql = "SELECT id from civicrm_email where email = 'celebration@example.org'";
1442 $eventEmail3 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1443
1444 $event = "INSERT INTO civicrm_phone (contact_id, location_type_id, is_primary, is_billing, mobile_provider_id, phone, phone_type_id)
1445 VALUES
1446 (NULL, 1, 0, 0, NULL,'204 222-1000', '1'),
1447 (NULL, 1, 0, 0, NULL,'204 223-1000', '1'),
1448 (NULL, 1, 0, 0, NULL,'303 323-1000', '1')
1449 ";
1450 CRM_Core_DAO::executeQuery($event, CRM_Core_DAO::$_nullArray);
1451
1452 $sql = "SELECT id from civicrm_phone where phone = '204 222-1000'";
1453 $eventPhone1 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1454 $sql = "SELECT id from civicrm_phone where phone = '204 223-1000'";
1455 $eventPhone2 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1456 $sql = "SELECT id from civicrm_phone where phone = '303 323-1000'";
1457 $eventPhone3 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1458
1459 $event = "INSERT INTO civicrm_loc_block ( address_id, email_id, phone_id, address_2_id, email_2_id, phone_2_id)
1460 VALUES
1461 ( $eventAdd1, $eventEmail1, $eventPhone1, NULL,NULL,NULL),
1462 ( $eventAdd2, $eventEmail2, $eventPhone2, NULL,NULL,NULL),
1463 ( $eventAdd3, $eventEmail3, $eventPhone3, NULL,NULL,NULL)
1464 ";
1465
1466 CRM_Core_DAO::executeQuery($event, CRM_Core_DAO::$_nullArray);
1467
1468 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone1 AND email_id = $eventEmail1 AND address_id = $eventAdd1";
1469 $eventLok1 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1470 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone2 AND email_id = $eventEmail2 AND address_id = $eventAdd2";
1471 $eventLok2 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1472 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone3 AND email_id = $eventEmail3 AND address_id = $eventAdd3";
1473 $eventLok3 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1474
1475 //create event fees
1476 $optionGroup = "INSERT INTO civicrm_option_group ( name, is_reserved, is_active)
1477 VALUES
1478 ( 'civicrm_event.amount.1', 0, 1),
1479 ( 'civicrm_event.amount.2', 0, 1),
1480 ( 'civicrm_event.amount.3', 0, 1)
1481 ";
1482 CRM_Core_DAO::executeQuery($optionGroup, CRM_Core_DAO::$_nullArray);
1483
1484
1485 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.1'";
1486 $page1 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1487
1488 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.2'";
1489 $page2 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1490
1491 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.3'";
1492 $page3 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1493
1494
1495 $optionValue = "INSERT INTO civicrm_option_value (option_group_id, label, value, is_default, weight, is_optgroup, is_reserved, is_active)
1496 VALUES
1497 ($page1, 'Single', '50', 0, 1, 0, 0, 1),
1498 ($page1, 'Couple', '100', 0, 2, 0, 0, 1),
1499 ($page1, 'Family', '200', 0, 3, 0, 0, 1),
1500 ($page2, 'Bass', '25', 0, 1, 0, 0, 1),
1501 ($page2, 'Tenor', '40', 0, 2, 0, 0, 1),
1502 ($page2, 'Soprano', '50', 0, 3, 0, 0, 1),
1503 ($page3, 'Tiny-tots (ages 5-8)', '800', 0, 1, 0, 0, 1),
1504 ($page3, 'Junior Stars (ages 9-12)', '1000', 0, 2, 0, 0, 1),
1505 ($page3, 'Super Stars (ages 13-18)', '1500', 0, 3, 0, 0, 1)";
1506
1507 CRM_Core_DAO::executeQuery($optionValue, CRM_Core_DAO::$_nullArray);
1508
1509 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page1 AND civicrm_option_value.weight=2";
1510 $defaultFee1 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1511
1512 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page2 AND civicrm_option_value.weight=2";
1513 $defaultFee2 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1514
1515 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page3 AND civicrm_option_value.weight=2";
1516 $defaultFee3 = CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray);
1517
1518 $event = "INSERT INTO civicrm_event
1519 ( title, summary, description, event_type_id, participant_listing_id, is_public, start_date, end_date, is_online_registration, registration_link_text, max_participants, event_full_text, is_monetary, financial_type_id, is_map, is_active, fee_label, is_show_location, loc_block_id,intro_text, footer_text, confirm_title, confirm_text, confirm_footer_text, is_email_confirm, confirm_email_text, confirm_from_name, confirm_from_email, cc_confirm, bcc_confirm, default_fee_id, thankyou_title, thankyou_text, thankyou_footer_text, is_pay_later, pay_later_text, pay_later_receipt, is_multiple_registrations, allow_same_participant_emails )
1520 VALUES
1521 ( 'Fall Fundraiser Dinner', 'Kick up your heels at our Fall Fundraiser Dinner/Dance at Glen Echo Park! Come by yourself or bring a partner, friend or the entire family!', 'This event benefits our teen programs. Admission includes a full 3 course meal and wine or soft drinks. Grab your dancing shoes, bring the kids and come join the party!', 3, 1, 1, '2010-11-21 17:00:00', '2010-11-21 23:00:00', 1, 'Register Now', 100, 'Sorry! The Fall Fundraiser Dinner is full. Please call Jane at 204 222-1000 ext 33 if you want to be added to the waiting list.', 1, 4, 1, 1, 'Dinner Contribution', 1 ,$eventLok1,'Fill in the information below to join as at this wonderful dinner event.', NULL, 'Confirm Your Registration Information', 'Review the information below carefully.', NULL, 1, 'Contact the Development Department if you need to make any changes to your registration.', 'Fundraising Dept.', 'development@example.org', NULL, NULL, {$defaultFee1}, 'Thanks for Registering!', '<p>Thank you for your support. Your contribution will help us build even better tools.</p><p>Please tell your friends and colleagues about this wonderful event.</p>', '<p><a href=http://civicrm.org>Back to CiviCRM Home Page</a></p>', 1, 'I will send payment by check', 'Send a check payable to Our Organization within 3 business days to hold your reservation. Checks should be sent to: 100 Main St., Suite 3, San Francisco CA 94110', 0, 0 ),
1522 ( 'Summer Solstice Festival Day Concert', 'Festival Day is coming! Join us and help support your parks.', 'We will gather at noon, learn a song all together, and then join in a joyous procession to the pavilion. We will be one of many groups performing at this wonderful concert which benefits our city parks.', 5, 1, 1, '2011-06-01 12:00:00', '2011-06-01 17:00:00', 1, 'Register Now', 50, 'We have all the singers we can handle. Come to the pavilion anyway and join in from the audience.', 1, 2, NULL, 1, 'Festival Fee', 1, $eventLok2, 'Complete the form below and click Continue to register online for the festival. Or you can register by calling us at 204 222-1000 ext 22.', '', 'Confirm Your Registration Information', '', '', 1, 'This email confirms your registration. If you have questions or need to change your registration - please do not hesitate to call us.', 'Event Dept.', 'events@example.org', '', NULL, {$defaultFee2}, 'Thanks for Your Joining In!', '<p>Thank you for your support. Your participation will help build new parks.</p><p>Please tell your friends and colleagues about the concert.</p>', '<p><a href=http://civicrm.org>Back to CiviCRM Home Page</a></p>', 0, NULL, NULL, 1, 0 ),
1523 ( 'Rain-forest Cup Youth Soccer Tournament', 'Sign up your team to participate in this fun tournament which benefits several Rain-forest protection groups in the Amazon basin.', 'This is a FYSA Sanctioned Tournament, which is open to all USSF/FIFA affiliated organizations for boys and girls in age groups: U9-U10 (6v6), U11-U12 (8v8), and U13-U17 (Full Sided).', 3, 1, 1, '2011-12-27 07:00:00', '2011-12-29 17:00:00', 1, 'Register Now', 500, 'Sorry! All available team slots for this tournament have been filled. Contact Jill Futbol for information about the waiting list and next years event.', 1, 4, NULL, 1, 'Tournament Fees',1, $eventLok3, 'Complete the form below to register your team for this year''s tournament.', '<em>A Soccer Youth Event</em>', 'Review and Confirm Your Registration Information', '', '<em>A Soccer Youth Event</em>', 1, 'Contact our Tournament Director for eligibility details.', 'Tournament Director', 'tournament@example.org', '', NULL, {$defaultFee3}, 'Thanks for Your Support!', '<p>Thank you for your support. Your participation will help save thousands of acres of rainforest.</p>', '<p><a href=http://civicrm.org>Back to CiviCRM Home Page</a></p>', 0, NULL, NULL, 0, 0 )
1524 ";
1525 CRM_Core_DAO::executeQuery($event, CRM_Core_DAO::$_nullArray);
1526 }
1527
1528 function addParticipant() {
1529 // add participant
1530 $participant = new CRM_Event_DAO_Participant();
1531
1532 for ($id = 1; $id <= self::NUM_PARTICIPANT; $id++) {
1533 $participant->contact_id = mt_rand(1, self::NUM_CONTACT);
1534 $participant->event_id = mt_rand(1, 3);
1535 $participant->status_id = mt_rand(1, 5);
1536 $participant->role_id = mt_rand(1, 4);
1537 $participant->register_date = $this->_getRandomDate();
1538 $participant->source = "Credit Card";
1539
1540 if ($participant->event_id == 1) {
1541 $fee_level = "Single";
1542 $fee_amount = 50;
1543 }
1544 elseif ($participant->event_id == 2) {
1545 $fee_level = "Soprano";
1546 $fee_amount = 50;
1547 }
1548 else {
1549 $fee_level = "Tiny-tots (ages 5-8)";
1550 $fee_amount = 800;
1551 }
1552 $participant->fee_level = $fee_level;
1553 $participant->fee_amount = $fee_amount;
1554 $participant->is_test = 0;
1555
1556 $this->_insert($participant);
1557 }
1558 }
1559
1560 function addPCP() {
1561 $query = "
1562 INSERT INTO `civicrm_pcp`
1563 (contact_id, status_id, title, intro_text, page_text, donate_link_text, contribution_page_id, is_thermometer, is_honor_roll, goal_amount, referer, is_active)
1564 VALUES
1565 ({$this->individual[3]}, 2, 'My Personal Civi Fundraiser', 'I''m on a mission to get all my friends and family to help support my favorite open-source civic sector CRM.', '<p>Friends and family - please help build much needed infrastructure for the civic sector by supporting my personal campaign!</p>\r\n<p><a href=\"http://civicrm.org\">You can learn more about CiviCRM here</a>.</p>\r\n<p>Then click the <strong>Contribute Now</strong> button to go to our easy-to-use online contribution form.</p>', 'Contribute Now', 1, 1, 1, 5000.00, NULL, 1);
1566 ";
1567 CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
1568 }
1569
1570 function addContribution() {
1571 // add contributions
1572 $contribution = new CRM_Contribute_DAO_Contribution();
1573
1574 for ($id = 1; $id <= self::NUM_CONTRIBUTION; $id++) {
1575 $contribution->contact_id = mt_rand(1, self::NUM_CONTACT);
1576 $contribution->financial_type_id = mt_rand(1, 4);
1577 $contribution->contribution_page_id = mt_rand(1, 3);
1578 $contribution->payment_instrument_id = mt_rand(1, 5);
1579 $contribution->receive_date = $this->_getRandomDate();
1580 $contribution->total_amount = mt_rand(10, 99);
1581 $contribution->contribution_status_id = mt_rand(1, 6);
1582 $contribution->trxn_id = "#" . md5($contribution->receive_date);
1583 $this->_insert($contribution);
1584 }
1585 }
1586
1587 function addSoftContribution() {
1588 $pcpRollNickNAme = array('Jones Family', 'Annie and the kids', 'Anonymous', 'Adam Family');
1589
1590 $pcpPersonalNote = array('Helping Hands', 'Annie Helps', 'Anonymous', 'Adam Helps');
1591
1592 $softContribution = new CRM_Contribute_DAO_ContributionSoft();
1593
1594 $sql = "SELECT DISTINCT(contact_id), id, total_amount from civicrm_contribution LIMIT 200";
1595
1596 $contriInfo = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
1597
1598 $prevContactID = NULL;
1599
1600 while ($contriInfo->fetch()) {
1601 if ($prevContactID) {
1602 $softContribution->contribution_id = $contriInfo->id;
1603 $softContribution->contact_id = $prevContactID;
1604 $softContribution->amount = $contriInfo->total_amount;
1605 $softContribution->pcp_id = 1;
1606 $softContribution->pcp_display_in_roll = 1;
1607 $softContribution->pcp_roll_nickname = $this->_getRandomElement($pcpRollNickNAme);
1608 $softContribution->pcp_personal_note = $this->_getRandomElement($pcpPersonalNote);
1609 $this->_insert($softContribution);
1610 }
1611 $prevContactID = $contriInfo->contact_id;
1612 }
1613 }
1614
1615 function addPledge() {
1616 $pledge = "INSERT INTO civicrm_pledge
1617 (contact_id, financial_type_id, contribution_page_id, amount, frequency_unit, frequency_interval, frequency_day, installments, start_date, create_date, acknowledge_date, modified_date, cancel_date, end_date, honor_contact_id, honor_type_id, status_id, is_test)
1618 VALUES
1619 (71, 1, 1, 500.00, 'month', 1, 1, 1, '2010-07-01 21:19:02', '2010-06-26 00:00:00', NULL, NULL, NULL,'2010-07-01 00:00:00', NULL, NULL, 1, 0),
1620 (43, 1, 1, 800.00, 'month', 3, 1, 4, '2010-07-01 10:11:09', '2010-06-23 10:11:14', '2010-06-23 10:11:18', NULL, NULL, '2010-04-01 10:11:40', NULL, NULL, 5, 0),
1621 (32, 1, 1, 600.00, 'month', 1, 1, 3, '2010-06-01 10:12:35', '2010-05-14 10:12:44', '2010-05-14 10:12:52', NULL, NULL, '2010-08-01 10:13:11', NULL, NULL, 5, 0);
1622 ";
1623 CRM_Core_DAO::executeQuery($pledge, CRM_Core_DAO::$_nullArray);
1624 }
1625
1626 function addPledgePayment() {
1627 $pledgePayment = "INSERT INTO civicrm_pledge_payment
1628 ( pledge_id, contribution_id, scheduled_amount, scheduled_date, reminder_date, reminder_count, status_id)
1629 VALUES
1630 (1, 10, 500.00, '2010-07-01 13:03:45', null, 0, 1),
1631 (2, 11, 200.00, '2010-07-01 10:59:35', null, 0, 1),
1632 (2, null, 200.00, '2010-10-01 10:59:35',null, 0, 2),
1633 (2, null, 200.00, '2010-01-01 10:59:35',null, 0, 2),
1634 (2, null, 200.00, '2010-04-01 10:59:35',null, 0, 2),
1635 (3, 12, 200.00, '2010-06-01 11:00:12', null, 0, 1),
1636 (3, 13, 200.00, '2010-07-01 10:59:35', '2010-06-28 10:59:41', 1, 1),
1637 (3, null, 200.00, '2010-08-01 11:00:12', null, 0, 2);
1638 ";
1639 CRM_Core_DAO::executeQuery($pledgePayment, CRM_Core_DAO::$_nullArray);
1640 }
1641
1642 function addMembershipPayment() {
1643 $amount = array('50', '100', '1200');
1644
1645 $contribution = new CRM_Contribute_DAO_Contribution();
1646 for ($id = 1; $id <= 200; $id++) {
1647 $contribution->contact_id = mt_rand(1, self::NUM_CONTACT);
1648 $contribution->financial_type_id = mt_rand(1, 4);
1649 $contribution->payment_instrument_id = mt_rand(1, 5);
1650 $contribution->receive_date = $this->_getRandomDate();
1651 $contribution->total_amount = $this->_getRandomElement($amount);
1652 $contribution->contribution_status_id = mt_rand(1, 6);
1653 $contribution->trxn_id = "#" . md5($contribution->receive_date);
1654 $this->_insert($contribution);
1655 }
1656 for ($i = 0; $i < 3; $i++) {
1657 $contributionsArray = $membershipArray = array();
1658 $contributionSQL = "
1659 SELECT id
1660 FROM civicrm_contribution
1661 WHERE contribution_page_id IS NULL AND
1662 total_amount = {$amount[$i]} limit 0, 50 ";
1663
1664 $contributionDAO = CRM_Core_DAO::executeQuery($contributionSQL, CRM_Core_DAO::$_nullArray);
1665
1666 while ($contributionDAO->fetch()) {
1667 $contributionsArray[] = $contributionDAO->id;
1668 }
1669 $j = $i + 1;
1670 $membershipSQL = "
1671 SELECT id
1672 FROM civicrm_membership
1673 WHERE civicrm_membership.membership_type_id = {$j} limit 0, 50";
1674 $membershipDAO = CRM_Core_DAO::executeQuery($membershipSQL, CRM_Core_DAO::$_nullArray);
1675
1676 while ($membershipDAO->fetch()) {
1677 $membershipArray[] = $membershipDAO->id;
1678 }
1679
1680 $payemntOBJ = new CRM_Member_DAO_MembershipPayment();
1681 foreach ($membershipArray as $key => $membershipid) {
1682 $payemntOBJ->contribution_id = $contributionsArray[$key];
1683 $payemntOBJ->membership_id = $membershipid;
1684 $this->_insert($payemntOBJ);
1685 }
1686 }
1687 }
1688 }
1689
1690 /**
1691 * @param null $str
1692 *
1693 * @return bool
1694 */
1695 function user_access($str = NULL) {
1696 return TRUE;
1697 }
1698
1699 /**
1700 * @return array
1701 */
1702 function module_list() {
1703 return array();
1704 }
1705
1706
1707 echo ("Starting data generation on " . date("F dS h:i:s A") . "\n");
1708 $obj1 = new CRM_GCD();
1709 $obj1->initID();
1710 $obj1->parseDataFile();
1711 $obj1->initDB();
1712 $obj1->addDomain();
1713 $obj1->addContact();
1714 $obj1->addIndividual();
1715 $obj1->addHousehold();
1716 $obj1->addOrganization();
1717 $obj1->addRelationship();
1718 $obj1->addLocation();
1719 $obj1->addEntityTag();
1720 $obj1->addGroup();
1721 $obj1->addNote();
1722 $obj1->addActivity();
1723 $obj1->addMembership();
1724 $obj1->addMembershipLog();
1725 $obj1->createEvent();
1726 $obj1->addParticipant();
1727 $obj1->addContribution();
1728 $obj1->addPCP();
1729 $obj1->addSoftContribution();
1730 $obj1->addPledge();
1731 $obj1->addPledgePayment();
1732 $obj1->addMembershipPayment();
1733 echo ("Ending data generation on " . date("F dS h:i:s A") . "\n");
1734