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 require_once '../civicrm.config.php';
94 require_once 'CRM/Core/Config.php';
95 require_once 'CRM/Core/Error.php';
96 require_once 'CRM/Core/I18n.php';
98 require_once 'CRM/Core/DAO/Address.php';
99 require_once 'CRM/Core/DAO.php';
100 require_once 'CRM/Core/DAO/Phone.php';
101 require_once 'CRM/Core/DAO/Email.php';
102 require_once 'CRM/Core/DAO/EntityTag.php';
103 require_once 'CRM/Core/DAO/Note.php';
104 require_once 'CRM/Core/DAO/Domain.php';
106 require_once 'CRM/Contact/DAO/Group.php';
107 require_once 'CRM/Contact/DAO/GroupContact.php';
108 require_once 'CRM/Contact/DAO/SubscriptionHistory.php';
109 require_once 'CRM/Contact/DAO/Contact.php';
110 require_once 'CRM/Contact/DAO/Relationship.php';
111 require_once 'CRM/Event/DAO/Participant.php';
112 require_once 'CRM/Contribute/DAO/ContributionSoft.php';
113 require_once 'CRM/Member/DAO/MembershipPayment.php';
123 const DATA_FILENAME
= "sample_data.xml";
124 const NUM_DOMAIN
= 1;
125 const NUM_CONTACT
= 5000;
126 const NUM_CONTRIBUTION
= 2000;
127 const NUM_MEMBERSHIP
= 2000;
128 const NUM_PARTICIPANT
= 2000;
129 const INDIVIDUAL_PERCENT
= 75;
130 const HOUSEHOLD_PERCENT
= 15;
131 const ORGANIZATION_PERCENT
= 10;
132 const NUM_INDIVIDUAL_PER_HOUSEHOLD
= 4;
133 const NUM_ACTIVITY
= 150;
135 // relationship types from the table crm_relationship_type
138 const SIBLING_OF
= 3;
139 const HEAD_OF_HOUSEHOLD
= 6;
140 const MEMBER_OF_HOUSEHOLD
= 7;
143 // location types from the table crm_location_type
148 const ADD_TO_DB
= TRUE;
149 //const ADD_TO_DB=FALSE;
150 const DEBUG_LEVEL
= 1;
157 * enum's from database
160 private $preferredCommunicationMethod = array('1', '2', '3', '4', '5');
161 private $contactType = array('Individual', 'Household', 'Organization');
162 private $phoneType = array('1', '2', '3', '4');
165 * customizable enums (foreign keys)
168 private $prefix = array(1 => 'Mrs', 2 => 'Ms', 3 => 'Mr', 4 => 'Dr');
169 private $suffix = array(1 => 'Jr', 2 => 'Sr');
170 private $gender = array(1 => 'Female', 2 => 'Male');
171 private $greetingType = array(1 => 'Dear [first]', 2 => 'Dear [prefix] [first] [last]', 3 => 'Dear [prefix] [last]');
177 private $domain = array();
183 private $contact = array();
184 private $individual = array();
185 private $household = array();
186 private $organization = array();
190 * store names, firstnames, street 1, street2
193 private $firstName = array();
194 private $lastName = array();
195 private $streetName = array();
196 private $supplementalAddress1 = array();
197 private $city = array();
198 private $state = array();
199 private $country = array();
200 private $addressDirection = array();
201 private $streetType = array();
202 private $emailDomain = array();
203 private $emailTLD = array();
204 private $organizationName = array();
205 private $organizationField = array();
206 private $organizationType = array();
207 private $group = array();
208 private $note = array();
209 private $activity_type = array();
210 private $module = array();
211 private $callback = array();
212 private $party_registration = array();
213 private $degree = array();
214 private $school = array();
217 * stores the strict individual id and household id to individual id mapping
220 private $strictIndividual = array();
221 private $householdIndividual = array();
224 * sample data in xml format
227 private $sampleData = NULL;
233 private $numIndividual = 0;
234 private $numHousehold = 0;
235 private $numOrganization = 0;
236 private $numStrictIndividual = 0;
238 private $CSC = array(
242 1004 => array('San Francisco', 'Los Angeles', 'Palo Alto'),
244 1031 => array('New York', 'Albany'),
249 1113 => array('Mumbai', 'Pune', 'Nasik'),
251 1114 => array('Bangalore', 'Mangalore', 'Udipi'),
256 1115 => array('Warszawa', 'PÅ‚ock'),
258 1116 => array('Gdańsk', 'Gdynia'),
264 private $groupMembershipStatus = array('Added', 'Removed', 'Pending');
265 private $subscriptionHistoryMethod = array('Admin', 'Email');
275 * Get a randomly generated string.
279 private function _getRandomString($size = 32) {
282 // get an ascii code for each character
283 for ($i = 0; $i < $size; $i++
) {
284 $random_int = mt_rand(65, 122);
285 if (($random_int < 97) && ($random_int > 90)) {
286 // if ascii code between 90 and 97 substitute with space
289 $random_char = chr($random_int);
290 $string .= $random_char;
298 private function _getRandomChar() {
299 return chr(mt_rand(65, 90));
305 private function getRandomBoolean() {
306 return mt_rand(0, 1);
314 private function _getRandomElement(&$array1) {
315 return $array1[mt_rand(1, count($array1)) - 1];
323 private function _getRandomIndex(&$array1) {
324 return mt_rand(1, count($array1));
327 // country state city combo
332 private function _getRandomCSC() {
335 // $c = array_rand($this->CSC);
338 // the state array now
339 $s = array_rand($this->CSC
[$c]);
342 $ci = array_rand($this->CSC
[$c][$s]);
343 $city = $this->CSC
[$c][$s][$ci];
353 * Generate a random date.
355 * If both $startDate and $endDate are defined generate
358 * If only startDate is specified then date generated is
359 * between startDate + 1 year.
361 * if only endDate is specified then date generated is
362 * between endDate - 1 year.
364 * if none are specified - date is between today - 1year
367 * @param int $startDate Start Date in Unix timestamp
368 * @param int $endDate End Date in Unix timestamp
371 * @return string randomly generated date in the format "Ymd"
374 private function _getRandomDate($startDate = 0, $endDate = 0) {
376 // number of seconds per year
377 // $numSecond = 31536000;
378 // number of seconds for 2 year
379 $numSecond = 63072000;
381 $dateFormat = "YmdHis";
385 if ($startDate && $endDate) {
386 return date($dateFormat, mt_rand($startDate, $endDate));
389 // only startDate is defined
391 // $nextYear = mktime(0, 0, 0, date("m", $startDate), date("d", $startDate), date("Y")+1);
392 return date($dateFormat, mt_rand($startDate, $startDate +
$numSecond));
395 // only endDate is defined
397 return date($dateFormat, mt_rand($endDate - $numSecond, $endDate));
401 return date($dateFormat, mt_rand($today - $numSecond, $today));
404 // insert data into db's
409 private function _insert(&$dao) {
410 if (self
::ADD_TO_DB
) {
411 if (!$dao->insert()) {
412 echo "ERROR INSERT: " . mysqli_error($dao->getConnection()->connection
) . "\n";
419 // update data into db's
424 private function _update($dao) {
425 if (self
::ADD_TO_DB
) {
426 if (!$dao->update()) {
427 echo "ERROR UPDATE: " . mysqli_error($dao->getConnection()->connection
) . "\n";
437 * Helper function which randomly populates "note" and
438 * "date_modified" and inserts it.
444 private function _insertNote($note) {
445 $note->note
= $this->_getRandomElement($this->note
);
446 $note->modified_date
= $this->_getRandomDate();
447 $this->_insert($note);
452 * Start of public functions
455 public function __construct() {
456 // initialize all the vars
457 $this->numIndividual
= self
::INDIVIDUAL_PERCENT
* self
::NUM_CONTACT
/ 100;
458 $this->numHousehold
= self
::HOUSEHOLD_PERCENT
* self
::NUM_CONTACT
/ 100;
459 $this->numOrganization
= self
::ORGANIZATION_PERCENT
* self
::NUM_CONTACT
/ 100;
460 $this->numStrictIndividual
= $this->numIndividual
- ($this->numHousehold
* self
::NUM_INDIVIDUAL_PER_HOUSEHOLD
);
463 public function parseDataFile() {
465 $sampleData = simplexml_load_file(self
::DATA_FILENAME
);
468 foreach ($sampleData->first_names
->first_name
as $first_name) {
469 $this->firstName
[] = trim($first_name);
473 foreach ($sampleData->last_names
->last_name
as $last_name) {
474 $this->lastName
[] = trim($last_name);
478 foreach ($sampleData->street_names
->street_name
as $street_name) {
479 $this->streetName
[] = trim($street_name);
482 // supplemental address 1
483 foreach ($sampleData->supplemental_addresses_1
->supplemental_address_1
as $supplemental_address_1) {
484 $this->supplementalAddress1
[] = trim($supplemental_address_1);
488 foreach ($sampleData->cities
->city
as $city) {
489 $this->city
[] = trim($city);
492 // address directions
493 foreach ($sampleData->address_directions
->address_direction
as $address_direction) {
494 $this->addressDirection
[] = trim($address_direction);
498 foreach ($sampleData->street_types
->street_type
as $street_type) {
499 $this->streetType
[] = trim($street_type);
503 foreach ($sampleData->email_domains
->email_domain
as $email_domain) {
504 $this->emailDomain
[] = trim($email_domain);
507 // email top level domain
508 foreach ($sampleData->email_tlds
->email_tld
as $email_tld) {
509 $this->emailTLD
[] = trim($email_tld);
513 foreach ($sampleData->organization_names
->organization_name
as $organization_name) {
514 $this->organization_name
[] = trim($organization_name);
517 // organization field
518 foreach ($sampleData->organization_fields
->organization_field
as $organization_field) {
519 $this->organizationField
[] = trim($organization_field);
523 foreach ($sampleData->organization_types
->organization_type
as $organization_type) {
524 $this->organizationType
[] = trim($organization_type);
528 foreach ($sampleData->groups
->group
as $group) {
529 $this->group
[] = trim($group);
533 foreach ($sampleData->notes
->note
as $note) {
534 $this->note
[] = trim($note);
538 foreach ($sampleData->activity_types
->activity_type
as $activity_type) {
539 $this->activity_type
[] = trim($activity_type);
543 foreach ($sampleData->modules
->module
as $module) {
544 $this->module
[] = trim($module);
548 foreach ($sampleData->callbacks
->callback
as $callback) {
549 $this->callback
[] = trim($callback);
552 // custom data - party registration
553 foreach ($sampleData->party_registrations
->party_registration
as $party_registration) {
554 $this->party_registration
[] = trim($party_registration);
557 // custom data - degrees
558 foreach ($sampleData->degrees
->degree
as $degree) {
559 $this->degree
[] = trim($degree);
562 // custom data - schools
563 foreach ($sampleData->schools
->school
as $school) {
564 $this->school
[] = trim($school);
567 // custom data - issue
568 foreach ($sampleData->issue
->status
as $status) {
569 $this->issue
[] = trim($status);
572 // custom data - gotv
573 require_once 'CRM/Core/BAO/CustomOption.php';
574 foreach ($sampleData->gotv
->status
as $status) {
575 $this->gotv
[] = CRM_Core_DAO
::VALUE_SEPARATOR
. trim($status) . CRM_Core_DAO
::VALUE_SEPARATOR
;
578 // custom data - marital_status
579 foreach ($sampleData->marital_status
->status
as $status) {
580 $this->marital_status
[] = trim($status);
589 public function getContactType($id) {
590 if (in_array($id, $this->individual
)) {
593 if (in_array($id, $this->household
)) {
596 if (in_array($id, $this->organization
)) {
597 return 'Organization';
601 public function initDB() {
602 $config = CRM_Core_Config
::singleton();
607 * this function creates arrays for the following
611 * contact_location id
612 * contact_contact_location id
615 * contact_instant_message uuid
616 * contact_relationship uuid
621 public function initID() {
623 // may use this function in future if needed to get
624 // a consistent pattern of random numbers.
626 // get the domain and contact id arrays
627 $this->domain
= range(1, self
::NUM_DOMAIN
);
628 shuffle($this->domain
);
629 $this->contact
= range(2, self
::NUM_CONTACT +
1);
630 shuffle($this->contact
);
632 // get the individual, household and organizaton contacts
634 $this->individual
= array_slice($this->contact
, $offset, $this->numIndividual
);
635 $offset +
= $this->numIndividual
;
636 $this->household
= array_slice($this->contact
, $offset, $this->numHousehold
);
637 $offset +
= $this->numHousehold
;
638 $this->organization
= array_slice($this->contact
, $offset, $this->numOrganization
);
640 // get the strict individual contacts (i.e individual contacts not belonging to any household)
641 $this->strictIndividual
= array_slice($this->individual
, 0, $this->numStrictIndividual
);
643 // get the household to individual mapping array
644 $this->householdIndividual
= array_diff($this->individual
, $this->strictIndividual
);
645 $this->householdIndividual
= array_chunk($this->householdIndividual
, self
::NUM_INDIVIDUAL_PER_HOUSEHOLD
);
646 $this->householdIndividual
= array_combine($this->household
, $this->householdIndividual
);
653 * This method adds NUM_DOMAIN domains and then adds NUM_REVISION
654 * revisions for each domain with the latest revision being the last one..
657 public function addDomain() {
659 /* Add a location for domain 1 */
661 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
662 // $this->_addLocation(self::MAIN, 1, true);
664 $domain = new CRM_Core_DAO_Domain();
665 for ($id = 2; $id <= self
::NUM_DOMAIN
; $id++
) {
666 // domain name is pretty simple. it is "Domain $id"
667 $domain->name
= "Domain $id";
668 $domain->description
= "Description $id";
669 $domain->contact_name
= $this->randomName();
672 $this->_insert($domain);
673 // FIXME FOR NEW LOCATION BLOCK STRUCTURE
674 // $this->_addLocation(self::MAIN, $id, true);
681 public function randomName() {
682 $prefix = $this->_getRandomIndex($this->prefix
);
683 $first_name = ucfirst($this->_getRandomElement($this->firstName
));
684 $middle_name = ucfirst($this->_getRandomChar());
685 $last_name = ucfirst($this->_getRandomElement($this->lastName
));
686 $suffix = $this->_getRandomIndex($this->suffix
);
688 return $this->prefix
[$prefix] . " $first_name $middle_name $last_name " . $this->suffix
[$suffix];
695 * This method adds data to the contact table
698 * contact_type 'Individual' 'Household' 'Organization'
699 * preferred_communication (random 1 to 3)
702 public function addContact() {
705 $contact = new CRM_Contact_DAO_Contact();
707 for ($id = 1; $id <= self
::NUM_CONTACT
; $id++
) {
708 $contact->contact_type
= $this->getContactType($id +
1);
709 $contact->do_not_phone
= mt_rand(0, 1);
710 $contact->do_not_email
= mt_rand(0, 1);
711 $contact->do_not_post
= mt_rand(0, 1);
712 $contact->do_not_trade
= mt_rand(0, 1);
713 $contact->preferred_communication_method
= $this->_getRandomElement($this->preferredCommunicationMethod
);
714 $this->_insert($contact);
722 * This method adds individual's data to the contact table
724 * The following fields are generated and added.
726 * contact_uuid - individual
727 * contact_rid - latest one
728 * first_name 'First Name $contact_uuid'
729 * middle_name 'Middle Name $contact_uuid'
730 * last_name 'Last Name $contact_uuid'
731 * job_title 'Job Title $contact_uuid'
732 * greeting_type - randomly select from the enum values
733 * custom_greeting - "custom greeting $contact_uuid'
736 public function addIndividual() {
738 $contact = new CRM_Contact_DAO_Contact();
740 for ($id = 1; $id <= $this->numIndividual
; $id++
) {
741 $contact->first_name
= ucfirst($this->_getRandomElement($this->firstName
));
742 $contact->middle_name
= ucfirst($this->_getRandomChar());
743 $contact->last_name
= ucfirst($this->_getRandomElement($this->lastName
));
744 $contact->prefix_id
= $this->_getRandomIndex($this->prefix
);
745 $contact->suffix_id
= $this->_getRandomIndex($this->suffix
);
746 $contact->greeting_type_id
= $this->_getRandomIndex($this->greetingType
);
747 $contact->gender_id
= $this->_getRandomIndex($this->gender
);
748 $contact->birth_date
= date("Ymd", mt_rand(0, time()));
749 $contact->is_deceased
= mt_rand(0, 1);
751 $contact->id
= $this->individual
[($id - 1)];
753 // also update the sort name for the contact id.
754 $contact->display_name
= trim($this->prefix
[$contact->prefix_id
] . " $contact->first_name $contact->middle_name $contact->last_name " . $this->suffix
[$contact->suffix_id
]);
755 $contact->sort_name
= $contact->last_name
. ', ' . $contact->first_name
;
756 $contact->hash
= crc32($contact->sort_name
);
757 $this->_update($contact);
765 * This method adds household's data to the contact table
767 * The following fields are generated and added.
769 * contact_uuid - household_individual
770 * contact_rid - latest one
771 * household_name 'household $contact_uuid primary contact $primary_contact_uuid'
772 * nick_name 'nick $contact_uuid'
773 * primary_contact_uuid = $household_individual[$contact_uuid][0];
776 public function addHousehold() {
778 $contact = new CRM_Contact_DAO_Contact();
779 for ($id = 1; $id <= $this->numHousehold
; $id++
) {
780 $cid = $this->household
[($id - 1)];
781 $contact->primary_contact_id
= $this->householdIndividual
[$cid][0];
783 // get the last name of the primary contact id
784 $individual = new CRM_Contact_DAO_Contact();
785 $individual->id
= $contact->primary_contact_id
;
786 $individual->find(TRUE);
787 $firstName = $individual->first_name
;
788 $lastName = $individual->last_name
;
790 // need to name the household and nick name appropriately
791 $contact->household_name
= "$firstName $lastName" . "'s home";
792 $contact->nick_name
= "$lastName" . "'s home";
794 $contact->id
= $this->household
[($id - 1)];
795 // need to update the sort name for the main contact table
796 $contact->display_name
= $contact->sort_name
= $contact->household_name
;
797 $contact->hash
= crc32($contact->sort_name
);
798 $this->_update($contact);
806 * This method adds organization data to the contact table
808 * The following fields are generated and added.
810 * contact_uuid - organization
811 * contact_rid - latest one
812 * organization_name 'organization $contact_uuid'
813 * legal_name 'legal $contact_uuid'
814 * nick_name 'nick $contact_uuid'
815 * sic_code 'sic $contact_uuid'
816 * primary_contact_id - random individual contact uuid
819 public function addOrganization() {
821 $contact = new CRM_Contact_DAO_Contact();
823 for ($id = 1; $id <= $this->numOrganization
; $id++
) {
824 $contact->id
= $this->organization
[($id - 1)];
825 $name = $this->_getRandomElement($this->organization_name
) . " " . $this->_getRandomElement($this->organization_field
) . " " . $this->_getRandomElement($this->organization_type
);
826 $contact->organization_name
= $name;
827 $contact->primary_contact_id
= $this->_getRandomElement($this->strict_individual
);
829 // need to update the sort name for the main contact table
830 $contact->display_name
= $contact->sort_name
= $contact->organization_name
;
831 $contact->hash
= crc32($contact->sort_name
);
832 $this->_update($contact);
840 * This method adds data to the contact_relationship table
842 * it adds the following fields
845 public function addRelationship() {
847 $relationship = new CRM_Contact_DAO_Relationship();
849 // all active for now.
850 $relationship->is_active
= 1;
852 foreach ($this->householdIndividual
as $household_id => $household_member) {
853 // add child_of relationship
855 $relationship->relationship_type_id
= self
::CHILD_OF
;
856 $relationship->contact_id_a
= $household_member[2];
857 $relationship->contact_id_b
= $household_member[0];
858 $this->_insert($relationship);
859 $relationship->contact_id_a
= $household_member[3];
860 $relationship->contact_id_b
= $household_member[0];
861 $this->_insert($relationship);
862 $relationship->contact_id_a
= $household_member[2];
863 $relationship->contact_id_b
= $household_member[1];
864 $this->_insert($relationship);
865 $relationship->contact_id_a
= $household_member[3];
866 $relationship->contact_id_b
= $household_member[1];
867 $this->_insert($relationship);
869 // add spouse_of relationship 1 for both the spouses
870 $relationship->relationship_type_id
= self
::SPOUSE_OF
;
871 $relationship->contact_id_a
= $household_member[1];
872 $relationship->contact_id_b
= $household_member[0];
873 $this->_insert($relationship);
875 // add sibling_of relationship 1 for both the siblings
876 $relationship->relationship_type_id
= self
::SIBLING_OF
;
877 $relationship->contact_id_a
= $household_member[3];
878 $relationship->contact_id_b
= $household_member[2];
879 $this->_insert($relationship);
881 // add head_of_household relationship 1 for head of house
882 $relationship->relationship_type_id
= self
::HEAD_OF_HOUSEHOLD
;
883 $relationship->contact_id_a
= $household_member[0];
884 $relationship->contact_id_b
= $household_id;
885 $this->_insert($relationship);
887 // add member_of_household relationship 3 for all other members
888 $relationship->relationship_type_id
= self
::MEMBER_OF_HOUSEHOLD
;
889 $relationship->contact_id_a
= $household_member[1];
890 $this->_insert($relationship);
891 $relationship->contact_id_a
= $household_member[2];
892 $this->_insert($relationship);
893 $relationship->contact_id_a
= $household_member[3];
894 $this->_insert($relationship);
902 * This method adds data to the location table
905 public function addLocation() {
906 // strict individuals
907 foreach ($this->strictIndividual
as $contactId) {
908 $this->_addLocation(self
::HOME
, $contactId);
912 foreach ($this->household
as $contactId) {
913 $this->_addLocation(self
::HOME
, $contactId);
917 foreach ($this->organization
as $contactId) {
918 $this->_addLocation(self
::MAIN
, $contactId);
922 $someIndividual = array_diff($this->individual
, $this->strictIndividual
);
923 $someIndividual = array_slice($someIndividual, 0, (int) (75 * ($this->numIndividual
- $this->numStrictIndividual
) / 100));
924 foreach ($someIndividual as $contactId) {
925 $this->_addLocation(self
::HOME
, $contactId, FALSE, TRUE);
930 * @param $locationTypeId
932 * @param bool $domain
933 * @param bool $isPrimary
935 private function _addLocation($locationTypeId, $contactId, $domain = FALSE, $isPrimary = TRUE) {
936 $this->_addAddress($locationTypeId, $contactId, $isPrimary);
938 // add two phones for each location
939 $this->_addPhone($locationTypeId, $contactId, '1', $isPrimary);
940 $this->_addPhone($locationTypeId, $contactId, '2', FALSE);
942 // need to get sort name to generate email id
943 $contact = new CRM_Contact_DAO_Contact();
944 $contact->id
= $contactId;
945 $contact->find(TRUE);
946 // get the sort name of the contact
947 $sortName = $contact->sort_name
;
948 if (!empty($sortName)) {
949 // add 2 email for each location
950 for ($emailId = 1; $emailId <= 2; $emailId++
) {
951 $this->_addEmail($locationTypeId, $contactId, $sortName, ($emailId == 1) && $isPrimary);
957 * @param $locationTypeId
959 * @param bool $isPrimary
960 * @param null $locationBlockID
963 private function _addAddress($locationTypeId, $contactId, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
964 $addressDAO = new CRM_Core_DAO_Address();
966 // add addresses now currently we are adding only 1 address for each location
967 $addressDAO->location_type_id
= $locationTypeId;
968 $addressDAO->contact_id
= $contactId;
969 $addressDAO->is_primary
= $isPrimary;
971 $addressDAO->street_number
= mt_rand(1, 1000);
972 $addressDAO->street_number_suffix
= ucfirst($this->_getRandomChar());
973 $addressDAO->street_number_predirectional
= $this->_getRandomElement($this->addressDirection
);
974 $addressDAO->street_name
= ucwords($this->_getRandomElement($this->streetName
));
975 $addressDAO->street_type
= $this->_getRandomElement($this->streetType
);
976 $addressDAO->street_number_postdirectional
= $this->_getRandomElement($this->addressDirection
);
977 $addressDAO->street_address
= $addressDAO->street_number_predirectional
. " " . $addressDAO->street_number
. $addressDAO->street_number_suffix
. " " . $addressDAO->street_name
. " " . $addressDAO->street_type
. " " . $addressDAO->street_number_postdirectional
;
978 $addressDAO->supplemental_address_1
= ucwords($this->_getRandomElement($this->supplementalAddress1
));
980 // some more random skips
981 // hack add lat / long for US based addresses
982 list($addressDAO->country_id
, $addressDAO->state_province_id
, $addressDAO->city
,
983 $addressDAO->postal_code
, $addressDAO->geo_code_1
, $addressDAO->geo_code_2
984 ) = self
::getZipCodeInfo();
986 //$addressDAO->county_id = 1;
988 $this->_insert($addressDAO);
996 private function _sortNameToEmail($sortName) {
997 $email = preg_replace("([^a-zA-Z0-9_-]*)", "", $sortName);
1002 * @param $locationTypeId
1005 * @param bool $isPrimary
1006 * @param null $locationBlockID
1007 * @param int $offset
1009 private function _addPhone($locationTypeId, $contactId, $phoneType, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
1010 if ($contactId %
3) {
1011 $phone = new CRM_Core_DAO_Phone();
1012 $phone->location_type_id
= $locationTypeId;
1013 $phone->contact_id
= $contactId;
1014 $phone->is_primary
= $isPrimary;
1015 $phone->phone
= mt_rand(11111111, 99999999);
1016 $phone->phone_type_id
= $phoneType;
1017 $this->_insert($phone);
1022 * @param $locationTypeId
1025 * @param bool $isPrimary
1026 * @param null $locationBlockID
1027 * @param int $offset
1029 private function _addEmail($locationTypeId, $contactId, $sortName, $isPrimary = FALSE, $locationBlockID = NULL, $offset = 1) {
1030 if ($contactId %
2) {
1031 $email = new CRM_Core_DAO_Email();
1032 $email->location_type_id
= $locationTypeId;
1033 $email->contact_id
= $contactId;
1034 $email->is_primary
= $isPrimary;
1036 $emailName = $this->_sortNameToEmail($sortName);
1037 $emailDomain = $this->_getRandomElement($this->emailDomain
);
1038 $tld = $this->_getRandomElement($this->emailTLD
);
1039 $email->email
= strtolower($emailName . "@" . $emailDomain . "." . $tld);
1040 $this->_insert($email);
1048 * This method populates the crm_entity_tag table
1051 public function addEntityTag() {
1053 $entity_tag = new CRM_Core_DAO_EntityTag();
1055 // add categories 1,2,3 for Organizations.
1056 for ($i = 0; $i < $this->numOrganization
; $i +
= 2) {
1057 $org_id = $this->organization
[$i];
1058 // echo "org_id = $org_id\n";
1059 $entity_tag->contact_id
= $this->organization
[$i];
1060 $entity_tag->tag_id
= mt_rand(1, 3);
1061 $this->_insert($entity_tag);
1064 // add categories 4,5 for Individuals.
1065 for ($i = 0; $i < $this->numIndividual
; $i +
= 2) {
1066 $entity_tag->contact_id
= $this->individual
[$i];
1067 if (($entity_tag->contact_id
) %
3) {
1068 $entity_tag->tag_id
= mt_rand(4, 5);
1069 $this->_insert($entity_tag);
1072 // some of the individuals are in both categories (4 and 5).
1073 $entity_tag->tag_id
= 4;
1074 $this->_insert($entity_tag);
1075 $entity_tag->tag_id
= 5;
1076 $this->_insert($entity_tag);
1085 * This method populates the crm_entity_tag table
1088 public function addGroup() {
1089 // add the 3 groups first
1090 $numGroup = count($this->group
);
1091 require_once 'CRM/Contact/BAO/Group.php';
1092 for ($i = 0; $i < $numGroup; $i++
) {
1093 $group = new CRM_Contact_BAO_Group();
1094 $group->name
= $this->group
[$i];
1095 $group->title
= $this->group
[$i];
1096 $group->group_type
= "\ 11\ 12\ 1";
1097 $group->visibility
= 'Public Pages';
1098 $group->is_active
= 1;
1100 $group->buildClause();
1104 // 60 are for newsletter
1105 for ($i = 0; $i < 60; $i++
) {
1106 $groupContact = new CRM_Contact_DAO_GroupContact();
1107 // newsletter subscribers
1108 $groupContact->group_id
= 2;
1109 $groupContact->contact_id
= $this->individual
[$i];
1110 // membership status
1111 $groupContact->status
= $this->_getRandomElement($this->groupMembershipStatus
);
1113 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1114 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1116 $subscriptionHistory->group_id
= $groupContact->group_id
;
1117 $subscriptionHistory->status
= $groupContact->status
;
1119 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1120 $subscriptionHistory->date
= $this->_getRandomDate();
1121 if ($groupContact->status
!= 'Pending') {
1122 $this->_insert($groupContact);
1124 $this->_insert($subscriptionHistory);
1128 for ($i = 0; $i < 15; $i++
) {
1129 $groupContact = new CRM_Contact_DAO_GroupContact();
1131 $groupContact->group_id
= 3;
1132 $groupContact->contact_id
= $this->individual
[$i +
60];
1133 // membership status
1134 $groupContact->status
= $this->_getRandomElement($this->groupMembershipStatus
);
1136 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1137 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1138 $subscriptionHistory->group_id
= $groupContact->group_id
;
1139 $subscriptionHistory->status
= $groupContact->status
;
1141 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1142 $subscriptionHistory->date
= $this->_getRandomDate();
1144 if ($groupContact->status
!= 'Pending') {
1145 $this->_insert($groupContact);
1147 $this->_insert($subscriptionHistory);
1150 // 8 advisory board group
1151 for ($i = 0; $i < 8; $i++
) {
1152 $groupContact = new CRM_Contact_DAO_GroupContact();
1153 // advisory board group
1154 $groupContact->group_id
= 4;
1155 $groupContact->contact_id
= $this->individual
[$i * 7];
1156 // membership status
1157 $groupContact->status
= $this->_getRandomElement($this->groupMembershipStatus
);
1159 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1160 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1161 $subscriptionHistory->group_id
= $groupContact->group_id
;
1162 $subscriptionHistory->status
= $groupContact->status
;
1164 $subscriptionHistory->method
= $this->_getRandomElement($this->subscriptionHistoryMethod
);
1165 $subscriptionHistory->date
= $this->_getRandomDate();
1167 if ($groupContact->status
!= 'Pending') {
1168 $this->_insert($groupContact);
1170 $this->_insert($subscriptionHistory);
1173 //In this function when we add groups that time we are cache the contact fields
1174 //But at the end of setup we are appending sample custom data, so for consistency
1176 require_once 'CRM/Core/BAO/Cache.php';
1177 CRM_Core_BAO_Cache
::deleteGroup('contact fields');
1184 * This method populates the crm_note table
1187 public function addNote() {
1189 $note = new CRM_Core_DAO_Note();
1190 $note->entity_table
= 'civicrm_contact';
1191 $note->contact_id
= 1;
1193 for ($i = 0; $i < self
::NUM_CONTACT
; $i++
) {
1194 $note->entity_id
= $this->contact
[$i];
1195 if ($this->contact
[$i] %
5 ||
$this->contact
[$i] %
3 ||
$this->contact
[$i] %
2) {
1196 $this->_insertNote($note);
1205 * This method populates the crm_activity_history table
1208 public function addActivity() {
1209 $contactDAO = new CRM_Contact_DAO_Contact();
1210 $contactDAO->contact_type
= 'Individual';
1211 $contactDAO->selectAdd();
1212 $contactDAO->selectAdd('id');
1213 $contactDAO->orderBy('sort_name');
1214 $contactDAO->find();
1217 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
1219 while ($contactDAO->fetch()) {
1223 for ($i = 0; $i < self
::NUM_ACTIVITY
; $i++
) {
1224 $activityDAO = new CRM_Activity_DAO_Activity();
1225 $activityDAO->source_contact_id
= $contactDAO->id
;
1226 $activityTypeID = mt_rand(7, 10);
1228 $activityDAO->activity_type_id
= $activityTypeID;
1229 $activityDAO->subject
= "Subject for $activity[$activityTypeID]";
1230 $activityDAO->activity_date_time
= $this->_getRandomDate();
1231 $activityDAO->duration
= mt_rand(1, 6);
1232 $activityDAO->status_id
= 2;
1233 $this->_insert($activityDAO);
1235 $activityContactDAO = new CRM_Activity_DAO_ActivityContact();
1236 $activityContactDAO->activity_id
= $activityDAO->id
;
1237 $activityContactDAO->contact_id
= mt_rand(1, 101);
1238 $activityContactDAO->record_type_id
= CRM_Utils_Array
::key('Activity Source', $activityContacts);
1239 $this->_insert($activityContactDAO);
1241 if (in_array($activityTypeID, array(
1244 $activityTargetDAO = new CRM_Activity_DAO_ActivityContact();
1245 $activityTargetDAO->activity_id
= $activityDAO->id
;
1246 $activityTargetDAO->contact_id
= mt_rand(1, 101);
1247 $activityTargetDAO->record_type_id
= CRM_Utils_Array
::key('Activity Targets', $activityContacts);
1248 $this->_insert($activityTargetDAO);
1251 if ($activityTypeID == 7) {
1252 $activityAssignmentDAO = new CRM_Activity_DAO_ActivityContact();
1253 $activityAssignmentDAO->activity_id
= $activityDAO->id
;
1254 $activityAssignmentDAO->contact_id
= mt_rand(1, 101);
1255 $activityAssignmentDAO->record_type_id
= CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
1256 $this->_insert($activityAssignmentDAO);
1265 public static function getZipCodeInfo() {
1266 $stateID = mt_rand(1000, 5132);
1267 $offset = mt_rand(1, 4132);
1269 $query = "SELECT id, country_id from civicrm_state_province LIMIT $offset, 1";
1270 $dao = new CRM_Core_DAO();
1271 $dao->query($query);
1272 while ($dao->fetch()) {
1273 return array($dao->country_id
, $dao->id
);
1284 public static function getLatLong($zipCode) {
1285 $query = "http://maps.google.com/maps?q=$zipCode&output=js";
1286 $userAgent = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0";
1289 curl_setopt($ch, CURLOPT_URL
, $query);
1290 curl_setopt($ch, CURLOPT_HEADER
, FALSE);
1291 curl_setopt($ch, CURLOPT_USERAGENT
, $userAgent);
1292 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
1294 // grab URL and pass it to the browser
1295 $outstr = curl_exec($ch);
1297 // close CURL resource, and free up system resources
1300 $preg = "/'(<\?xml.+?)',/s";
1301 preg_match($preg, $outstr, $matches);
1303 $xml = simplexml_load_string($matches[1]);
1304 $attributes = $xml->center
->attributes();
1305 if (!empty($attributes)) {
1306 return array((float ) $attributes['lat'], (float ) $attributes['lng']);
1309 return array(NULL, NULL);
1312 public function addMembershipType() {
1313 $organizationDAO = new CRM_Contact_DAO_Contact();
1314 $organizationDAO->id
= 5;
1315 $organizationDAO->find(TRUE);
1316 $contact_id = $organizationDAO->contact_id
;
1318 $membershipType = "INSERT INTO civicrm_membership_type
1319 (name, description, member_of_contact_id, financial_type_id, minimum_fee, duration_unit, duration_interval, period_type, fixed_period_start_day, fixed_period_rollover_day, relationship_type_id, relationship_direction, visibility, weight, is_active)
1321 ('General', 'Regular annual membership.', " . $contact_id . ", 3, 100, 'year', 1, 'rolling',null, null, 7, 'b_a', 'Public', 1, 1),
1322 ('Student', 'Discount membership for full-time students.', " . $contact_id . ", 1, 50, 'year', 1, 'rolling', null, null, 7, 'b_a', 'Public', 2, 1),
1323 ('Lifetime', 'Lifetime membership.', " . $contact_id . ", 2, 1200, 'lifetime', 1, 'rolling', null, null, 7, 'b_a', 'Admin', 3, 1);
1325 CRM_Core_DAO
::executeQuery($membershipType);
1328 public function addMembership() {
1329 $contact = new CRM_Contact_DAO_Contact();
1330 $contact->query("SELECT id FROM civicrm_contact where contact_type = 'Individual'");
1331 while ($contact->fetch()) {
1332 $contacts[] = $contact->id
;
1336 $randomContacts = array_slice($contacts, 0, 350);
1338 $sources = array('Payment', 'Donation', 'Check');
1339 $membershipTypes = array(2, 1);
1340 $membershipTypeNames = array('Student', 'General');
1341 $statuses = array(3, 4);
1344 INSERT INTO civicrm_membership
1345 (contact_id, membership_type_id, join_date, start_date, end_date, source, status_id)
1349 INSERT INTO civicrm_activity
1350 (source_contact_id, source_record_id, activity_type_id, subject, activity_date_time, duration, location, phone_id, phone_number, details, priority_id,parent_id, is_test, status_id)
1354 foreach ($randomContacts as $count => $dontCare) {
1355 $source = self
::_getRandomElement($sources);
1356 $acititySourceId = $count +
1;
1357 if ((($count +
1) %
11 == 0)) {
1358 // lifetime membership, status can be anything
1359 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1360 $membership .= "( {$randomContacts[$count]}, 3, '{$startDate}', '{$startDate}', null, '{$source}', 1)";
1361 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'Lifetime', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1363 elseif (($count +
1) %
5 == 0) {
1364 // Grace or expired, memberhsip type is random of 1 & 2
1365 $randId = array_rand($membershipTypes);
1366 $membershipType = self
::_getRandomElement($membershipTypes);
1367 $startDate = date('Y-m-d', mktime(0, 0, 0,
1369 (date('d') - ($count * ($randId +
1) * ($randId +
1) * ($randId +
1))),
1370 (date('Y') - ($randId +
1))
1372 $partOfDate = explode('-', $startDate);
1373 $endDate = date('Y-m-d', mktime(0, 0, 0,
1375 ($partOfDate[2] - 1),
1376 ($partOfDate[0] +
($randId +
1))
1378 $membership .= "( {$randomContacts[$count]}, {$membershipType}, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', {$statuses[$randId]})";
1379 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, '{$membershipTypeNames[$randId]}', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1381 elseif (($count +
1) %
2 == 0) {
1382 // membership type 2
1383 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1384 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), (date('Y') +
1)));
1385 $membership .= "( {$randomContacts[$count]}, 2, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1386 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'Student', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1389 // membership type 1
1390 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1391 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), (date('Y') +
2)));
1392 $membership .= "( {$randomContacts[$count]}, 1, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1393 $activity .= "( {$randomContacts[$count]}, {$acititySourceId}, 7, 'General', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1396 if ($count != 349) {
1402 CRM_Core_DAO
::executeQuery($membership);
1404 CRM_Core_DAO
::executeQuery($activity);
1412 public static function repairDate($date) {
1413 $dropArray = array('-' => '', ':' => '', ' ' => '');
1414 return strtr($date, $dropArray);
1417 public function addMembershipLog() {
1418 $membership = new CRM_Member_DAO_Membership();
1419 $membership->query("SELECT id FROM civicrm_membership");
1420 while ($membership->fetch()) {
1421 $ids[] = $membership->id
;
1423 require_once 'CRM/Member/DAO/MembershipLog.php';
1424 foreach ($ids as $id) {
1425 $membership = new CRM_Member_DAO_Membership();
1426 $membership->id
= $id;
1427 $membershipLog = new CRM_Member_DAO_MembershipLog();
1428 if ($membership->find(TRUE)) {
1429 $membershipLog->membership_id
= $membership->id
;
1430 $membershipLog->status_id
= $membership->status_id
;
1431 $membershipLog->start_date
= self
::repairDate($membership->start_date
);
1432 $membershipLog->end_date
= self
::repairDate($membership->end_date
);
1433 $membershipLog->modified_id
= $membership->contact_id
;
1434 $membershipLog->modified_date
= date("Ymd");
1435 $membershipLog->save();
1437 $membershipLog = NULL;
1441 public function createEvent() {
1442 $event = "INSERT INTO civicrm_address ( contact_id, location_type_id, is_primary, is_billing, street_address, street_number, street_number_suffix, street_number_predirectional, street_name, street_type, street_number_postdirectional, street_unit, supplemental_address_1, supplemental_address_2, supplemental_address_3, city, county_id, state_province_id, postal_code_suffix, postal_code, usps_adc, country_id, geo_code_1, geo_code_2, timezone)
1444 ( NULL, 1, 1, 1, 'S 14S El Camino Way E', 14, 'S', NULL, 'El Camino', 'Way', NULL, NULL, NULL, NULL, NULL, 'Collinsville', NULL, 1006, NULL, '6022', NULL, 1228, 41.8328, -72.9253, NULL),
1445 ( NULL, 1, 1, 1, 'E 11B Woodbridge Path SW', 11, 'B', NULL, 'Woodbridge', 'Path', NULL, NULL, NULL, NULL, NULL, 'Dayton', NULL, 1034, NULL, '45417', NULL, 1228, 39.7531, -84.2471, NULL),
1446 ( NULL, 1, 1, 1, 'E 581O Lincoln Dr SW', 581, 'O', NULL, 'Lincoln', 'Dr', NULL, NULL, NULL, NULL, NULL, 'Santa Fe', NULL, 1030, NULL, '87594', NULL, 1228, 35.5212, -105.982, NULL)
1448 CRM_Core_DAO
::executeQuery($event);
1450 $sql = "SELECT id from civicrm_address where street_address = 'S 14S El Camino Way E'";
1451 $eventAdd1 = CRM_Core_DAO
::singleValueQuery($sql);
1452 $sql = "SELECT id from civicrm_address where street_address = 'E 11B Woodbridge Path SW'";
1453 $eventAdd2 = CRM_Core_DAO
::singleValueQuery($sql);
1454 $sql = "SELECT id from civicrm_address where street_address = 'E 581O Lincoln Dr SW'";
1455 $eventAdd3 = CRM_Core_DAO
::singleValueQuery($sql);
1457 $event = "INSERT INTO civicrm_email (contact_id, location_type_id, email, is_primary, is_billing, on_hold, hold_date, reset_date)
1459 (NULL, 1, 'development@example.org', 0, 0, 0, NULL, NULL),
1460 (NULL, 1, 'tournaments@example.org', 0, 0, 0, NULL, NULL),
1461 (NULL, 1, 'celebration@example.org', 0, 0, 0, NULL, NULL)
1463 CRM_Core_DAO
::executeQuery($event);
1465 $sql = "SELECT id from civicrm_email where email = 'development@example.org'";
1466 $eventEmail1 = CRM_Core_DAO
::singleValueQuery($sql);
1467 $sql = "SELECT id from civicrm_email where email = 'tournaments@example.org'";
1468 $eventEmail2 = CRM_Core_DAO
::singleValueQuery($sql);
1469 $sql = "SELECT id from civicrm_email where email = 'celebration@example.org'";
1470 $eventEmail3 = CRM_Core_DAO
::singleValueQuery($sql);
1472 $event = "INSERT INTO civicrm_phone (contact_id, location_type_id, is_primary, is_billing, mobile_provider_id, phone, phone_type_id)
1474 (NULL, 1, 0, 0, NULL,'204 222-1000', '1'),
1475 (NULL, 1, 0, 0, NULL,'204 223-1000', '1'),
1476 (NULL, 1, 0, 0, NULL,'303 323-1000', '1')
1478 CRM_Core_DAO
::executeQuery($event);
1480 $sql = "SELECT id from civicrm_phone where phone = '204 222-1000'";
1481 $eventPhone1 = CRM_Core_DAO
::singleValueQuery($sql);
1482 $sql = "SELECT id from civicrm_phone where phone = '204 223-1000'";
1483 $eventPhone2 = CRM_Core_DAO
::singleValueQuery($sql);
1484 $sql = "SELECT id from civicrm_phone where phone = '303 323-1000'";
1485 $eventPhone3 = CRM_Core_DAO
::singleValueQuery($sql);
1487 $event = "INSERT INTO civicrm_loc_block ( address_id, email_id, phone_id, address_2_id, email_2_id, phone_2_id)
1489 ( $eventAdd1, $eventEmail1, $eventPhone1, NULL,NULL,NULL),
1490 ( $eventAdd2, $eventEmail2, $eventPhone2, NULL,NULL,NULL),
1491 ( $eventAdd3, $eventEmail3, $eventPhone3, NULL,NULL,NULL)
1494 CRM_Core_DAO
::executeQuery($event);
1496 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone1 AND email_id = $eventEmail1 AND address_id = $eventAdd1";
1497 $eventLok1 = CRM_Core_DAO
::singleValueQuery($sql);
1498 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone2 AND email_id = $eventEmail2 AND address_id = $eventAdd2";
1499 $eventLok2 = CRM_Core_DAO
::singleValueQuery($sql);
1500 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone3 AND email_id = $eventEmail3 AND address_id = $eventAdd3";
1501 $eventLok3 = CRM_Core_DAO
::singleValueQuery($sql);
1504 $optionGroup = "INSERT INTO civicrm_option_group ( name, is_reserved, is_active)
1506 ( 'civicrm_event.amount.1', 0, 1),
1507 ( 'civicrm_event.amount.2', 0, 1),
1508 ( 'civicrm_event.amount.3', 0, 1)
1510 CRM_Core_DAO
::executeQuery($optionGroup);
1512 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.1'";
1513 $page1 = CRM_Core_DAO
::singleValueQuery($sql);
1515 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.2'";
1516 $page2 = CRM_Core_DAO
::singleValueQuery($sql);
1518 $sql = "SELECT max(id) from civicrm_option_group where name = 'civicrm_event.amount.3'";
1519 $page3 = CRM_Core_DAO
::singleValueQuery($sql);
1521 $optionValue = "INSERT INTO civicrm_option_value (option_group_id, label, value, is_default, weight, is_optgroup, is_reserved, is_active)
1523 ($page1, 'Single', '50', 0, 1, 0, 0, 1),
1524 ($page1, 'Couple', '100', 0, 2, 0, 0, 1),
1525 ($page1, 'Family', '200', 0, 3, 0, 0, 1),
1526 ($page2, 'Bass', '25', 0, 1, 0, 0, 1),
1527 ($page2, 'Tenor', '40', 0, 2, 0, 0, 1),
1528 ($page2, 'Soprano', '50', 0, 3, 0, 0, 1),
1529 ($page3, 'Tiny-tots (ages 5-8)', '800', 0, 1, 0, 0, 1),
1530 ($page3, 'Junior Stars (ages 9-12)', '1000', 0, 2, 0, 0, 1),
1531 ($page3, 'Super Stars (ages 13-18)', '1500', 0, 3, 0, 0, 1)";
1533 CRM_Core_DAO
::executeQuery($optionValue);
1535 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page1 AND civicrm_option_value.weight=2";
1536 $defaultFee1 = CRM_Core_DAO
::singleValueQuery($sql);
1538 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page2 AND civicrm_option_value.weight=2";
1539 $defaultFee2 = CRM_Core_DAO
::singleValueQuery($sql);
1541 $sql = "SELECT max(id) FROM civicrm_option_value WHERE civicrm_option_value.option_group_id = $page3 AND civicrm_option_value.weight=2";
1542 $defaultFee3 = CRM_Core_DAO
::singleValueQuery($sql);
1544 $event = "INSERT INTO civicrm_event
1545 ( title, summary, description, event_type_id, participant_listing_id, is_public, start_date, end_date, is_online_registration, registration_link_text, max_participants, event_full_text, is_monetary, financial_type_id, is_map, is_active, fee_label, is_show_location, loc_block_id,intro_text, footer_text, confirm_title, confirm_text, confirm_footer_text, is_email_confirm, confirm_email_text, confirm_from_name, confirm_from_email, cc_confirm, bcc_confirm, default_fee_id, thankyou_title, thankyou_text, thankyou_footer_text, is_pay_later, pay_later_text, pay_later_receipt, is_multiple_registrations, allow_same_participant_emails )
1547 ( 'Fall Fundraiser Dinner', 'Kick up your heels at our Fall Fundraiser Dinner/Dance at Glen Echo Park! Come by yourself or bring a partner, friend or the entire family!', 'This event benefits our teen programs. Admission includes a full 3 course meal and wine or soft drinks. Grab your dancing shoes, bring the kids and come join the party!', 3, 1, 1, '2010-11-21 17:00:00', '2010-11-21 23:00:00', 1, 'Register Now', 100, 'Sorry! The Fall Fundraiser Dinner is full. Please call Jane at 204 222-1000 ext 33 if you want to be added to the waiting list.', 1, 4, 1, 1, 'Dinner Contribution', 1 ,$eventLok1,'Fill in the information below to join as at this wonderful dinner event.', NULL, 'Confirm Your Registration Information', 'Review the information below carefully.', NULL, 1, 'Contact the Development Department if you need to make any changes to your registration.', 'Fundraising Dept.', 'development@example.org', NULL, NULL, {$defaultFee1}, 'Thanks for Registering!', '<p>Thank you for your support. Your contribution will help us build even better tools.</p><p>Please tell your friends and colleagues about this wonderful event.</p>', '<p><a href=https://civicrm.org>Back to CiviCRM Home Page</a></p>', 1, 'I will send payment by check', 'Send a check payable to Our Organization within 3 business days to hold your reservation. Checks should be sent to: 100 Main St., Suite 3, San Francisco CA 94110', 0, 0 ),
1548 ( 'Summer Solstice Festival Day Concert', 'Festival Day is coming! Join us and help support your parks.', 'We will gather at noon, learn a song all together, and then join in a joyous procession to the pavilion. We will be one of many groups performing at this wonderful concert which benefits our city parks.', 5, 1, 1, '2011-06-01 12:00:00', '2011-06-01 17:00:00', 1, 'Register Now', 50, 'We have all the singers we can handle. Come to the pavilion anyway and join in from the audience.', 1, 2, NULL, 1, 'Festival Fee', 1, $eventLok2, 'Complete the form below and click Continue to register online for the festival. Or you can register by calling us at 204 222-1000 ext 22.', '', 'Confirm Your Registration Information', '', '', 1, 'This email confirms your registration. If you have questions or need to change your registration - please do not hesitate to call us.', 'Event Dept.', 'events@example.org', '', NULL, {$defaultFee2}, 'Thanks for Your Joining In!', '<p>Thank you for your support. Your participation will help build new parks.</p><p>Please tell your friends and colleagues about the concert.</p>', '<p><a href=https://civicrm.org>Back to CiviCRM Home Page</a></p>', 0, NULL, NULL, 1, 0 ),
1549 ( 'Rain-forest Cup Youth Soccer Tournament', 'Sign up your team to participate in this fun tournament which benefits several Rain-forest protection groups in the Amazon basin.', 'This is a FYSA Sanctioned Tournament, which is open to all USSF/FIFA affiliated organizations for boys and girls in age groups: U9-U10 (6v6), U11-U12 (8v8), and U13-U17 (Full Sided).', 3, 1, 1, '2011-12-27 07:00:00', '2011-12-29 17:00:00', 1, 'Register Now', 500, 'Sorry! All available team slots for this tournament have been filled. Contact Jill Futbol for information about the waiting list and next years event.', 1, 4, NULL, 1, 'Tournament Fees',1, $eventLok3, 'Complete the form below to register your team for this year''s tournament.', '<em>A Soccer Youth Event</em>', 'Review and Confirm Your Registration Information', '', '<em>A Soccer Youth Event</em>', 1, 'Contact our Tournament Director for eligibility details.', 'Tournament Director', 'tournament@example.org', '', NULL, {$defaultFee3}, 'Thanks for Your Support!', '<p>Thank you for your support. Your participation will help save thousands of acres of rainforest.</p>', '<p><a href=https://civicrm.org>Back to CiviCRM Home Page</a></p>', 0, NULL, NULL, 0, 0 )
1551 CRM_Core_DAO
::executeQuery($event);
1554 public function addParticipant() {
1556 $participant = new CRM_Event_DAO_Participant();
1558 for ($id = 1; $id <= self
::NUM_PARTICIPANT
; $id++
) {
1559 $participant->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1560 $participant->event_id
= mt_rand(1, 3);
1561 $participant->status_id
= mt_rand(1, 5);
1562 $participant->role_id
= mt_rand(1, 4);
1563 $participant->register_date
= $this->_getRandomDate();
1564 $participant->source
= "Credit Card";
1566 if ($participant->event_id
== 1) {
1567 $fee_level = "Single";
1570 elseif ($participant->event_id
== 2) {
1571 $fee_level = "Soprano";
1575 $fee_level = "Tiny-tots (ages 5-8)";
1578 $participant->fee_level
= $fee_level;
1579 $participant->fee_amount
= $fee_amount;
1580 $participant->is_test
= 0;
1582 $this->_insert($participant);
1586 public function addPCP() {
1588 INSERT INTO `civicrm_pcp`
1589 (contact_id, status_id, title, intro_text, page_text, donate_link_text, contribution_page_id, is_thermometer, is_honor_roll, goal_amount, referer, is_active)
1591 ({$this->individual[3]}, 2, 'My Personal Civi Fundraiser', 'I''m on a mission to get all my friends and family to help support my favorite open-source civic sector CRM.', '<p>Friends and family - please help build much needed infrastructure for the civic sector by supporting my personal campaign!</p>\r\n<p><a href=\"https://civicrm.org\">You can learn more about CiviCRM here</a>.</p>\r\n<p>Then click the <strong>Contribute Now</strong> button to go to our easy-to-use online contribution form.</p>', 'Contribute Now', 1, 1, 1, 5000.00, NULL, 1);
1593 CRM_Core_DAO
::executeQuery($query);
1596 public function addContribution() {
1597 // add contributions
1598 $contribution = new CRM_Contribute_DAO_Contribution();
1600 for ($id = 1; $id <= self
::NUM_CONTRIBUTION
; $id++
) {
1601 $contribution->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1602 $contribution->financial_type_id
= mt_rand(1, 4);
1603 $contribution->contribution_page_id
= mt_rand(1, 3);
1604 $contribution->payment_instrument_id
= mt_rand(1, 5);
1605 $contribution->receive_date
= $this->_getRandomDate();
1606 $contribution->total_amount
= mt_rand(10, 99);
1607 $contribution->contribution_status_id
= mt_rand(1, 6);
1608 $contribution->trxn_id
= "#" . md5($contribution->receive_date
);
1609 $this->_insert($contribution);
1613 public function addSoftContribution() {
1614 $pcpRollNickNAme = array('Jones Family', 'Annie and the kids', 'Anonymous', 'Adam Family');
1616 $pcpPersonalNote = array('Helping Hands', 'Annie Helps', 'Anonymous', 'Adam Helps');
1618 $softContribution = new CRM_Contribute_DAO_ContributionSoft();
1620 $sql = "SELECT DISTINCT(contact_id), id, total_amount from civicrm_contribution LIMIT 200";
1622 $contriInfo = CRM_Core_DAO
::executeQuery($sql);
1624 $prevContactID = NULL;
1626 while ($contriInfo->fetch()) {
1627 if ($prevContactID) {
1628 $softContribution->contribution_id
= $contriInfo->id
;
1629 $softContribution->contact_id
= $prevContactID;
1630 $softContribution->amount
= $contriInfo->total_amount
;
1631 $softContribution->pcp_id
= 1;
1632 $softContribution->pcp_display_in_roll
= 1;
1633 $softContribution->pcp_roll_nickname
= $this->_getRandomElement($pcpRollNickNAme);
1634 $softContribution->pcp_personal_note
= $this->_getRandomElement($pcpPersonalNote);
1635 $this->_insert($softContribution);
1637 $prevContactID = $contriInfo->contact_id
;
1641 public function addPledge() {
1642 $pledge = "INSERT INTO civicrm_pledge
1643 (contact_id, financial_type_id, contribution_page_id, amount, frequency_unit, frequency_interval, frequency_day, installments, start_date, create_date, acknowledge_date, modified_date, cancel_date, end_date, honor_contact_id, honor_type_id, status_id, is_test)
1645 (71, 1, 1, 500.00, 'month', 1, 1, 1, '2010-07-01 21:19:02', '2010-06-26 00:00:00', NULL, NULL, NULL,'2010-07-01 00:00:00', NULL, NULL, 1, 0),
1646 (43, 1, 1, 800.00, 'month', 3, 1, 4, '2010-07-01 10:11:09', '2010-06-23 10:11:14', '2010-06-23 10:11:18', NULL, NULL, '2010-04-01 10:11:40', NULL, NULL, 5, 0),
1647 (32, 1, 1, 600.00, 'month', 1, 1, 3, '2010-06-01 10:12:35', '2010-05-14 10:12:44', '2010-05-14 10:12:52', NULL, NULL, '2010-08-01 10:13:11', NULL, NULL, 5, 0);
1649 CRM_Core_DAO
::executeQuery($pledge);
1652 public function addPledgePayment() {
1653 $pledgePayment = "INSERT INTO civicrm_pledge_payment
1654 ( pledge_id, contribution_id, scheduled_amount, scheduled_date, reminder_date, reminder_count, status_id)
1656 (1, 10, 500.00, '2010-07-01 13:03:45', null, 0, 1),
1657 (2, 11, 200.00, '2010-07-01 10:59:35', null, 0, 1),
1658 (2, null, 200.00, '2010-10-01 10:59:35',null, 0, 2),
1659 (2, null, 200.00, '2010-01-01 10:59:35',null, 0, 2),
1660 (2, null, 200.00, '2010-04-01 10:59:35',null, 0, 2),
1661 (3, 12, 200.00, '2010-06-01 11:00:12', null, 0, 1),
1662 (3, 13, 200.00, '2010-07-01 10:59:35', '2010-06-28 10:59:41', 1, 1),
1663 (3, null, 200.00, '2010-08-01 11:00:12', null, 0, 2);
1665 CRM_Core_DAO
::executeQuery($pledgePayment);
1668 public function addMembershipPayment() {
1669 $amount = array('50', '100', '1200');
1671 $contribution = new CRM_Contribute_DAO_Contribution();
1672 for ($id = 1; $id <= 200; $id++
) {
1673 $contribution->contact_id
= mt_rand(1, self
::NUM_CONTACT
);
1674 $contribution->financial_type_id
= mt_rand(1, 4);
1675 $contribution->payment_instrument_id
= mt_rand(1, 5);
1676 $contribution->receive_date
= $this->_getRandomDate();
1677 $contribution->total_amount
= $this->_getRandomElement($amount);
1678 $contribution->contribution_status_id
= mt_rand(1, 6);
1679 $contribution->trxn_id
= "#" . md5($contribution->receive_date
);
1680 $this->_insert($contribution);
1682 for ($i = 0; $i < 3; $i++
) {
1683 $contributionsArray = $membershipArray = array();
1684 $contributionSQL = "
1686 FROM civicrm_contribution
1687 WHERE contribution_page_id IS NULL AND
1688 total_amount = {$amount[$i]} limit 0, 50 ";
1690 $contributionDAO = CRM_Core_DAO
::executeQuery($contributionSQL);
1692 while ($contributionDAO->fetch()) {
1693 $contributionsArray[] = $contributionDAO->id
;
1698 FROM civicrm_membership
1699 WHERE civicrm_membership.membership_type_id = {$j} limit 0, 50";
1700 $membershipDAO = CRM_Core_DAO
::executeQuery($membershipSQL);
1702 while ($membershipDAO->fetch()) {
1703 $membershipArray[] = $membershipDAO->id
;
1706 $payemntOBJ = new CRM_Member_DAO_MembershipPayment();
1707 foreach ($membershipArray as $key => $membershipid) {
1708 $payemntOBJ->contribution_id
= $contributionsArray[$key];
1709 $payemntOBJ->membership_id
= $membershipid;
1710 $this->_insert($payemntOBJ);
1722 function user_access($str = NULL) {
1729 function module_list() {
1733 echo ("Starting data generation on " . date("F dS h:i:s A") . "\n");
1734 $obj1 = new CRM_GCD();
1736 $obj1->parseDataFile();
1739 $obj1->addContact();
1740 $obj1->addIndividual();
1741 $obj1->addHousehold();
1742 $obj1->addOrganization();
1743 $obj1->addRelationship();
1744 $obj1->addLocation();
1745 $obj1->addEntityTag();
1748 $obj1->addActivity();
1749 $obj1->addMembership();
1750 $obj1->addMembershipLog();
1751 $obj1->createEvent();
1752 $obj1->addParticipant();
1753 $obj1->addContribution();
1755 $obj1->addSoftContribution();
1757 $obj1->addPledgePayment();
1758 $obj1->addMembershipPayment();
1759 echo ("Ending data generation on " . date("F dS h:i:s A") . "\n");