3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
37 * This class generates data for the schema located in Contact.sql
39 * each public method generates data for the concerned table.
40 * so for example the addContactDomain method generates and adds
41 * data to the contact_domain table
43 * Data generation is a bit tricky since the data generated
44 * randomly in one table could be used as a FKEY in another
47 * In order to ensure that a randomly generated FKEY matches
48 * a field in the referened table, the field in the referenced
49 * table is always generated linearly.
56 * Domain ID's - 1 to NUM_DOMAIN
60 * Contact - 1 to NUM_CONTACT
65 * Contact to Domain distribution should be equal.
68 * Contact Individual = 1 to 0.75*NUM_CONTACT
70 * Contact Household = 0.75*NUM_CONTACT to 0.9*NUM_CONTACT
72 * Contact Organization = 0.9*NUM_CONTACT to NUM_CONTACT
74 * Contact Location = 15% for Households, 10% for Organizations, (75-(15*4))% for Individuals.
75 * (Assumption is that each household contains 4 individuals)
81 * Note: implication of using of mt_srand(1) in constructor
82 * The data generated will be done in a consistent manner
83 * so as to give the same data during each run (but this
84 * would involve populating the entire db at one go - since
85 * mt_srand(1) is in the constructor, if one needs to be able
86 * to get consistent random numbers then the mt_srand(1) shld
87 * be in each function that adds data to each table.
92 * Note as of 2019-07-15 this file does not appear to be called
93 * from anywhere and seems to have issues running on more recent
95 * @todo look to remove this file completely.
99 require_once '../civicrm.config.php';
102 require_once 'CRM/Core/ClassLoader.php';
103 CRM_Core_ClassLoader
::singleton()->register();
113 const DATA_FILENAME
= "sample_data.xml";
114 const NUM_DOMAIN
= 1;
115 const NUM_CONTACT
= 5000;
116 const NUM_CONTRIBUTION
= 2000;
117 const NUM_MEMBERSHIP
= 2000;
118 const NUM_PARTICIPANT
= 2000;
119 const INDIVIDUAL_PERCENT
= 75;
120 const HOUSEHOLD_PERCENT
= 15;
121 const ORGANIZATION_PERCENT
= 10;
122 const NUM_INDIVIDUAL_PER_HOUSEHOLD
= 4;
123 const NUM_ACTIVITY
= 150;
125 // relationship types from the table crm_relationship_type
128 const SIBLING_OF
= 3;
129 const HEAD_OF_HOUSEHOLD
= 6;
130 const MEMBER_OF_HOUSEHOLD
= 7;
133 // location types from the table crm_location_type
138 const ADD_TO_DB
= TRUE;
139 //const ADD_TO_DB=FALSE;
140 const DEBUG_LEVEL
= 1;
147 * enum's from database
150 private $preferredCommunicationMethod = array('1', '2', '3', '4', '5');
151 private $contactType = array('Individual', 'Household', 'Organization');
152 private $phoneType = array('1', '2', '3', '4');
155 * customizable enums (foreign keys)
158 private $prefix = array(1 => 'Mrs', 2 => 'Ms', 3 => 'Mr', 4 => 'Dr');
159 private $suffix = array(1 => 'Jr', 2 => 'Sr');
160 private $gender = array(1 => 'Female', 2 => 'Male');
161 private $greetingType = array(1 => 'Dear [first]', 2 => 'Dear [prefix] [first] [last]', 3 => 'Dear [prefix] [last]');
167 private $domain = array();
173 private $contact = array();
174 private $individual = array();
175 private $household = array();
176 private $organization = array();
180 * store names, firstnames, street 1, street2
183 private $firstName = array();
184 private $lastName = array();
185 private $streetName = array();
186 private $supplementalAddress1 = array();
187 private $city = array();
188 private $state = array();
189 private $country = array();
190 private $addressDirection = array();
191 private $streetType = array();
192 private $emailDomain = array();
193 private $emailTLD = array();
194 private $organizationName = array();
195 private $organizationField = array();
196 private $organizationType = array();
197 private $group = array();
198 private $note = array();
199 private $activity_type = array();
200 private $module = array();
201 private $callback = array();
202 private $party_registration = array();
203 private $degree = array();
204 private $school = array();
207 * stores the strict individual id and household id to individual id mapping
210 private $strictIndividual = array();
211 private $householdIndividual = array();
214 * sample data in xml format
217 private $sampleData = NULL;
223 private $numIndividual = 0;
224 private $numHousehold = 0;
225 private $numOrganization = 0;
226 private $numStrictIndividual = 0;
228 private $CSC = array(
232 1004 => array('San Francisco', 'Los Angeles', 'Palo Alto'),
234 1031 => array('New York', 'Albany'),
239 1113 => array('Mumbai', 'Pune', 'Nasik'),
241 1114 => array('Bangalore', 'Mangalore', 'Udipi'),
246 1115 => array('Warszawa', 'PÅ‚ock'),
248 1116 => array('Gdańsk', 'Gdynia'),
254 private $groupMembershipStatus = array('Added', 'Removed', 'Pending');
255 private $subscriptionHistoryMethod = array('Admin', 'Email');
265 * Get a randomly generated string.
269 private function _getRandomString($size = 32) {
272 // get an ascii code for each character
273 for ($i = 0; $i < $size; $i++
) {
274 $random_int = mt_rand(65, 122);
275 if (($random_int < 97) && ($random_int > 90)) {
276 // if ascii code between 90 and 97 substitute with space
279 $random_char = chr($random_int);
280 $string .= $random_char;
288 private function _getRandomChar() {
289 return chr(mt_rand(65, 90));
295 private function getRandomBoolean() {
296 return mt_rand(0, 1);
304 private function _getRandomElement(&$array1) {
305 return $array1[mt_rand(1, count($array1)) - 1];
313 private function _getRandomIndex(&$array1) {
314 return mt_rand(1, count($array1));
317 // country state city combo
322 private function _getRandomCSC() {
325 // $c = array_rand($this->CSC);
328 // the state array now
329 $s = array_rand($this->CSC
[$c]);
332 $ci = array_rand($this->CSC
[$c][$s]);
333 $city = $this->CSC
[$c][$s][$ci];
343 * Generate a random date.
345 * If both $startDate and $endDate are defined generate
348 * If only startDate is specified then date generated is
349 * between startDate + 1 year.
351 * if only endDate is specified then date generated is
352 * between endDate - 1 year.
354 * if none are specified - date is between today - 1year
357 * @param int $startDate Start Date in Unix timestamp
358 * @param int $endDate End Date in Unix timestamp
361 * @return string randomly generated date in the format "Ymd"
364 private function _getRandomDate($startDate = 0, $endDate = 0) {
366 // number of seconds per year
367 // $numSecond = 31536000;
368 // number of seconds for 2 year
369 $numSecond = 63072000;
371 $dateFormat = "YmdHis";
375 if ($startDate && $endDate) {
376 return date($dateFormat, mt_rand($startDate, $endDate));
379 // only startDate is defined
381 // $nextYear = mktime(0, 0, 0, date("m", $startDate), date("d", $startDate), date("Y")+1);
382 return date($dateFormat, mt_rand($startDate, $startDate +
$numSecond));
385 // only endDate is defined
387 return date($dateFormat, mt_rand($endDate - $numSecond, $endDate));
391 return date($dateFormat, mt_rand($today - $numSecond, $today));
394 // insert data into db's
399 private function _insert(&$dao) {
400 if (self
::ADD_TO_DB
) {
401 if (!$dao->insert()) {
402 echo "ERROR INSERT: " . mysqli_error($dao->getConnection()->connection
) . "\n";
409 // update data into db's
414 private function _update($dao) {
415 if (self
::ADD_TO_DB
) {
416 if (!$dao->update()) {
417 echo "ERROR UPDATE: " . mysqli_error($dao->getConnection()->connection
) . "\n";
427 * Helper function which randomly populates "note" and
428 * "date_modified" and inserts it.
434 private function _insertNote($note) {
435 $note->note
= $this->_getRandomElement($this->note
);
436 $note->modified_date
= $this->_getRandomDate();
437 $this->_insert($note);
442 * Start of public functions
445 public function __construct() {
446 // initialize all the vars
447 $this->numIndividual
= self
::INDIVIDUAL_PERCENT
* self
::NUM_CONTACT
/ 100;
448 $this->numHousehold
= self
::HOUSEHOLD_PERCENT
* self
::NUM_CONTACT
/ 100;
449 $this->numOrganization
= self
::ORGANIZATION_PERCENT
* self
::NUM_CONTACT
/ 100;
450 $this->numStrictIndividual
= $this->numIndividual
- ($this->numHousehold
* self
::NUM_INDIVIDUAL_PER_HOUSEHOLD
);
453 public function parseDataFile() {
455 $sampleData = simplexml_load_file(self
::DATA_FILENAME
);
458 foreach ($sampleData->first_names
->first_name
as $first_name) {
459 $this->firstName
[] = trim($first_name);
463 foreach ($sampleData->last_names
->last_name
as $last_name) {
464 $this->lastName
[] = trim($last_name);
468 foreach ($sampleData->street_names
->street_name
as $street_name) {
469 $this->streetName
[] = trim($street_name);
472 // supplemental address 1
473 foreach ($sampleData->supplemental_addresses_1
->supplemental_address_1
as $supplemental_address_1) {
474 $this->supplementalAddress1
[] = trim($supplemental_address_1);
478 foreach ($sampleData->cities
->city
as $city) {
479 $this->city
[] = trim($city);
482 // address directions
483 foreach ($sampleData->address_directions
->address_direction
as $address_direction) {
484 $this->addressDirection
[] = trim($address_direction);
488 foreach ($sampleData->street_types
->street_type
as $street_type) {
489 $this->streetType
[] = trim($street_type);
493 foreach ($sampleData->email_domains
->email_domain
as $email_domain) {
494 $this->emailDomain
[] = trim($email_domain);
497 // email top level domain
498 foreach ($sampleData->email_tlds
->email_tld
as $email_tld) {
499 $this->emailTLD
[] = trim($email_tld);
503 foreach ($sampleData->organization_names
->organization_name
as $organization_name) {
504 $this->organization_name
[] = trim($organization_name);
507 // organization field
508 foreach ($sampleData->organization_fields
->organization_field
as $organization_field) {
509 $this->organizationField
[] = trim($organization_field);
513 foreach ($sampleData->organization_types
->organization_type
as $organization_type) {
514 $this->organizationType
[] = trim($organization_type);
518 foreach ($sampleData->groups
->group
as $group) {
519 $this->group
[] = trim($group);
523 foreach ($sampleData->notes
->note
as $note) {
524 $this->note
[] = trim($note);
528 foreach ($sampleData->activity_types
->activity_type
as $activity_type) {
529 $this->activity_type
[] = trim($activity_type);
533 foreach ($sampleData->modules
->module
as $module) {
534 $this->module
[] = trim($module);
538 foreach ($sampleData->callbacks
->callback
as $callback) {
539 $this->callback
[] = trim($callback);
542 // custom data - party registration
543 foreach ($sampleData->party_registrations
->party_registration
as $party_registration) {
544 $this->party_registration
[] = trim($party_registration);
547 // custom data - degrees
548 foreach ($sampleData->degrees
->degree
as $degree) {
549 $this->degree
[] = trim($degree);
552 // custom data - schools
553 foreach ($sampleData->schools
->school
as $school) {
554 $this->school
[] = trim($school);
557 // custom data - issue
558 foreach ($sampleData->issue
->status
as $status) {
559 $this->issue
[] = trim($status);
562 // custom data - gotv
563 require_once 'CRM/Core/BAO/CustomOption.php';
564 foreach ($sampleData->gotv
->status
as $status) {
565 $this->gotv
[] = CRM_Core_DAO
::VALUE_SEPARATOR
. trim($status) . CRM_Core_DAO
::VALUE_SEPARATOR
;
568 // custom data - marital_status
569 foreach ($sampleData->marital_status
->status
as $status) {
570 $this->marital_status
[] = trim($status);
579 public function getContactType($id) {
580 if (in_array($id, $this->individual
)) {
583 if (in_array($id, $this->household
)) {
586 if (in_array($id, $this->organization
)) {
587 return 'Organization';
591 public function initDB() {
592 $config = CRM_Core_Config
::singleton();
597 * this function creates arrays for the following
601 * contact_location id
602 * contact_contact_location id
605 * contact_instant_message uuid
606 * contact_relationship uuid
611 public function initID() {
613 // may use this function in future if needed to get
614 // a consistent pattern of random numbers.
616 // get the domain and contact id arrays
617 $this->domain
= range(1, self
::NUM_DOMAIN
);
618 shuffle($this->domain
);
619 $this->contact
= range(2, self
::NUM_CONTACT +
1);
620 shuffle($this->contact
);
622 // get the individual, household and organizaton contacts
624 $this->individual
= array_slice($this->contact
, $offset, $this->numIndividual
);
625 $offset +
= $this->numIndividual
;
626 $this->household
= array_slice($this->contact
, $offset, $this->numHousehold
);
627 $offset +
= $this->numHousehold
;
628 $this->organization
= array_slice($this->contact
, $offset, $this->numOrganization
);
630 // get the strict individual contacts (i.e individual contacts not belonging to any household)
631 $this->strictIndividual
= array_slice($this->individual
, 0, $this->numStrictIndividual
);
633 // get the household to individual mapping array
634 $this->householdIndividual
= array_diff($this->individual
, $this->strictIndividual
);
635 $this->householdIndividual
= array_chunk($this->householdIndividual
, self
::NUM_INDIVIDUAL_PER_HOUSEHOLD
);
636 $this->householdIndividual
= array_combine($this->household
, $this->householdIndividual
);
643 * This method adds NUM_DOMAIN domains and then adds NUM_REVISION
644 * revisions for each domain with the latest revision being the last one..
647 public function addDomain() {
649 /* Add a location for domain 1 */
651 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
652 // $this->_addLocation(self::MAIN, 1, true);
654 $domain = new CRM_Core_DAO_Domain();
655 for ($id = 2; $id <= self
::NUM_DOMAIN
; $id++
) {
656 // domain name is pretty simple. it is "Domain $id"
657 $domain->name
= "Domain $id";
658 $domain->description
= "Description $id";
659 $domain->contact_name
= $this->randomName();
662 $this->_insert($domain);
663 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
664 // $this->_addLocation(self::MAIN, $id, true);
671 public function randomName() {
672 $prefix = $this->_getRandomIndex($this->prefix
);
673 $first_name = ucfirst($this->_getRandomElement($this->firstName
));
674 $middle_name = ucfirst($this->_getRandomChar());
675 $last_name = ucfirst($this->_getRandomElement($this->lastName
));
676 $suffix = $this->_getRandomIndex($this->suffix
);
678 return $this->prefix
[$prefix] . " $first_name $middle_name $last_name " . $this->suffix
[$suffix];
685 * This method adds data to the contact table
688 * contact_type 'Individual' 'Household' 'Organization'
689 * preferred_communication (random 1 to 3)
692 public function addContact() {
695 $contact = new CRM_Contact_DAO_Contact();
697 for ($id = 1; $id <= self
::NUM_CONTACT
; $id++
) {
698 $contact->contact_type
= $this->getContactType($id +
1);
699 $contact->do_not_phone
= mt_rand(0, 1);
700 $contact->do_not_email
= mt_rand(0, 1);
701 $contact->do_not_post
= mt_rand(0, 1);
702 $contact->do_not_trade
= mt_rand(0, 1);
703 $contact->preferred_communication_method
= $this->_getRandomElement($this->preferredCommunicationMethod
);
704 $this->_insert($contact);
712 * This method adds individual's data to the contact table
714 * The following fields are generated and added.
716 * contact_uuid - individual
717 * contact_rid - latest one
718 * first_name 'First Name $contact_uuid'
719 * middle_name 'Middle Name $contact_uuid'
720 * last_name 'Last Name $contact_uuid'
721 * job_title 'Job Title $contact_uuid'
722 * greeting_type - randomly select from the enum values
723 * custom_greeting - "custom greeting $contact_uuid'
726 public function addIndividual() {
728 $contact = new CRM_Contact_DAO_Contact();
730 for ($id = 1; $id <= $this->numIndividual
; $id++
) {
731 $contact->first_name
= ucfirst($this->_getRandomElement($this->firstName
));
732 $contact->middle_name
= ucfirst($this->_getRandomChar());
733 $contact->last_name
= ucfirst($this->_getRandomElement($this->lastName
));
734 $contact->prefix_id
= $this->_getRandomIndex($this->prefix
);
735 $contact->suffix_id
= $this->_getRandomIndex($this->suffix
);
736 $contact->greeting_type_id
= $this->_getRandomIndex($this->greetingType
);
737 $contact->gender_id
= $this->_getRandomIndex($this->gender
);
738 $contact->birth_date
= date("Ymd", mt_rand(0, time()));
739 $contact->is_deceased
= mt_rand(0, 1);
741 $contact->id
= $this->individual
[($id - 1)];
743 // also update the sort name for the contact id.
744 $contact->display_name
= trim($this->prefix
[$contact->prefix_id
] . " $contact->first_name $contact->middle_name $contact->last_name " . $this->suffix
[$contact->suffix_id
]);
745 $contact->sort_name
= $contact->last_name
. ', ' . $contact->first_name
;
746 $contact->hash
= crc32($contact->sort_name
);
747 $this->_update($contact);
755 * This method adds household's data to the contact table
757 * The following fields are generated and added.
759 * contact_uuid - household_individual
760 * contact_rid - latest one
761 * household_name 'household $contact_uuid primary contact $primary_contact_uuid'
762 * nick_name 'nick $contact_uuid'
763 * primary_contact_uuid = $household_individual[$contact_uuid][0];
766 public function addHousehold() {
768 $contact = new CRM_Contact_DAO_Contact();
769 for ($id = 1; $id <= $this->numHousehold
; $id++
) {
770 $cid = $this->household
[($id - 1)];
771 $contact->primary_contact_id
= $this->householdIndividual
[$cid][0];
773 // get the last name of the primary contact id
774 $individual = new CRM_Contact_DAO_Contact();
775 $individual->id
= $contact->primary_contact_id
;
776 $individual->find(TRUE);
777 $firstName = $individual->first_name
;
778 $lastName = $individual->last_name
;
780 // need to name the household and nick name appropriately
781 $contact->household_name
= "$firstName $lastName" . "'s home";
782 $contact->nick_name
= "$lastName" . "'s home";
784 $contact->id
= $this->household
[($id - 1)];
785 // need to update the sort name for the main contact table
786 $contact->display_name
= $contact->sort_name
= $contact->household_name
;
787 $contact->hash
= crc32($contact->sort_name
);
788 $this->_update($contact);
796 * This method adds organization data to the contact table
798 * The following fields are generated and added.
800 * contact_uuid - organization
801 * contact_rid - latest one
802 * organization_name 'organization $contact_uuid'
803 * legal_name 'legal $contact_uuid'
804 * nick_name 'nick $contact_uuid'
805 * sic_code 'sic $contact_uuid'
806 * primary_contact_id - random individual contact uuid
809 public function addOrganization() {
811 $contact = new CRM_Contact_DAO_Contact();
813 for ($id = 1; $id <= $this->numOrganization
; $id++
) {
814 $contact->id
= $this->organization
[($id - 1)];
815 $name = $this->_getRandomElement($this->organization_name
) . " " . $this->_getRandomElement($this->organization_field
) . " " . $this->_getRandomElement($this->organization_type
);
816 $contact->organization_name
= $name;
817 $contact->primary_contact_id
= $this->_getRandomElement($this->strict_individual
);
819 // need to update the sort name for the main contact table
820 $contact->display_name
= $contact->sort_name
= $contact->organization_name
;
821 $contact->hash
= crc32($contact->sort_name
);
822 $this->_update($contact);
830 * This method adds data to the contact_relationship table
832 * it adds the following fields
835 public function addRelationship() {
837 $relationship = new CRM_Contact_DAO_Relationship();
839 // all active for now.
840 $relationship->is_active
= 1;
842 foreach ($this->householdIndividual
as $household_id => $household_member) {
843 // add child_of relationship
845 $relationship->relationship_type_id
= self
::CHILD_OF
;
846 $relationship->contact_id_a
= $household_member[2];
847 $relationship->contact_id_b
= $household_member[0];
848 $this->_insert($relationship);
849 $relationship->contact_id_a
= $household_member[3];
850 $relationship->contact_id_b
= $household_member[0];
851 $this->_insert($relationship);
852 $relationship->contact_id_a
= $household_member[2];
853 $relationship->contact_id_b
= $household_member[1];
854 $this->_insert($relationship);
855 $relationship->contact_id_a
= $household_member[3];
856 $relationship->contact_id_b
= $household_member[1];
857 $this->_insert($relationship);
859 // add spouse_of relationship 1 for both the spouses
860 $relationship->relationship_type_id
= self
::SPOUSE_OF
;
861 $relationship->contact_id_a
= $household_member[1];
862 $relationship->contact_id_b
= $household_member[0];
863 $this->_insert($relationship);
865 // add sibling_of relationship 1 for both the siblings
866 $relationship->relationship_type_id
= self
::SIBLING_OF
;
867 $relationship->contact_id_a
= $household_member[3];
868 $relationship->contact_id_b
= $household_member[2];
869 $this->_insert($relationship);
871 // add head_of_household relationship 1 for head of house
872 $relationship->relationship_type_id
= self
::HEAD_OF_HOUSEHOLD
;
873 $relationship->contact_id_a
= $household_member[0];
874 $relationship->contact_id_b
= $household_id;
875 $this->_insert($relationship);
877 // add member_of_household relationship 3 for all other members
878 $relationship->relationship_type_id
= self
::MEMBER_OF_HOUSEHOLD
;
879 $relationship->contact_id_a
= $household_member[1];
880 $this->_insert($relationship);
881 $relationship->contact_id_a
= $household_member[2];
882 $this->_insert($relationship);
883 $relationship->contact_id_a
= $household_member[3];
884 $this->_insert($relationship);
892 * This method adds data to the location table
895 public function addLocation() {
896 // strict individuals
897 foreach ($this->strictIndividual
as $contactId) {
898 $this->_addLocation(self
::HOME
, $contactId);
902 foreach ($this->household
as $contactId) {
903 $this->_addLocation(self
::HOME
, $contactId);
907 foreach ($this->organization
as $contactId) {
908 $this->_addLocation(self
::MAIN
, $contactId);
912 $someIndividual = array_diff($this->individual
, $this->strictIndividual
);
913 $someIndividual = array_slice($someIndividual, 0, (int) (75 * ($this->numIndividual
- $this->numStrictIndividual
) / 100));
914 foreach ($someIndividual as $contactId) {
915 $this->_addLocation(self
::HOME
, $contactId, FALSE, TRUE);
920 * @param $locationTypeId
922 * @param bool $domain
923 * @param bool $isPrimary
925 private function _addLocation($locationTypeId, $contactId, $domain = FALSE, $isPrimary = TRUE) {
926 $this->_addAddress($locationTypeId, $contactId, $isPrimary);
928 // add two phones for each location
929 $this->_addPhone($locationTypeId, $contactId, '1', $isPrimary);
930 $this->_addPhone($locationTypeId, $contactId, '2', FALSE);
932 // need to get sort name to generate email id
933 $contact = new CRM_Contact_DAO_Contact();
934 $contact->id
= $contactId;
935 $contact->find(TRUE);
936 // get the sort name of the contact
937 $sortName = $contact->sort_name
;
938 if (!empty($sortName)) {
939 // add 2 email for each location
940 for ($emailId = 1; $emailId <= 2; $emailId++
) {
941 $this->_addEmail($locationTypeId, $contactId, $sortName, ($emailId == 1) && $isPrimary);
947 * @param $locationTypeId
949 * @param bool $isPrimary
950 * @param null $locationBlockID
953 private function _addAddress($locationTypeId, $contactId, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
954 $addressDAO = new CRM_Core_DAO_Address();
956 // add addresses now currently we are adding only 1 address for each location
957 $addressDAO->location_type_id
= $locationTypeId;
958 $addressDAO->contact_id
= $contactId;
959 $addressDAO->is_primary
= $isPrimary;
961 $addressDAO->street_number
= mt_rand(1, 1000);
962 $addressDAO->street_number_suffix
= ucfirst($this->_getRandomChar());
963 $addressDAO->street_number_predirectional
= $this->_getRandomElement($this->addressDirection
);
964 $addressDAO->street_name
= ucwords($this->_getRandomElement($this->streetName
));
965 $addressDAO->street_type
= $this->_getRandomElement($this->streetType
);
966 $addressDAO->street_number_postdirectional
= $this->_getRandomElement($this->addressDirection
);
967 $addressDAO->street_address
= $addressDAO->street_number_predirectional
. " " . $addressDAO->street_number
. $addressDAO->street_number_suffix
. " " . $addressDAO->street_name
. " " . $addressDAO->street_type
. " " . $addressDAO->street_number_postdirectional
;
968 $addressDAO->supplemental_address_1
= ucwords($this->_getRandomElement($this->supplementalAddress1
));
970 // some more random skips
971 // hack add lat / long for US based addresses
972 list($addressDAO->country_id
, $addressDAO->state_province_id
, $addressDAO->city
,
973 $addressDAO->postal_code
, $addressDAO->geo_code_1
, $addressDAO->geo_code_2
974 ) = self
::getZipCodeInfo();
976 //$addressDAO->county_id = 1;
978 $this->_insert($addressDAO);
986 private function _sortNameToEmail($sortName) {
987 $email = preg_replace("([^a-zA-Z0-9_-]*)", "", $sortName);
992 * @param $locationTypeId
995 * @param bool $isPrimary
996 * @param null $locationBlockID
999 private function _addPhone($locationTypeId, $contactId, $phoneType, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
1000 if ($contactId %
3) {
1001 $phone = new CRM_Core_DAO_Phone();
1002 $phone->location_type_id
= $locationTypeId;
1003 $phone->contact_id
= $contactId;
1004 $phone->is_primary
= $isPrimary;
1005 $phone->phone
= mt_rand(11111111, 99999999);
1006 $phone->phone_type_id
= $phoneType;
1007 $this->_insert($phone);
1012 * @param $locationTypeId
1015 * @param bool $isPrimary
1016 * @param null $locationBlockID
1017 * @param int $offset
1019 private function _addEmail($locationTypeId, $contactId, $sortName, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
1020 if ($contactId %
2) {
1021 $email = new CRM_Core_DAO_Email();
1022 $email->location_type_id
= $locationTypeId;
1023 $email->contact_id
= $contactId;
1024 $email->is_primary
= $isPrimary;
1026 $emailName = $this->_sortNameToEmail($sortName);
1027 $emailDomain = $this->_getRandomElement($this->emailDomain
);
1028 $tld = $this->_getRandomElement($this->emailTLD
);
1029 $email->email
= strtolower($emailName . "@" . $emailDomain . "." . $tld);
1030 $this->_insert($email);
1038 * This method populates the crm_entity_tag table
1041 public function addEntityTag() {
1043 $entity_tag = new CRM_Core_DAO_EntityTag();
1045 // add categories 1,2,3 for Organizations.
1046 for ($i = 0; $i < $this->numOrganization
; $i +
= 2) {
1047 $org_id = $this->organization
[$i];
1048 // echo "org_id = $org_id\n";
1049 $entity_tag->contact_id
= $this->organization
[$i];
1050 $entity_tag->tag_id
= mt_rand(1, 3);
1051 $this->_insert($entity_tag);
1054 // add categories 4,5 for Individuals.
1055 for ($i = 0; $i < $this->numIndividual
; $i +
= 2) {
1056 $entity_tag->contact_id
= $this->individual
[$i];
1057 if (($entity_tag->contact_id
) %
3) {
1058 $entity_tag->tag_id
= mt_rand(4, 5);
1059 $this->_insert($entity_tag);
1062 // some of the individuals are in both categories (4 and 5).
1063 $entity_tag->tag_id
= 4;
1064 $this->_insert($entity_tag);
1065 $entity_tag->tag_id
= 5;
1066 $this->_insert($entity_tag);
1075 * This method populates the crm_entity_tag table
1078 public function addGroup() {
1079 // add the 3 groups first
1080 $numGroup = count($this->group
);
1081 require_once 'CRM/Contact/BAO/Group.php';
1082 for ($i = 0; $i < $numGroup; $i++
) {
1083 $group = new CRM_Contact_BAO_Group();
1084 $group->name
= $this->group
[$i];
1085 $group->title
= $this->group
[$i];
1086 $group->group_type
= "\ 11\ 12\ 1";
1087 $group->visibility
= 'Public Pages';
1088 $group->is_active
= 1;
1090 $group->buildClause();
1094 // 60 are for newsletter
1095 for ($i = 0; $i < 60; $i++
) {
1096 $groupContact = new CRM_Contact_DAO_GroupContact();
1097 // newsletter subscribers
1098 $groupContact->group_id
= 2;
1099 $groupContact->contact_id
= $this->individual
[$i];
1100 // membership status
1101 $groupContact->status
= $this->_getRandomElement($this->groupMembershipStatus
);
1103 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1104 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1106 $subscriptionHistory->group_id
= $groupContact->group_id
;
1107 $subscriptionHistory->status
= $groupContact->status
;
1109 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1110 $subscriptionHistory->date
= $this->_getRandomDate();
1111 if ($groupContact->status
!= 'Pending') {
1112 $this->_insert($groupContact);
1114 $this->_insert($subscriptionHistory);
1118 for ($i = 0; $i < 15; $i++
) {
1119 $groupContact = new CRM_Contact_DAO_GroupContact();
1121 $groupContact->group_id
= 3;
1122 $groupContact->contact_id
= $this->individual
[$i +
60];
1123 // membership status
1124 $groupContact->status
= $this->_getRandomElement($this->groupMembershipStatus
);
1126 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1127 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1128 $subscriptionHistory->group_id
= $groupContact->group_id
;
1129 $subscriptionHistory->status
= $groupContact->status
;
1131 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1132 $subscriptionHistory->date
= $this->_getRandomDate();
1134 if ($groupContact->status
!= 'Pending') {
1135 $this->_insert($groupContact);
1137 $this->_insert($subscriptionHistory);
1140 // 8 advisory board group
1141 for ($i = 0; $i < 8; $i++
) {
1142 $groupContact = new CRM_Contact_DAO_GroupContact();
1143 // advisory board group
1144 $groupContact->group_id
= 4;
1145 $groupContact->contact_id
= $this->individual
[$i * 7];
1146 // membership status
1147 $groupContact->status
= $this->_getRandomElement($this->groupMembershipStatus
);
1149 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1150 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1151 $subscriptionHistory->group_id
= $groupContact->group_id
;
1152 $subscriptionHistory->status
= $groupContact->status
;
1154 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1155 $subscriptionHistory->date
= $this->_getRandomDate();
1157 if ($groupContact->status
!= 'Pending') {
1158 $this->_insert($groupContact);
1160 $this->_insert($subscriptionHistory);
1163 //In this function when we add groups that time we are cache the contact fields
1164 //But at the end of setup we are appending sample custom data, so for consistency
1166 Civi
::cache('fields')->flush();
1167 CRM_Core_BAO_Cache
::resetCaches();
1174 * This method populates the crm_note table
1177 public function addNote() {
1179 $note = new CRM_Core_DAO_Note();
1180 $note->entity_table
= 'civicrm_contact';
1181 $note->contact_id
= 1;
1183 for ($i = 0; $i < self
::NUM_CONTACT
; $i++
) {
1184 $note->entity_id
= $this->contact
[$i];
1185 if ($this->contact
[$i] %
5 ||
$this->contact
[$i] %
3 ||
$this->contact
[$i] %
2) {
1186 $this->_insertNote($note);
1195 * This method populates the crm_activity_history table
1198 public function addActivity() {
1199 $contactDAO = new CRM_Contact_DAO_Contact();
1200 $contactDAO->contact_type
= 'Individual';
1201 $contactDAO->selectAdd();
1202 $contactDAO->selectAdd('id');
1203 $contactDAO->orderBy('sort_name');
1204 $contactDAO->find();
1207 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
1209 while ($contactDAO->fetch()) {
1213 for ($i = 0; $i < self
::NUM_ACTIVITY
; $i++
) {
1214 $activityDAO = new CRM_Activity_DAO_Activity();
1215 $activityDAO->source_contact_id
= $contactDAO->id
;
1216 $activityTypeID = mt_rand(7, 10);
1218 $activityDAO->activity_type_id
= $activityTypeID;
1219 $activityDAO->subject
= "Subject for $activity[$activityTypeID]";
1220 $activityDAO->activity_date_time
= $this->_getRandomDate();
1221 $activityDAO->duration
= mt_rand(1, 6);
1222 $activityDAO->status_id
= 2;
1223 $this->_insert($activityDAO);
1225 $activityContactDAO = new CRM_Activity_DAO_ActivityContact();
1226 $activityContactDAO->activity_id
= $activityDAO->id
;
1227 $activityContactDAO->contact_id
= mt_rand(1, 101);
1228 $activityContactDAO->record_type_id
= CRM_Utils_Array
::key('Activity Source', $activityContacts);
1229 $this->_insert($activityContactDAO);
1231 if (in_array($activityTypeID, array(
1234 $activityTargetDAO = new CRM_Activity_DAO_ActivityContact();
1235 $activityTargetDAO->activity_id
= $activityDAO->id
;
1236 $activityTargetDAO->contact_id
= mt_rand(1, 101);
1237 $activityTargetDAO->record_type_id
= CRM_Utils_Array
::key('Activity Targets', $activityContacts);
1238 $this->_insert($activityTargetDAO);
1241 if ($activityTypeID == 7) {
1242 $activityAssignmentDAO = new CRM_Activity_DAO_ActivityContact();
1243 $activityAssignmentDAO->activity_id
= $activityDAO->id
;
1244 $activityAssignmentDAO->contact_id
= mt_rand(1, 101);
1245 $activityAssignmentDAO->record_type_id
= CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
1246 $this->_insert($activityAssignmentDAO);
1255 public static function getZipCodeInfo() {
1256 $stateID = mt_rand(1000, 5132);
1257 $offset = mt_rand(1, 4132);
1259 $query = "SELECT id, country_id from civicrm_state_province LIMIT $offset, 1";
1260 $dao = new CRM_Core_DAO();
1261 $dao->query($query);
1262 while ($dao->fetch()) {
1263 return array($dao->country_id
, $dao->id
);
1274 public static function getLatLong($zipCode) {
1275 $query = "http://maps.google.com/maps?q=$zipCode&output=js";
1276 $userAgent = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0";
1279 curl_setopt($ch, CURLOPT_URL
, $query);
1280 curl_setopt($ch, CURLOPT_HEADER
, FALSE);
1281 curl_setopt($ch, CURLOPT_USERAGENT
, $userAgent);
1282 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
1284 // grab URL and pass it to the browser
1285 $outstr = curl_exec($ch);
1287 // close CURL resource, and free up system resources
1290 $preg = "/'(<\?xml.+?)',/s";
1291 preg_match($preg, $outstr, $matches);
1293 $xml = simplexml_load_string($matches[1]);
1294 $attributes = $xml->center
->attributes();
1295 if (!empty($attributes)) {
1296 return array((float ) $attributes['lat'], (float ) $attributes['lng']);
1299 return array(NULL, NULL);
1302 public function addMembershipType() {
1303 $organizationDAO = new CRM_Contact_DAO_Contact();
1304 $organizationDAO->id
= 5;
1305 $organizationDAO->find(TRUE);
1306 $contact_id = $organizationDAO->contact_id
;
1308 $membershipType = "INSERT INTO civicrm_membership_type
1309 (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)
1311 ('General', 'Regular annual membership.', " . $contact_id . ", 3, 100, 'year', 1, 'rolling',null, null, 7, 'b_a', 'Public', 1, 1),
1312 ('Student', 'Discount membership for full-time students.', " . $contact_id . ", 1, 50, 'year', 1, 'rolling', null, null, 7, 'b_a', 'Public', 2, 1),
1313 ('Lifetime', 'Lifetime membership.', " . $contact_id . ", 2, 1200, 'lifetime', 1, 'rolling', null, null, 7, 'b_a', 'Admin', 3, 1);
1315 CRM_Core_DAO
::executeQuery($membershipType);
1318 public function addMembership() {
1319 $contact = new CRM_Contact_DAO_Contact();
1320 $contact->query("SELECT id FROM civicrm_contact where contact_type = 'Individual'");
1321 while ($contact->fetch()) {
1322 $contacts[] = $contact->id
;
1326 $randomContacts = array_slice($contacts, 0, 350);
1328 $sources = array('Payment', 'Donation', 'Check');
1329 $membershipTypes = array(2, 1);
1330 $membershipTypeNames = array('Student', 'General');
1331 $statuses = array(3, 4);
1334 INSERT INTO civicrm_membership
1335 (contact_id, membership_type_id, join_date, start_date, end_date, source, status_id)
1339 INSERT INTO civicrm_activity
1340 (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)
1344 foreach ($randomContacts as $count => $dontCare) {
1345 $source = self
::_getRandomElement($sources);
1346 $acititySourceId = $count +
1;
1347 if ((($count +
1) %
11 == 0)) {
1348 // lifetime membership, status can be anything
1349 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1350 $membership .= "( {$randomContacts[$count]}, 3, '{$startDate}', '{$startDate}', null, '{$source}', 1)";
1351 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'Lifetime', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1353 elseif (($count +
1) %
5 == 0) {
1354 // Grace or expired, memberhsip type is random of 1 & 2
1355 $randId = array_rand($membershipTypes);
1356 $membershipType = self
::_getRandomElement($membershipTypes);
1357 $startDate = date('Y-m-d', mktime(0, 0, 0,
1359 (date('d') - ($count * ($randId +
1) * ($randId +
1) * ($randId +
1))),
1360 (date('Y') - ($randId +
1))
1362 $partOfDate = explode('-', $startDate);
1363 $endDate = date('Y-m-d', mktime(0, 0, 0,
1365 ($partOfDate[2] - 1),
1366 ($partOfDate[0] +
($randId +
1))
1368 $membership .= "( {$randomContacts[$count]}, {$membershipType}, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', {$statuses[$randId]})";
1369 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, '{$membershipTypeNames[$randId]}', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1371 elseif (($count +
1) %
2 == 0) {
1372 // membership type 2
1373 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1374 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), (date('Y') +
1)));
1375 $membership .= "( {$randomContacts[$count]}, 2, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1376 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'Student', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1379 // membership type 1
1380 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1381 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), (date('Y') +
2)));
1382 $membership .= "( {$randomContacts[$count]}, 1, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1383 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'General', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1386 if ($count != 349) {
1392 CRM_Core_DAO
::executeQuery($membership);
1394 CRM_Core_DAO
::executeQuery($activity);
1402 public static function repairDate($date) {
1403 $dropArray = array('-' => '', ':' => '', ' ' => '');
1404 return strtr($date, $dropArray);
1407 public function addMembershipLog() {
1408 $membership = new CRM_Member_DAO_Membership();
1409 $membership->query("SELECT id FROM civicrm_membership");
1410 while ($membership->fetch()) {
1411 $ids[] = $membership->id
;
1413 require_once 'CRM/Member/DAO/MembershipLog.php';
1414 foreach ($ids as $id) {
1415 $membership = new CRM_Member_DAO_Membership();
1416 $membership->id
= $id;
1417 $membershipLog = new CRM_Member_DAO_MembershipLog();
1418 if ($membership->find(TRUE)) {
1419 $membershipLog->membership_id
= $membership->id
;
1420 $membershipLog->status_id
= $membership->status_id
;
1421 $membershipLog->start_date
= self
::repairDate($membership->start_date
);
1422 $membershipLog->end_date
= self
::repairDate($membership->end_date
);
1423 $membershipLog->modified_id
= $membership->contact_id
;
1424 $membershipLog->modified_date
= date("Ymd");
1425 $membershipLog->save();
1427 $membershipLog = NULL;
1431 public function createEvent() {
1432 $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)
1434 ( 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),
1435 ( 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),
1436 ( 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)
1438 CRM_Core_DAO
::executeQuery($event);
1440 $sql = "SELECT id from civicrm_address where street_address = 'S 14S El Camino Way E'";
1441 $eventAdd1 = CRM_Core_DAO
::singleValueQuery($sql);
1442 $sql = "SELECT id from civicrm_address where street_address = 'E 11B Woodbridge Path SW'";
1443 $eventAdd2 = CRM_Core_DAO
::singleValueQuery($sql);
1444 $sql = "SELECT id from civicrm_address where street_address = 'E 581O Lincoln Dr SW'";
1445 $eventAdd3 = CRM_Core_DAO
::singleValueQuery($sql);
1447 $event = "INSERT INTO civicrm_email (contact_id, location_type_id, email, is_primary, is_billing, on_hold, hold_date, reset_date)
1449 (NULL, 1, 'development@example.org', 0, 0, 0, NULL, NULL),
1450 (NULL, 1, 'tournaments@example.org', 0, 0, 0, NULL, NULL),
1451 (NULL, 1, 'celebration@example.org', 0, 0, 0, NULL, NULL)
1453 CRM_Core_DAO
::executeQuery($event);
1455 $sql = "SELECT id from civicrm_email where email = 'development@example.org'";
1456 $eventEmail1 = CRM_Core_DAO
::singleValueQuery($sql);
1457 $sql = "SELECT id from civicrm_email where email = 'tournaments@example.org'";
1458 $eventEmail2 = CRM_Core_DAO
::singleValueQuery($sql);
1459 $sql = "SELECT id from civicrm_email where email = 'celebration@example.org'";
1460 $eventEmail3 = CRM_Core_DAO
::singleValueQuery($sql);
1462 $event = "INSERT INTO civicrm_phone (contact_id, location_type_id, is_primary, is_billing, mobile_provider_id, phone, phone_type_id)
1464 (NULL, 1, 0, 0, NULL,'204 222-1000', '1'),
1465 (NULL, 1, 0, 0, NULL,'204 223-1000', '1'),
1466 (NULL, 1, 0, 0, NULL,'303 323-1000', '1')
1468 CRM_Core_DAO
::executeQuery($event);
1470 $sql = "SELECT id from civicrm_phone where phone = '204 222-1000'";
1471 $eventPhone1 = CRM_Core_DAO
::singleValueQuery($sql);
1472 $sql = "SELECT id from civicrm_phone where phone = '204 223-1000'";
1473 $eventPhone2 = CRM_Core_DAO
::singleValueQuery($sql);
1474 $sql = "SELECT id from civicrm_phone where phone = '303 323-1000'";
1475 $eventPhone3 = CRM_Core_DAO
::singleValueQuery($sql);
1477 $event = "INSERT INTO civicrm_loc_block ( address_id, email_id, phone_id, address_2_id, email_2_id, phone_2_id)
1479 ( $eventAdd1, $eventEmail1, $eventPhone1, NULL,NULL,NULL),
1480 ( $eventAdd2, $eventEmail2, $eventPhone2, NULL,NULL,NULL),
1481 ( $eventAdd3, $eventEmail3, $eventPhone3, NULL,NULL,NULL)
1484 CRM_Core_DAO
::executeQuery($event);
1486 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone1 AND email_id = $eventEmail1 AND address_id = $eventAdd1";
1487 $eventLok1 = CRM_Core_DAO
::singleValueQuery($sql);
1488 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone2 AND email_id = $eventEmail2 AND address_id = $eventAdd2";
1489 $eventLok2 = CRM_Core_DAO
::singleValueQuery($sql);
1490 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone3 AND email_id = $eventEmail3 AND address_id = $eventAdd3";
1491 $eventLok3 = CRM_Core_DAO
::singleValueQuery($sql);
1494 $optionGroup = "INSERT INTO civicrm_option_group ( name, is_reserved, is_active)
1496 ( 'civicrm_event.amount.1', 0, 1),
1497 ( 'civicrm_event.amount.2', 0, 1),
1498 ( 'civicrm_event.amount.3', 0, 1)
1500 CRM_Core_DAO
::executeQuery($optionGroup);
1502 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.1'";
1503 $page1 = CRM_Core_DAO
::singleValueQuery($sql);
1505 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.2'";
1506 $page2 = CRM_Core_DAO
::singleValueQuery($sql);
1508 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.3'";
1509 $page3 = CRM_Core_DAO
::singleValueQuery($sql);
1511 $optionValue = "INSERT INTO civicrm_option_value (option_group_id, label, value, is_default, weight, is_optgroup, is_reserved, is_active)
1513 ($page1, 'Single', '50', 0, 1, 0, 0, 1),
1514 ($page1, 'Couple', '100', 0, 2, 0, 0, 1),
1515 ($page1, 'Family', '200', 0, 3, 0, 0, 1),
1516 ($page2, 'Bass', '25', 0, 1, 0, 0, 1),
1517 ($page2, 'Tenor', '40', 0, 2, 0, 0, 1),
1518 ($page2, 'Soprano', '50', 0, 3, 0, 0, 1),
1519 ($page3, 'Tiny-tots (ages 5-8)', '800', 0, 1, 0, 0, 1),
1520 ($page3, 'Junior Stars (ages 9-12)', '1000', 0, 2, 0, 0, 1),
1521 ($page3, 'Super Stars (ages 13-18)', '1500', 0, 3, 0, 0, 1)";
1523 CRM_Core_DAO
::executeQuery($optionValue);
1525 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page1 AND civicrm_option_value.weight=2";
1526 $defaultFee1 = CRM_Core_DAO
::singleValueQuery($sql);
1528 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page2 AND civicrm_option_value.weight=2";
1529 $defaultFee2 = CRM_Core_DAO
::singleValueQuery($sql);
1531 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page3 AND civicrm_option_value.weight=2";
1532 $defaultFee3 = CRM_Core_DAO
::singleValueQuery($sql);
1534 $event = "INSERT INTO civicrm_event
1535 ( 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 )
1537 ( '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 ),
1538 ( '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 ),
1539 ( '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 )
1541 CRM_Core_DAO
::executeQuery($event);
1544 public function addParticipant() {
1546 $participant = new CRM_Event_DAO_Participant();
1548 for ($id = 1; $id <= self
::NUM_PARTICIPANT
; $id++
) {
1549 $participant->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1550 $participant->event_id
= mt_rand(1, 3);
1551 $participant->status_id
= mt_rand(1, 5);
1552 $participant->role_id
= mt_rand(1, 4);
1553 $participant->register_date
= $this->_getRandomDate();
1554 $participant->source
= "Credit Card";
1556 if ($participant->event_id
== 1) {
1557 $fee_level = "Single";
1560 elseif ($participant->event_id
== 2) {
1561 $fee_level = "Soprano";
1565 $fee_level = "Tiny-tots (ages 5-8)";
1568 $participant->fee_level
= $fee_level;
1569 $participant->fee_amount
= $fee_amount;
1570 $participant->is_test
= 0;
1572 $this->_insert($participant);
1576 public function addPCP() {
1578 INSERT INTO `civicrm_pcp`
1579 (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)
1581 ({$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);
1583 CRM_Core_DAO
::executeQuery($query);
1586 public function addContribution() {
1587 // add contributions
1588 $contribution = new CRM_Contribute_DAO_Contribution();
1590 for ($id = 1; $id <= self
::NUM_CONTRIBUTION
; $id++
) {
1591 $contribution->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1592 $contribution->financial_type_id
= mt_rand(1, 4);
1593 $contribution->contribution_page_id
= mt_rand(1, 3);
1594 $contribution->payment_instrument_id
= mt_rand(1, 5);
1595 $contribution->receive_date
= $this->_getRandomDate();
1596 $contribution->total_amount
= mt_rand(10, 99);
1597 $contribution->contribution_status_id
= mt_rand(1, 6);
1598 $contribution->trxn_id
= "#" . md5($contribution->receive_date
);
1599 $this->_insert($contribution);
1603 public function addSoftContribution() {
1604 $pcpRollNickNAme = array('Jones Family', 'Annie and the kids', 'Anonymous', 'Adam Family');
1606 $pcpPersonalNote = array('Helping Hands', 'Annie Helps', 'Anonymous', 'Adam Helps');
1608 $softContribution = new CRM_Contribute_DAO_ContributionSoft();
1610 $sql = "SELECT DISTINCT(contact_id), id, total_amount from civicrm_contribution LIMIT 200";
1612 $contriInfo = CRM_Core_DAO
::executeQuery($sql);
1614 $prevContactID = NULL;
1616 while ($contriInfo->fetch()) {
1617 if ($prevContactID) {
1618 $softContribution->contribution_id
= $contriInfo->id
;
1619 $softContribution->contact_id
= $prevContactID;
1620 $softContribution->amount
= $contriInfo->total_amount
;
1621 $softContribution->pcp_id
= 1;
1622 $softContribution->pcp_display_in_roll
= 1;
1623 $softContribution->pcp_roll_nickname
= $this->_getRandomElement($pcpRollNickNAme);
1624 $softContribution->pcp_personal_note
= $this->_getRandomElement($pcpPersonalNote);
1625 $this->_insert($softContribution);
1627 $prevContactID = $contriInfo->contact_id
;
1631 public function addPledge() {
1632 $pledge = "INSERT INTO civicrm_pledge
1633 (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)
1635 (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),
1636 (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),
1637 (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);
1639 CRM_Core_DAO
::executeQuery($pledge);
1642 public function addPledgePayment() {
1643 $pledgePayment = "INSERT INTO civicrm_pledge_payment
1644 ( pledge_id, contribution_id, scheduled_amount, scheduled_date, reminder_date, reminder_count, status_id)
1646 (1, 10, 500.00, '2010-07-01 13:03:45', null, 0, 1),
1647 (2, 11, 200.00, '2010-07-01 10:59:35', null, 0, 1),
1648 (2, null, 200.00, '2010-10-01 10:59:35',null, 0, 2),
1649 (2, null, 200.00, '2010-01-01 10:59:35',null, 0, 2),
1650 (2, null, 200.00, '2010-04-01 10:59:35',null, 0, 2),
1651 (3, 12, 200.00, '2010-06-01 11:00:12', null, 0, 1),
1652 (3, 13, 200.00, '2010-07-01 10:59:35', '2010-06-28 10:59:41', 1, 1),
1653 (3, null, 200.00, '2010-08-01 11:00:12', null, 0, 2);
1655 CRM_Core_DAO
::executeQuery($pledgePayment);
1658 public function addMembershipPayment() {
1659 $amount = array('50', '100', '1200');
1661 $contribution = new CRM_Contribute_DAO_Contribution();
1662 for ($id = 1; $id <= 200; $id++
) {
1663 $contribution->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1664 $contribution->financial_type_id
= mt_rand(1, 4);
1665 $contribution->payment_instrument_id
= mt_rand(1, 5);
1666 $contribution->receive_date
= $this->_getRandomDate();
1667 $contribution->total_amount
= $this->_getRandomElement($amount);
1668 $contribution->contribution_status_id
= mt_rand(1, 6);
1669 $contribution->trxn_id
= "#" . md5($contribution->receive_date
);
1670 $this->_insert($contribution);
1672 for ($i = 0; $i < 3; $i++
) {
1673 $contributionsArray = $membershipArray = array();
1674 $contributionSQL = "
1676 FROM civicrm_contribution
1677 WHERE contribution_page_id IS NULL AND
1678 total_amount = {$amount[$i]} limit 0, 50 ";
1680 $contributionDAO = CRM_Core_DAO
::executeQuery($contributionSQL);
1682 while ($contributionDAO->fetch()) {
1683 $contributionsArray[] = $contributionDAO->id
;
1688 FROM civicrm_membership
1689 WHERE civicrm_membership.membership_type_id = {$j} limit 0, 50";
1690 $membershipDAO = CRM_Core_DAO
::executeQuery($membershipSQL);
1692 while ($membershipDAO->fetch()) {
1693 $membershipArray[] = $membershipDAO->id
;
1696 $payemntOBJ = new CRM_Member_DAO_MembershipPayment();
1697 foreach ($membershipArray as $key => $membershipid) {
1698 $payemntOBJ->contribution_id
= $contributionsArray[$key];
1699 $payemntOBJ->membership_id
= $membershipid;
1700 $this->_insert($payemntOBJ);
1712 function user_access($str = NULL) {
1719 function module_list() {
1723 echo ("Starting data generation on " . date("F dS h:i:s A") . "\n");
1724 $obj1 = new CRM_GCD();
1726 $obj1->parseDataFile();
1729 $obj1->addContact();
1730 $obj1->addIndividual();
1731 $obj1->addHousehold();
1732 $obj1->addOrganization();
1733 $obj1->addRelationship();
1734 $obj1->addLocation();
1735 $obj1->addEntityTag();
1738 $obj1->addActivity();
1739 $obj1->addMembership();
1740 $obj1->addMembershipLog();
1741 $obj1->createEvent();
1742 $obj1->addParticipant();
1743 $obj1->addContribution();
1745 $obj1->addSoftContribution();
1747 $obj1->addPledgePayment();
1748 $obj1->addMembershipPayment();
1749 echo ("Ending data generation on " . date("F dS h:i:s A") . "\n");