3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates data for the schema located in Contact.sql
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
25 * Data generation is a bit tricky since the data generated
26 * randomly in one table could be used as a FKEY in another
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.
38 * Domain ID's - 1 to NUM_DOMAIN
42 * Contact - 1 to NUM_CONTACT
47 * Contact to Domain distribution should be equal.
50 * Contact Individual = 1 to 0.75*NUM_CONTACT
52 * Contact Household = 0.75*NUM_CONTACT to 0.9*NUM_CONTACT
54 * Contact Organization = 0.9*NUM_CONTACT to NUM_CONTACT
56 * Contact Location = 15% for Households, 10% for Organizations, (75-(15*4))% for Individuals.
57 * (Assumption is that each household contains 4 individuals)
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.
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
77 * @todo look to remove this file completely.
81 require_once '../civicrm.config.php';
84 require_once 'CRM/Core/ClassLoader.php';
85 CRM_Core_ClassLoader
::singleton()->register();
95 const DATA_FILENAME
= "sample_data.xml";
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;
107 // relationship types from the table crm_relationship_type
110 const SIBLING_OF
= 3;
111 const HEAD_OF_HOUSEHOLD
= 6;
112 const MEMBER_OF_HOUSEHOLD
= 7;
115 // location types from the table crm_location_type
120 const ADD_TO_DB
= TRUE;
121 //const ADD_TO_DB=FALSE;
122 const DEBUG_LEVEL
= 1;
129 * enum's from database
132 private $preferredCommunicationMethod = array('1', '2', '3', '4', '5');
133 private $contactType = array('Individual', 'Household', 'Organization');
134 private $phoneType = array('1', '2', '3', '4');
137 * customizable enums (foreign keys)
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]');
149 private $domain = array();
155 private $contact = array();
156 private $individual = array();
157 private $household = array();
158 private $organization = array();
162 * store names, firstnames, street 1, street2
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();
189 * stores the strict individual id and household id to individual id mapping
192 private $strictIndividual = array();
193 private $householdIndividual = array();
196 * sample data in xml format
199 private $sampleData = NULL;
205 private $numIndividual = 0;
206 private $numHousehold = 0;
207 private $numOrganization = 0;
208 private $numStrictIndividual = 0;
210 private $CSC = array(
214 1004 => array('San Francisco', 'Los Angeles', 'Palo Alto'),
216 1031 => array('New York', 'Albany'),
221 1113 => array('Mumbai', 'Pune', 'Nasik'),
223 1114 => array('Bangalore', 'Mangalore', 'Udipi'),
228 1115 => array('Warszawa', 'PÅ‚ock'),
230 1116 => array('Gdańsk', 'Gdynia'),
236 private $groupMembershipStatus = array('Added', 'Removed', 'Pending');
237 private $subscriptionHistoryMethod = array('Admin', 'Email');
247 * Get a randomly generated string.
251 private function _getRandomString($size = 32) {
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
261 $random_char = chr($random_int);
262 $string .= $random_char;
270 private function _getRandomChar() {
271 return chr(mt_rand(65, 90));
277 private function getRandomBoolean() {
278 return mt_rand(0, 1);
286 private function _getRandomElement(&$array1) {
287 return $array1[mt_rand(1, count($array1)) - 1];
295 private function _getRandomIndex(&$array1) {
296 return mt_rand(1, count($array1));
299 // country state city combo
304 private function _getRandomCSC() {
307 // $c = array_rand($this->CSC);
310 // the state array now
311 $s = array_rand($this->CSC
[$c]);
314 $ci = array_rand($this->CSC
[$c][$s]);
315 $city = $this->CSC
[$c][$s][$ci];
325 * Generate a random date.
327 * If both $startDate and $endDate are defined generate
330 * If only startDate is specified then date generated is
331 * between startDate + 1 year.
333 * if only endDate is specified then date generated is
334 * between endDate - 1 year.
336 * if none are specified - date is between today - 1year
339 * @param int $startDate Start Date in Unix timestamp
340 * @param int $endDate End Date in Unix timestamp
343 * @return string randomly generated date in the format "Ymd"
346 private function _getRandomDate($startDate = 0, $endDate = 0) {
348 // number of seconds per year
349 // $numSecond = 31536000;
350 // number of seconds for 2 year
351 $numSecond = 63072000;
353 $dateFormat = "YmdHis";
357 if ($startDate && $endDate) {
358 return date($dateFormat, mt_rand($startDate, $endDate));
361 // only startDate is defined
363 // $nextYear = mktime(0, 0, 0, date("m", $startDate), date("d", $startDate), date("Y")+1);
364 return date($dateFormat, mt_rand($startDate, $startDate +
$numSecond));
367 // only endDate is defined
369 return date($dateFormat, mt_rand($endDate - $numSecond, $endDate));
373 return date($dateFormat, mt_rand($today - $numSecond, $today));
376 // insert data into db's
381 private function _insert(&$dao) {
382 if (self
::ADD_TO_DB
) {
383 if (!$dao->insert()) {
384 echo "ERROR INSERT: " . mysqli_error($dao->getConnection()->connection
) . "\n";
391 // update data into db's
396 private function _update($dao) {
397 if (self
::ADD_TO_DB
) {
398 if (!$dao->update()) {
399 echo "ERROR UPDATE: " . mysqli_error($dao->getConnection()->connection
) . "\n";
409 * Helper function which randomly populates "note" and
410 * "date_modified" and inserts it.
416 private function _insertNote($note) {
417 $note->note
= $this->_getRandomElement($this->note
);
418 $note->modified_date
= $this->_getRandomDate();
419 $this->_insert($note);
424 * Start of public functions
427 public function __construct() {
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
);
435 public function parseDataFile() {
437 $sampleData = simplexml_load_file(self
::DATA_FILENAME
);
440 foreach ($sampleData->first_names
->first_name
as $first_name) {
441 $this->firstName
[] = trim($first_name);
445 foreach ($sampleData->last_names
->last_name
as $last_name) {
446 $this->lastName
[] = trim($last_name);
450 foreach ($sampleData->street_names
->street_name
as $street_name) {
451 $this->streetName
[] = trim($street_name);
454 // supplemental address 1
455 foreach ($sampleData->supplemental_addresses_1
->supplemental_address_1
as $supplemental_address_1) {
456 $this->supplementalAddress1
[] = trim($supplemental_address_1);
460 foreach ($sampleData->cities
->city
as $city) {
461 $this->city
[] = trim($city);
464 // address directions
465 foreach ($sampleData->address_directions
->address_direction
as $address_direction) {
466 $this->addressDirection
[] = trim($address_direction);
470 foreach ($sampleData->street_types
->street_type
as $street_type) {
471 $this->streetType
[] = trim($street_type);
475 foreach ($sampleData->email_domains
->email_domain
as $email_domain) {
476 $this->emailDomain
[] = trim($email_domain);
479 // email top level domain
480 foreach ($sampleData->email_tlds
->email_tld
as $email_tld) {
481 $this->emailTLD
[] = trim($email_tld);
485 foreach ($sampleData->organization_names
->organization_name
as $organization_name) {
486 $this->organization_name
[] = trim($organization_name);
489 // organization field
490 foreach ($sampleData->organization_fields
->organization_field
as $organization_field) {
491 $this->organizationField
[] = trim($organization_field);
495 foreach ($sampleData->organization_types
->organization_type
as $organization_type) {
496 $this->organizationType
[] = trim($organization_type);
500 foreach ($sampleData->groups
->group
as $group) {
501 $this->group
[] = trim($group);
505 foreach ($sampleData->notes
->note
as $note) {
506 $this->note
[] = trim($note);
510 foreach ($sampleData->activity_types
->activity_type
as $activity_type) {
511 $this->activity_type
[] = trim($activity_type);
515 foreach ($sampleData->modules
->module
as $module) {
516 $this->module
[] = trim($module);
520 foreach ($sampleData->callbacks
->callback
as $callback) {
521 $this->callback
[] = trim($callback);
524 // custom data - party registration
525 foreach ($sampleData->party_registrations
->party_registration
as $party_registration) {
526 $this->party_registration
[] = trim($party_registration);
529 // custom data - degrees
530 foreach ($sampleData->degrees
->degree
as $degree) {
531 $this->degree
[] = trim($degree);
534 // custom data - schools
535 foreach ($sampleData->schools
->school
as $school) {
536 $this->school
[] = trim($school);
539 // custom data - issue
540 foreach ($sampleData->issue
->status
as $status) {
541 $this->issue
[] = trim($status);
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
;
550 // custom data - marital_status
551 foreach ($sampleData->marital_status
->status
as $status) {
552 $this->marital_status
[] = trim($status);
561 public function getContactType($id) {
562 if (in_array($id, $this->individual
)) {
565 if (in_array($id, $this->household
)) {
568 if (in_array($id, $this->organization
)) {
569 return 'Organization';
573 public function initDB() {
574 $config = CRM_Core_Config
::singleton();
579 * this function creates arrays for the following
583 * contact_location id
584 * contact_contact_location id
587 * contact_instant_message uuid
588 * contact_relationship uuid
593 public function initID() {
595 // may use this function in future if needed to get
596 // a consistent pattern of random numbers.
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
);
604 // get the individual, household and organizaton contacts
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
);
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
);
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
);
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..
629 public function addDomain() {
631 /* Add a location for domain 1 */
633 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
634 // $this->_addLocation(self::MAIN, 1, true);
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();
644 $this->_insert($domain);
645 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
646 // $this->_addLocation(self::MAIN, $id, true);
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
);
660 return $this->prefix
[$prefix] . " $first_name $middle_name $last_name " . $this->suffix
[$suffix];
667 * This method adds data to the contact table
670 * contact_type 'Individual' 'Household' 'Organization'
671 * preferred_communication (random 1 to 3)
674 public function addContact() {
677 $contact = new CRM_Contact_DAO_Contact();
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);
694 * This method adds individual's data to the contact table
696 * The following fields are generated and added.
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'
708 public function addIndividual() {
710 $contact = new CRM_Contact_DAO_Contact();
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);
723 $contact->id
= $this->individual
[($id - 1)];
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);
737 * This method adds household's data to the contact table
739 * The following fields are generated and added.
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];
748 public function addHousehold() {
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];
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
;
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";
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);
778 * This method adds organization data to the contact table
780 * The following fields are generated and added.
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
791 public function addOrganization() {
793 $contact = new CRM_Contact_DAO_Contact();
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
);
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);
812 * This method adds data to the contact_relationship table
814 * it adds the following fields
817 public function addRelationship() {
819 $relationship = new CRM_Contact_DAO_Relationship();
821 // all active for now.
822 $relationship->is_active
= 1;
824 foreach ($this->householdIndividual
as $household_id => $household_member) {
825 // add child_of relationship
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);
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);
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);
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);
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);
874 * This method adds data to the location table
877 public function addLocation() {
878 // strict individuals
879 foreach ($this->strictIndividual
as $contactId) {
880 $this->_addLocation(self
::HOME
, $contactId);
884 foreach ($this->household
as $contactId) {
885 $this->_addLocation(self
::HOME
, $contactId);
889 foreach ($this->organization
as $contactId) {
890 $this->_addLocation(self
::MAIN
, $contactId);
894 $someIndividual = array_diff($this->individual
, $this->strictIndividual
);
895 $someIndividual = array_slice($someIndividual, 0, (int) (75 * ($this->numIndividual
- $this->numStrictIndividual
) / 100));
896 foreach ($someIndividual as $contactId) {
897 $this->_addLocation(self
::HOME
, $contactId, FALSE, TRUE);
902 * @param $locationTypeId
904 * @param bool $domain
905 * @param bool $isPrimary
907 private function _addLocation($locationTypeId, $contactId, $domain = FALSE, $isPrimary = TRUE) {
908 $this->_addAddress($locationTypeId, $contactId, $isPrimary);
910 // add two phones for each location
911 $this->_addPhone($locationTypeId, $contactId, '1', $isPrimary);
912 $this->_addPhone($locationTypeId, $contactId, '2', FALSE);
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);
929 * @param $locationTypeId
931 * @param bool $isPrimary
932 * @param null $locationBlockID
935 private function _addAddress($locationTypeId, $contactId, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
936 $addressDAO = new CRM_Core_DAO_Address();
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;
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
));
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();
958 //$addressDAO->county_id = 1;
960 $this->_insert($addressDAO);
968 private function _sortNameToEmail($sortName) {
969 $email = preg_replace("([^a-zA-Z0-9_-]*)", "", $sortName);
974 * @param $locationTypeId
977 * @param bool $isPrimary
978 * @param null $locationBlockID
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);
994 * @param $locationTypeId
997 * @param bool $isPrimary
998 * @param null $locationBlockID
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;
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);
1020 * This method populates the crm_entity_tag table
1023 public function addEntityTag() {
1025 $entity_tag = new CRM_Core_DAO_EntityTag();
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);
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);
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);
1057 * This method populates the crm_entity_tag table
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;
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
);
1083 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1084 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1086 $subscriptionHistory->group_id
= $groupContact->group_id
;
1087 $subscriptionHistory->status
= $groupContact->status
;
1089 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1090 $subscriptionHistory->date
= $this->_getRandomDate();
1091 if ($groupContact->status
!= 'Pending') {
1092 $this->_insert($groupContact);
1094 $this->_insert($subscriptionHistory);
1098 for ($i = 0; $i < 15; $i++
) {
1099 $groupContact = new CRM_Contact_DAO_GroupContact();
1101 $groupContact->group_id
= 3;
1102 $groupContact->contact_id
= $this->individual
[$i +
60];
1103 // membership status
1104 $groupContact->status
= $this->_getRandomElement($this->groupMembershipStatus
);
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
;
1111 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1112 $subscriptionHistory->date
= $this->_getRandomDate();
1114 if ($groupContact->status
!= 'Pending') {
1115 $this->_insert($groupContact);
1117 $this->_insert($subscriptionHistory);
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
);
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
;
1134 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1135 $subscriptionHistory->date
= $this->_getRandomDate();
1137 if ($groupContact->status
!= 'Pending') {
1138 $this->_insert($groupContact);
1140 $this->_insert($subscriptionHistory);
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
1146 Civi
::cache('fields')->flush();
1147 CRM_Core_BAO_Cache
::resetCaches();
1154 * This method populates the crm_note table
1157 public function addNote() {
1159 $note = new CRM_Core_DAO_Note();
1160 $note->entity_table
= 'civicrm_contact';
1161 $note->contact_id
= 1;
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);
1175 * This method populates the crm_activity_history table
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();
1187 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
1189 while ($contactDAO->fetch()) {
1193 for ($i = 0; $i < self
::NUM_ACTIVITY
; $i++
) {
1194 $activityDAO = new CRM_Activity_DAO_Activity();
1195 $activityDAO->source_contact_id
= $contactDAO->id
;
1196 $activityTypeID = mt_rand(7, 10);
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);
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);
1211 if (in_array($activityTypeID, array(
1214 $activityTargetDAO = new CRM_Activity_DAO_ActivityContact();
1215 $activityTargetDAO->activity_id
= $activityDAO->id
;
1216 $activityTargetDAO->contact_id
= mt_rand(1, 101);
1217 $activityTargetDAO->record_type_id
= CRM_Utils_Array
::key('Activity Targets', $activityContacts);
1218 $this->_insert($activityTargetDAO);
1221 if ($activityTypeID == 7) {
1222 $activityAssignmentDAO = new CRM_Activity_DAO_ActivityContact();
1223 $activityAssignmentDAO->activity_id
= $activityDAO->id
;
1224 $activityAssignmentDAO->contact_id
= mt_rand(1, 101);
1225 $activityAssignmentDAO->record_type_id
= CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
1226 $this->_insert($activityAssignmentDAO);
1235 public static function getZipCodeInfo() {
1236 $stateID = mt_rand(1000, 5132);
1237 $offset = mt_rand(1, 4132);
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
);
1254 public static function getLatLong($zipCode) {
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";
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);
1264 // grab URL and pass it to the browser
1265 $outstr = curl_exec($ch);
1267 // close CURL resource, and free up system resources
1270 $preg = "/'(<\?xml.+?)',/s";
1271 preg_match($preg, $outstr, $matches);
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']);
1279 return array(NULL, NULL);
1282 public function addMembershipType() {
1283 $organizationDAO = new CRM_Contact_DAO_Contact();
1284 $organizationDAO->id
= 5;
1285 $organizationDAO->find(TRUE);
1286 $contact_id = $organizationDAO->contact_id
;
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)
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);
1295 CRM_Core_DAO
::executeQuery($membershipType);
1298 public function addMembership() {
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
;
1306 $randomContacts = array_slice($contacts, 0, 350);
1308 $sources = array('Payment', 'Donation', 'Check');
1309 $membershipTypes = array(2, 1);
1310 $membershipTypeNames = array('Student', 'General');
1311 $statuses = array(3, 4);
1314 INSERT INTO civicrm_membership
1315 (contact_id, membership_type_id, join_date, start_date, end_date, source, status_id)
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)
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 )";
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,
1339 (date('d') - ($count * ($randId +
1) * ($randId +
1) * ($randId +
1))),
1340 (date('Y') - ($randId +
1))
1342 $partOfDate = explode('-', $startDate);
1343 $endDate = date('Y-m-d', mktime(0, 0, 0,
1345 ($partOfDate[2] - 1),
1346 ($partOfDate[0] +
($randId +
1))
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 )";
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 )";
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 )";
1366 if ($count != 349) {
1372 CRM_Core_DAO
::executeQuery($membership);
1374 CRM_Core_DAO
::executeQuery($activity);
1382 public static function repairDate($date) {
1383 $dropArray = array('-' => '', ':' => '', ' ' => '');
1384 return strtr($date, $dropArray);
1387 public function addMembershipLog() {
1388 $membership = new CRM_Member_DAO_Membership();
1389 $membership->query("SELECT id FROM civicrm_membership");
1390 while ($membership->fetch()) {
1391 $ids[] = $membership->id
;
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();
1407 $membershipLog = NULL;
1411 public function createEvent() {
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)
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)
1418 CRM_Core_DAO
::executeQuery($event);
1420 $sql = "SELECT id from civicrm_address where street_address = 'S 14S El Camino Way E'";
1421 $eventAdd1 = CRM_Core_DAO
::singleValueQuery($sql);
1422 $sql = "SELECT id from civicrm_address where street_address = 'E 11B Woodbridge Path SW'";
1423 $eventAdd2 = CRM_Core_DAO
::singleValueQuery($sql);
1424 $sql = "SELECT id from civicrm_address where street_address = 'E 581O Lincoln Dr SW'";
1425 $eventAdd3 = CRM_Core_DAO
::singleValueQuery($sql);
1427 $event = "INSERT INTO civicrm_email (contact_id, location_type_id, email, is_primary, is_billing, on_hold, hold_date, reset_date)
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)
1433 CRM_Core_DAO
::executeQuery($event);
1435 $sql = "SELECT id from civicrm_email where email = 'development@example.org'";
1436 $eventEmail1 = CRM_Core_DAO
::singleValueQuery($sql);
1437 $sql = "SELECT id from civicrm_email where email = 'tournaments@example.org'";
1438 $eventEmail2 = CRM_Core_DAO
::singleValueQuery($sql);
1439 $sql = "SELECT id from civicrm_email where email = 'celebration@example.org'";
1440 $eventEmail3 = CRM_Core_DAO
::singleValueQuery($sql);
1442 $event = "INSERT INTO civicrm_phone (contact_id, location_type_id, is_primary, is_billing, mobile_provider_id, phone, phone_type_id)
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')
1448 CRM_Core_DAO
::executeQuery($event);
1450 $sql = "SELECT id from civicrm_phone where phone = '204 222-1000'";
1451 $eventPhone1 = CRM_Core_DAO
::singleValueQuery($sql);
1452 $sql = "SELECT id from civicrm_phone where phone = '204 223-1000'";
1453 $eventPhone2 = CRM_Core_DAO
::singleValueQuery($sql);
1454 $sql = "SELECT id from civicrm_phone where phone = '303 323-1000'";
1455 $eventPhone3 = CRM_Core_DAO
::singleValueQuery($sql);
1457 $event = "INSERT INTO civicrm_loc_block ( address_id, email_id, phone_id, address_2_id, email_2_id, phone_2_id)
1459 ( $eventAdd1, $eventEmail1, $eventPhone1, NULL,NULL,NULL),
1460 ( $eventAdd2, $eventEmail2, $eventPhone2, NULL,NULL,NULL),
1461 ( $eventAdd3, $eventEmail3, $eventPhone3, NULL,NULL,NULL)
1464 CRM_Core_DAO
::executeQuery($event);
1466 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone1 AND email_id = $eventEmail1 AND address_id = $eventAdd1";
1467 $eventLok1 = CRM_Core_DAO
::singleValueQuery($sql);
1468 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone2 AND email_id = $eventEmail2 AND address_id = $eventAdd2";
1469 $eventLok2 = CRM_Core_DAO
::singleValueQuery($sql);
1470 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone3 AND email_id = $eventEmail3 AND address_id = $eventAdd3";
1471 $eventLok3 = CRM_Core_DAO
::singleValueQuery($sql);
1474 $optionGroup = "INSERT INTO civicrm_option_group ( name, is_reserved, is_active)
1476 ( 'civicrm_event.amount.1', 0, 1),
1477 ( 'civicrm_event.amount.2', 0, 1),
1478 ( 'civicrm_event.amount.3', 0, 1)
1480 CRM_Core_DAO
::executeQuery($optionGroup);
1482 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.1'";
1483 $page1 = CRM_Core_DAO
::singleValueQuery($sql);
1485 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.2'";
1486 $page2 = CRM_Core_DAO
::singleValueQuery($sql);
1488 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.3'";
1489 $page3 = CRM_Core_DAO
::singleValueQuery($sql);
1491 $optionValue = "INSERT INTO civicrm_option_value (option_group_id, label, value, is_default, weight, is_optgroup, is_reserved, is_active)
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)";
1503 CRM_Core_DAO
::executeQuery($optionValue);
1505 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page1 AND civicrm_option_value.weight=2";
1506 $defaultFee1 = CRM_Core_DAO
::singleValueQuery($sql);
1508 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page2 AND civicrm_option_value.weight=2";
1509 $defaultFee2 = CRM_Core_DAO
::singleValueQuery($sql);
1511 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page3 AND civicrm_option_value.weight=2";
1512 $defaultFee3 = CRM_Core_DAO
::singleValueQuery($sql);
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 )
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 )
1521 CRM_Core_DAO
::executeQuery($event);
1524 public function addParticipant() {
1526 $participant = new CRM_Event_DAO_Participant();
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";
1536 if ($participant->event_id
== 1) {
1537 $fee_level = "Single";
1540 elseif ($participant->event_id
== 2) {
1541 $fee_level = "Soprano";
1545 $fee_level = "Tiny-tots (ages 5-8)";
1548 $participant->fee_level
= $fee_level;
1549 $participant->fee_amount
= $fee_amount;
1550 $participant->is_test
= 0;
1552 $this->_insert($participant);
1556 public function addPCP() {
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)
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);
1563 CRM_Core_DAO
::executeQuery($query);
1566 public function addContribution() {
1567 // add contributions
1568 $contribution = new CRM_Contribute_DAO_Contribution();
1570 for ($id = 1; $id <= self
::NUM_CONTRIBUTION
; $id++
) {
1571 $contribution->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1572 $contribution->financial_type_id
= mt_rand(1, 4);
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);
1583 public function addSoftContribution() {
1584 $pcpRollNickNAme = array('Jones Family', 'Annie and the kids', 'Anonymous', 'Adam Family');
1586 $pcpPersonalNote = array('Helping Hands', 'Annie Helps', 'Anonymous', 'Adam Helps');
1588 $softContribution = new CRM_Contribute_DAO_ContributionSoft();
1590 $sql = "SELECT DISTINCT(contact_id), id, total_amount from civicrm_contribution LIMIT 200";
1592 $contriInfo = CRM_Core_DAO
::executeQuery($sql);
1594 $prevContactID = NULL;
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);
1607 $prevContactID = $contriInfo->contact_id
;
1611 public function addPledge() {
1612 $pledge = "INSERT INTO civicrm_pledge
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)
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);
1619 CRM_Core_DAO
::executeQuery($pledge);
1622 public function addPledgePayment() {
1623 $pledgePayment = "INSERT INTO civicrm_pledge_payment
1624 ( pledge_id, contribution_id, scheduled_amount, scheduled_date, reminder_date, reminder_count, status_id)
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);
1635 CRM_Core_DAO
::executeQuery($pledgePayment);
1638 public function addMembershipPayment() {
1639 $amount = array('50', '100', '1200');
1641 $contribution = new CRM_Contribute_DAO_Contribution();
1642 for ($id = 1; $id <= 200; $id++
) {
1643 $contribution->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1644 $contribution->financial_type_id
= mt_rand(1, 4);
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);
1652 for ($i = 0; $i < 3; $i++
) {
1653 $contributionsArray = $membershipArray = array();
1654 $contributionSQL = "
1656 FROM civicrm_contribution
1657 WHERE contribution_page_id IS NULL AND
1658 total_amount = {$amount[$i]} limit 0, 50 ";
1660 $contributionDAO = CRM_Core_DAO
::executeQuery($contributionSQL);
1662 while ($contributionDAO->fetch()) {
1663 $contributionsArray[] = $contributionDAO->id
;
1668 FROM civicrm_membership
1669 WHERE civicrm_membership.membership_type_id = {$j} limit 0, 50";
1670 $membershipDAO = CRM_Core_DAO
::executeQuery($membershipSQL);
1672 while ($membershipDAO->fetch()) {
1673 $membershipArray[] = $membershipDAO->id
;
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);
1692 function user_access($str = NULL) {
1699 function module_list() {
1703 echo ("Starting data generation on " . date("F dS h:i:s A") . "\n");
1704 $obj1 = new CRM_GCD();
1706 $obj1->parseDataFile();
1709 $obj1->addContact();
1710 $obj1->addIndividual();
1711 $obj1->addHousehold();
1712 $obj1->addOrganization();
1713 $obj1->addRelationship();
1714 $obj1->addLocation();
1715 $obj1->addEntityTag();
1718 $obj1->addActivity();
1719 $obj1->addMembership();
1720 $obj1->addMembershipLog();
1721 $obj1->createEvent();
1722 $obj1->addParticipant();
1723 $obj1->addContribution();
1725 $obj1->addSoftContribution();
1727 $obj1->addPledgePayment();
1728 $obj1->addMembershipPayment();
1729 echo ("Ending data generation on " . date("F dS h:i:s A") . "\n");