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