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