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