3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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.8*NUM_CONTACT
70 * Contact Household = 0.8*NUM_CONTACT to 0.9*NUM_CONTACT
72 * Contact Organization = 0.9*NUM_CONTACT to NUM_CONTACT
74 * Assumption is that each household contains 4 individuals
80 * Note: implication of using of mt_srand(1) in constructor
81 * The data generated will be done in a consistent manner
82 * so as to give the same data during each run (but this
83 * would involve populating the entire db at one go - since
84 * mt_srand(1) is in the constructor, if one needs to be able
85 * to get consistent random numbers then the mt_srand(1) shld
86 * be in each function that adds data to each table.
91 require_once '../civicrm.config.php';
94 require_once 'CRM/Core/ClassLoader.php';
95 CRM_Core_ClassLoader
::singleton()->register();
102 // Set ADD_TO_DB = FALSE to do a dry run
103 CONST ADD_TO_DB
= TRUE;
105 CONST DATA_FILENAME
= "sample_data.xml";
106 CONST NUM_DOMAIN
= 1;
107 CONST NUM_CONTACT
= 200;
108 CONST INDIVIDUAL_PERCENT
= 80;
109 CONST HOUSEHOLD_PERCENT
= 10;
110 CONST ORGANIZATION_PERCENT
= 10;
111 CONST NUM_INDIVIDUAL_PER_HOUSEHOLD
= 4;
112 CONST NUM_ACTIVITY
= 150;
114 // Relationship types from the table crm_relationship_type
117 CONST SIBLING_OF
= 3;
118 CONST EMPLOYEE_OF
= 4;
119 CONST HEAD_OF_HOUSEHOLD
= 6;
120 CONST MEMBER_OF_HOUSEHOLD
= 7;
122 // Location types from the table crm_location_type
131 function __construct() {
132 // initialize all the vars
133 $this->numIndividual
= self
::INDIVIDUAL_PERCENT
* self
::NUM_CONTACT
/ 100;
134 $this->numHousehold
= self
::HOUSEHOLD_PERCENT
* self
::NUM_CONTACT
/ 100;
135 $this->numOrganization
= self
::ORGANIZATION_PERCENT
* self
::NUM_CONTACT
/ 100;
136 $this->numStrictIndividual
= $this->numIndividual
- ($this->numHousehold
* self
::NUM_INDIVIDUAL_PER_HOUSEHOLD
);
139 foreach((array) simplexml_load_file(self
::DATA_FILENAME
) as $key => $val) {
141 $this->sampleData
[$key] = (array) $val['item'];
144 $config = CRM_Core_Config
::singleton();
148 * Public wrapper for calling private "add" functions
149 * Provides user feedback
151 public function generate($itemName) {
152 echo "Generating $itemName\n";
153 $fn = "add$itemName";
158 * this function creates arrays for the following
162 * contact_location id
163 * contact_contact_location id
166 * contact_instant_message uuid
167 * contact_relationship uuid
171 public function initID() {
172 // get the domain and contact id arrays
173 $this->domain
= range(1, self
::NUM_DOMAIN
);
174 shuffle($this->domain
);
176 // Get first contact id
177 $this->startCid
= $cid = CRM_Core_DAO
::singleValueQuery("SELECT MAX(id) FROM civicrm_contact");
178 $this->contact
= range($cid +
1, $cid + self
::NUM_CONTACT
);
179 shuffle($this->contact
);
181 // get the individual, household and organizaton contacts
183 $this->Individual
= array_slice($this->contact
, $offset, $this->numIndividual
);
184 $offset +
= $this->numIndividual
;
185 $this->Household
= array_slice($this->contact
, $offset, $this->numHousehold
);
186 $offset +
= $this->numHousehold
;
187 $this->Organization
= array_slice($this->contact
, $offset, $this->numOrganization
);
189 // get the strict individual contacts (i.e individual contacts not belonging to any household)
190 $this->strictIndividual
= array_slice($this->Individual
, 0, $this->numStrictIndividual
);
192 // get the household to individual mapping array
193 $this->householdIndividual
= array_slice($this->Individual
, $this->numStrictIndividual
);
194 $this->householdIndividual
= array_chunk($this->householdIndividual
, self
::NUM_INDIVIDUAL_PER_HOUSEHOLD
);
195 $this->householdIndividual
= array_combine($this->Household
, $this->householdIndividual
);
198 /*********************************
200 *********************************/
202 // enum's from database
203 private $preferredCommunicationMethod = array('1', '2', '3', '4', '5');
204 private $contactType = array('Individual', 'Household', 'Organization');
205 private $phoneType = array('1', '2', '3', '4');
207 // customizable enums (foreign keys)
208 private $prefix = array(
221 private $suffix = array(1 => 'Jr.', 2 => 'Sr.', 3 => 'II', 4 => 'III');
222 private $gender = array(1 => 'female', 2 => 'male');
225 private $domain = array();
227 // store contact id's
228 private $contact = array();
229 private $Individual = array();
230 private $Household = array();
231 private $Organization = array();
233 // store which contacts have a location entity
234 // for automatic management of is_primary field
235 private $location = array(
238 'Address' => array(),
241 // stores the strict individual id and household id to individual id mapping
242 private $strictIndividual = array();
243 private $householdIndividual = array();
244 private $householdName = array();
246 // sample data in xml format
247 private $sampleData = array();
251 private $numIndividual = 0;
252 private $numHousehold = 0;
253 private $numOrganization = 0;
254 private $numStrictIndividual = 0;
255 private $stateMap = array();
256 private $states = array();
258 private $groupMembershipStatus = array('Added', 'Removed', 'Pending');
259 private $subscriptionHistoryMethod = array('Admin', 'Email');
261 /*********************************
263 *********************************/
265 // get a randomly generated string
266 private function randomString($size = 32) {
269 // get an ascii code for each character
270 for ($i = 0; $i < $size; $i++
) {
271 $random_int = mt_rand(65, 122);
272 if (($random_int < 97) && ($random_int > 90)) {
273 // if ascii code between 90 and 97 substitute with space
276 $random_char = chr($random_int);
277 $string .= $random_char;
282 private function randomChar() {
283 return chr(mt_rand(65, 90));
287 * Get a random item from the sample data or any other array
289 * @param $items (array or string) - if string, used as key for sample data, if array, used as data source
291 * @return mixed (element from array)
295 private function randomItem($items) {
296 if (!is_array($items)) {
298 $items = $this->sampleData
[$key];
301 echo "Error: no items found for '$key'\n";
304 return $items[mt_rand(0, count($items) - 1)];
307 private function randomIndex($items) {
308 return $this->randomItem(array_keys($items));
311 private function randomKeyValue($items) {
312 $key = $this->randomIndex($items);
313 return array($key, $items[$key]);
316 private function probability($chance) {
317 if (mt_rand(0, 100) < ($chance * 100)) {
324 * Generate a random date.
326 * If both $startDate and $endDate are defined generate
329 * If only startDate is specified then date generated is
330 * between startDate + 1 year.
332 * if only endDate is specified then date generated is
333 * between endDate - 1 year.
335 * if none are specified - date is between today - 1year
338 * @param int $startDate Start Date in Unix timestamp
339 * @param int $endDate End Date in Unix timestamp
342 * @return string randomly generated date in the format "Ymd"
345 private function randomDate($startDate = 0, $endDate = 0) {
347 // number of seconds per year
348 $numSecond = 31536000;
349 $dateFormat = "Ymdhis";
353 if ($startDate && $endDate) {
354 return date($dateFormat, mt_rand($startDate, $endDate));
357 // only startDate is defined
359 return date($dateFormat, mt_rand($startDate, $startDate +
$numSecond));
362 // only endDate is defined
364 return date($dateFormat, mt_rand($endDate - $numSecond, $endDate));
368 return date($dateFormat, mt_rand($today - $numSecond, $today));
372 * Automatically manage the is_primary field by tracking which contacts have each item
374 private function isPrimary($cid, $type) {
375 if (empty($this->location
[$type][$cid])) {
376 $this->location
[$type][$cid] = TRUE;
383 * Execute a query unless we are doing a dry run
384 * Note: this wrapper should not be used for SELECT queries
386 private function _query($query, $params = array()) {
387 if (self
::ADD_TO_DB
) {
388 return CRM_Core_DAO
::executeQuery($query, $params);
393 * Call dao insert method unless we are doing a dry run
395 private function _insert(&$dao) {
396 if (self
::ADD_TO_DB
) {
397 if (!$dao->insert()) {
398 echo "ERROR INSERT: " . mysql_error() . "\n";
406 * Call dao update method unless we are doing a dry run
408 private function _update(&$dao) {
409 if (self
::ADD_TO_DB
) {
410 if (!$dao->update()) {
411 echo "ERROR UPDATE: " . mysql_error() . "\n";
419 * Add core DAO object
421 private function _addDAO($type, $params) {
422 $daoName = "CRM_Core_DAO_$type";
423 $obj = new $daoName();
424 foreach ($params as $key => $value) {
427 if (isset($this->location
[$type])) {
428 $obj->is_primary
= $this->isPrimary($params['contact_id'], $type);
430 $this->_insert($obj);
434 * Fetch contact type based on stored mapping
436 private function getContactType($id) {
437 foreach (array('Individual', 'Household', 'Organization') as $type) {
438 if (in_array($id, $this->$type)) {
445 * This method adds NUM_DOMAIN domains and then adds NUM_REVISION
446 * revisions for each domain with the latest revision being the last one..
448 private function addDomain() {
450 /* Add a location for domain 1 */
452 $domain = new CRM_Core_DAO_Domain();
453 for ($id = 2; $id <= self
::NUM_DOMAIN
; $id++
) {
454 // domain name is pretty simple. it is "Domain $id"
455 $domain->name
= "Domain $id";
456 $domain->description
= "Description $id";
457 $domain->contact_name
= $this->randomName();
460 $this->_insert($domain);
464 public function randomName() {
465 $first_name = $this->randomItem(($this->probability(.5) ?
'fe' : '') . 'male_name');
466 $middle_name = ucfirst($this->randomChar());
467 $last_name = $this->randomItem('last_name');
468 return "$first_name $middle_name. $last_name";
472 * This method adds data to the contact table
475 * contact_type 'Individual' 'Household' 'Organization'
476 * preferred_communication (random 1 to 3)
478 private function addContact() {
479 $contact = new CRM_Contact_DAO_Contact();
480 $cid = $this->startCid
;
482 for ($id = $cid +
1; $id <= $cid + self
::NUM_CONTACT
; $id++
) {
483 $contact->contact_type
= $this->getContactType($id);
484 $contact->do_not_phone
= $this->probability(.2);
485 $contact->do_not_email
= $this->probability(.2);
486 $contact->do_not_post
= $this->probability(.2);
487 $contact->do_not_trade
= $this->probability(.2);
488 $contact->preferred_communication_method
= NULL;
489 if ($this->probability(.5)) {
490 $contact->preferred_communication_method
= CRM_Core_DAO
::VALUE_SEPARATOR
. $this->randomItem($this->preferredCommunicationMethod
) . CRM_Core_DAO
::VALUE_SEPARATOR
;
492 $this->_insert($contact);
499 * This method adds individual's data to the contact table
501 * The following fields are generated and added.
503 * contact_uuid - individual
504 * contact_rid - latest one
505 * first_name 'First Name $contact_uuid'
506 * middle_name 'Middle Name $contact_uuid'
507 * last_name 'Last Name $contact_uuid'
508 * job_title 'Job Title $contact_uuid'
511 private function addIndividual() {
513 $contact = new CRM_Contact_DAO_Contact();
514 $year = 60 * 60 * 24 * 365.25;
517 foreach ($this->Individual
as $cid) {
518 $contact->is_deceased
= $contact->gender_id
= $contact->birth_date
= $contact->deceased_date
= $email = NULL;
519 list($gender_id, $gender) = $this->randomKeyValue($this->gender
);
520 $birth_date = mt_rand($now - 90 * $year, $now - 10 * $year);
522 $contact->last_name
= $this->randomItem('last_name');
524 // Manage household names
525 if (!in_array($contact->id
, $this->strictIndividual
)) {
526 // Find position in household
527 foreach ($this->householdIndividual
as $householdId => $house) {
528 foreach ($house as $position => $memberId) {
529 if ($memberId == $cid) {
534 // Head of household: set name
535 if (empty($this->householdName
[$householdId])) {
536 $this->householdName
[$householdId] = $contact->last_name
;
538 // Kids get household name, spouse might get it
539 if ($position > 1 ||
$this->probability(.5)) {
540 $contact->last_name
= $this->householdName
[$householdId];
542 elseif ($this->householdName
[$householdId] != $contact->last_name
) {
543 // Spouse might hyphenate name
544 if ($this->probability(.5)) {
545 $contact->last_name
.= '-' . $this->householdName
[$householdId];
547 // Kids might hyphenate name
549 $this->householdName
[$householdId] .= '-' . $contact->last_name
;
552 // Sensible ages and genders
553 $offset = mt_rand($now - 40 * $year, $now);
556 $birth_date = mt_rand($offset - 35 * $year, $offset - 20 * $year);
557 if ($this->probability(.8)) {
558 $gender_id = 2 - $position;
559 $gender = $this->gender
[$gender_id];
564 $birth_date = mt_rand($offset - 10 * $year, $offset);
567 // Non household people
569 if ($this->probability(.6)) {
570 $this->_addAddress($cid);
574 $contact->first_name
= $this->randomItem($gender . '_name');
575 $contact->middle_name
= $this->probability(.5) ?
'' : ucfirst($this->randomChar());
576 $age = intval(($now - $birth_date) / $year);
578 // Prefix and suffix by gender and age
579 $contact->prefix_id
= $contact->suffix_id
= $prefix = $suffix = NULL;
580 if ($this->probability(.5) && $age > 20) {
581 list($contact->prefix_id
, $prefix) = $this->randomKeyValue($this->prefix
[$gender_id]);
584 if ($gender == 'male' && $this->probability(.50)) {
585 list($contact->suffix_id
, $suffix) = $this->randomKeyValue($this->suffix
);
586 $suffix = ' ' . $suffix;
588 if ($this->probability(.7)) {
589 $contact->gender_id
= $gender_id;
591 if ($this->probability(.7)) {
592 $contact->birth_date
= date("Ymd", $birth_date);
595 // Deceased probability based on age
597 $contact->is_deceased
= $this->probability(($age - 30) / 100);
598 if ($contact->is_deceased
&& $this->probability(.7)) {
599 $contact->deceased_date
= $this->randomDate();
603 // Add 0, 1 or 2 email address
604 $count = mt_rand(0, 2);
605 for ($i = 0; $i < $count; ++
$i) {
606 $email = $this->_individualEmail($contact);
607 $this->_addEmail($cid, $email, self
::HOME
);
610 // Add 0, 1 or 2 phones
611 $count = mt_rand(0, 2);
612 for ($i = 0; $i < $count; ++
$i) {
613 $this->_addPhone($cid);
616 // Occasionally you get contacts with just an email in the db
617 if ($this->probability(.2) && $email) {
618 $contact->first_name
= $contact->last_name
= $contact->middle_name
= NULL;
619 $contact->is_deceased
= $contact->gender_id
= $contact->birth_date
= $contact->deceased_date
= NULL;
620 $contact->display_name
= $contact->sort_name
= $email;
621 $contact->postal_greeting_display
= $contact->email_greeting_display
= "Dear $email";
624 $contact->display_name
= $prefix . $contact->first_name
. ' ' . $contact->last_name
. $suffix;
625 $contact->sort_name
= $contact->last_name
. ', ' . $contact->first_name
;
626 $contact->postal_greeting_display
= $contact->email_greeting_display
= 'Dear ' . $contact->first_name
;
628 $contact->addressee_id
= $contact->postal_greeting_id
= $contact->email_greeting_id
= 1;
629 $contact->addressee_display
= $contact->display_name
;
630 $contact->hash
= crc32($contact->sort_name
);
632 $this->_update($contact);
637 * This method adds household's data to the contact table
639 * The following fields are generated and added.
641 * contact_uuid - household_individual
642 * contact_rid - latest one
643 * household_name 'household $contact_uuid primary contact $primary_contact_uuid'
644 * nick_name 'nick $contact_uuid'
645 * primary_contact_uuid = $household_individual[$contact_uuid][0];
648 private function addHousehold() {
650 $contact = new CRM_Contact_DAO_Contact();
651 foreach ($this->Household
as $cid) {
653 $this->_addAddress($cid);
656 $contact->household_name
= $this->householdName
[$cid] . " family";
657 // need to update the sort name for the main contact table
658 $contact->display_name
= $contact->sort_name
= $contact->household_name
;
659 $contact->postal_greeting_id
= $contact->email_greeting_id
= 5;
660 $contact->postal_greeting_display
= $contact->email_greeting_display
= 'Dear ' . $contact->household_name
;
661 $contact->addressee_id
= 2;
662 $contact->addressee_display
= $contact->display_name
;
663 $contact->hash
= crc32($contact->sort_name
);
664 $this->_update($contact);
669 * This method adds organization data to the contact table
671 * The following fields are generated and added.
673 * contact_uuid - organization
674 * contact_rid - latest one
675 * organization_name 'organization $contact_uuid'
676 * legal_name 'legal $contact_uuid'
677 * nick_name 'nick $contact_uuid'
678 * sic_code 'sic $contact_uuid'
679 * primary_contact_id - random individual contact uuid
682 private function addOrganization() {
684 $org = new CRM_Contact_DAO_Contact();
685 $employees = $this->Individual
;
688 foreach ($this->Organization
as $key => $id) {
689 $org->primary_contact_id
= $website = $email = NULL;
691 $address = $this->_addAddress($id);
693 $namePre = $this->randomItem('organization_prefix');
694 $nameMid = $this->randomItem('organization_name');
695 $namePost = $this->randomItem('organization_suffix');
697 // Some orgs are named after their location
698 if ($this->probability(.7)) {
699 $place = $this->randomItem(array('city', 'street_name', 'state'));
700 $namePre = $address[$place];
702 $org->organization_name
= "$namePre $nameMid $namePost";
704 // Most orgs have a website and email
705 if ($this->probability(.8)) {
706 $website = $this->_addWebsite($id, $org->organization_name
);
707 $url = str_replace('http://', '', $website['url']);
708 $email = $this->randomItem('email_address') . '@' . $url;
709 $this->_addEmail($id, $email, self
::MAIN
);
713 if ($this->probability(.8)) {
714 $indiv = new CRM_Contact_DAO_Contact();
715 $org->primary_contact_id
= $indiv->id
= $employees[$key];
716 $indiv->organization_name
= $org->organization_name
;
717 $indiv->employer_id
= $id;
718 $this->_update($indiv);
719 // Share address with employee
720 if ($this->probability(.8)) {
721 $this->_addAddress($indiv->id
, $id);
723 // Add work email for employee
726 $email = $this->_individualEmail($indiv, $url);
727 $this->_addEmail($indiv->id
, $email, self
::WORK
);
731 // need to update the sort name for the main contact table
732 $org->display_name
= $org->sort_name
= $org->organization_name
;
733 $org->addressee_id
= 3;
734 $org->addressee_display
= $org->display_name
;
735 $org->hash
= crc32($org->sort_name
);
736 $this->_update($org);
741 * This method adds data to the contact_relationship table
743 private function addRelationship() {
745 $relationship = new CRM_Contact_DAO_Relationship();
747 // Household relationships
748 foreach ($this->householdIndividual
as $household_id => $household_member) {
750 $relationship->is_active
= 1;
752 // add child_of relationship for each child
753 $relationship->relationship_type_id
= self
::CHILD_OF
;
754 foreach (array(0, 1) as $parent) {
755 foreach (array(2, 3) as $child) {
756 $relationship->contact_id_a
= $household_member[$child];
757 $relationship->contact_id_b
= $household_member[$parent];
758 $this->_insert($relationship);
762 // add sibling_of relationship
763 $relationship->relationship_type_id
= self
::SIBLING_OF
;
764 $relationship->contact_id_a
= $household_member[3];
765 $relationship->contact_id_b
= $household_member[2];
766 $this->_insert($relationship);
768 // add member_of_household relationships and shared address
769 $relationship->relationship_type_id
= self
::MEMBER_OF_HOUSEHOLD
;
770 $relationship->contact_id_b
= $household_id;
771 for ($i = 1; $i < 4; ++
$i) {
772 $relationship->contact_id_a
= $household_member[$i];
773 $this->_insert($relationship);
774 $this->_addAddress($household_member[$i], $household_id);
777 // Divorced/separated couples - end relationship and different address
778 if ($this->probability(.4)) {
779 $relationship->is_active
= 0;
780 $this->_addAddress($household_member[0]);
783 $this->_addAddress($household_member[0], $household_id);
786 // add head_of_household relationship 1 for head of house
787 $relationship->relationship_type_id
= self
::HEAD_OF_HOUSEHOLD
;
788 $relationship->contact_id_a
= $household_member[0];
789 $relationship->contact_id_b
= $household_id;
790 $this->_insert($relationship);
792 // add spouse_of relationship 1 for both the spouses
793 $relationship->relationship_type_id
= self
::SPOUSE_OF
;
794 $relationship->contact_id_a
= $household_member[1];
795 $relationship->contact_id_b
= $household_member[0];
796 $this->_insert($relationship);
799 // Add current employer relationships
800 $this->_query("INSERT INTO civicrm_relationship
801 (contact_id_a, contact_id_b, relationship_type_id, is_active)
802 (SELECT id, employer_id, " . self
::EMPLOYEE_OF
. ", 1 FROM civicrm_contact WHERE employer_id IN (" . implode(',', $this->Organization
) . "))"
807 * Create an address for a contact
809 * @param $cid int: contact id
810 * @param $masterContactId int: set if this is a shared address
812 private function _addAddress($cid, $masterContactId = NULL) {
814 // Share existing address
815 if ($masterContactId) {
816 $dao = new CRM_Core_DAO_Address();
817 $dao->is_primary
= 1;
818 $dao->contact_id
= $masterContactId;
820 $dao->master_id
= $dao->id
;
822 $dao->contact_id
= $cid;
823 $dao->is_primary
= $this->isPrimary($cid, 'Address');
824 $dao->location_type_id
= $this->getContactType($masterContactId) == 'Organization' ? self
::WORK
: self
::HOME
;
825 $this->_insert($dao);
828 // Generate new address
831 'contact_id' => $cid,
832 'location_type_id' => $this->getContactType($cid) == 'Organization' ? self
::MAIN
: self
::HOME
,
833 'street_number' => mt_rand(1, 1000),
834 'street_number_suffix' => ucfirst($this->randomChar()),
835 'street_name' => $this->randomItem('street_name'),
836 'street_type' => $this->randomItem('street_type'),
837 'street_number_postdirectional' => $this->randomItem('address_direction'),
841 $params['street_address'] = $params['street_number'] . $params['street_number_suffix'] . " " . $params['street_name'] . " " . $params['street_type'] . " " . $params['street_number_postdirectional'];
844 if ($params['location_type_id'] == self
::MAIN
) {
845 $params['supplemental_address_1'] = $this->randomItem('supplemental_addresses_1');
848 // Hack to add lat/long (limited to USA based addresses)
850 $params['country_id'],
851 $params['state_province_id'],
853 $params['postal_code'],
854 $params['geo_code_1'],
855 $params['geo_code_2'],
856 ) = $this->getZipCodeInfo();
858 $this->_addDAO('Address', $params);
859 $params['state'] = $this->states
[$params['state_province_id']];
865 * Add a phone number for a contact
867 * @param $cid int: contact id
869 private function _addPhone($cid) {
870 $area = $this->probability(.5) ?
'' : mt_rand(201, 899);
871 $pre = mt_rand(201, 899);
872 $post = mt_rand(1000, 9999);
874 'location_type_id' => $this->getContactType($cid) == 'Organization' ? self
::MAIN
: self
::HOME
,
875 'contact_id' => $cid,
876 'phone' => ($area ?
"($area) " : '') . "$pre-$post",
877 'phone_numeric' => $area . $pre . $post,
878 'phone_type_id' => mt_rand(1, 2),
880 $this->_addDAO('Phone', $params);
885 * Add an email for a contact
887 * @param $cid int: contact id
889 private function _addEmail($cid, $email, $locationType) {
891 'location_type_id' => $locationType,
892 'contact_id' => $cid,
895 $this->_addDAO('Email', $params);
900 * Add a website based on organization name
901 * Using common naming patterns
903 * @param $cid int: contact id
904 * @param $name str: contact name
906 private function _addWebsite($cid, $name) {
907 $part = array_pad(split(' ', strtolower($name)), 3, '');
908 if (count($part) > 3) {
909 // Abbreviate the place name if it's two words
910 $domain = $part[0][0] . $part[1][0] . $part[2] . $part[3];
913 // Common naming patterns
914 switch (mt_rand(1, 3)) {
916 $domain = $part[0] . $part[1] . $part[2];
919 $domain = $part[0] . $part[1];
922 $domain = $part[0] . $part[2];
927 'website_type_id' => 1,
928 'location_type_id' => self
::MAIN
,
929 'contact_id' => $cid,
930 'url' => "http://$domain.org",
932 $this->_addDAO('Website', $params);
937 * Create an email address based on a person's name
938 * Using common naming patterns
939 * @param $contact obj: individual contact record
940 * @param $domain str: supply a domain (i.e. for a work address)
942 private function _individualEmail($contact, $domain = NULL) {
943 $first = $contact->first_name
;
944 $last = $contact->last_name
;
947 $m = $contact->middle_name ?
$contact->middle_name
[0] . '.' : '';
948 // Common naming patterns
949 switch (mt_rand(1, 6)) {
951 $email = $first . $last;
954 $email = "$last.$first";
960 $email = $first . $l;
963 $email = "$last.$m$first";
966 $email = "$f$m$last";
969 //to ensure we dont insert
970 //invalid characters in email
971 $email = preg_replace("([^a-zA-Z0-9_\.-]*)", "", $email);
973 // Some people have numbers in their address
974 if ($this->probability(.4)) {
975 $email .= mt_rand(1, 99);
977 // Generate random domain if not specified
979 $domain = $this->randomItem('email_domain') . '.' . $this->randomItem('email_tld');
981 return strtolower($email) . '@' . $domain;
985 * This method populates the civicrm_entity_tag table
987 private function addEntityTag() {
989 $entity_tag = new CRM_Core_DAO_EntityTag();
991 // add categories 1,2,3 for Organizations.
992 for ($i = 0; $i < $this->numOrganization
; $i +
= 2) {
993 $org_id = $this->Organization
[$i];
994 // echo "org_id = $org_id\n";
995 $entity_tag->entity_id
= $this->Organization
[$i];
996 $entity_tag->entity_table
= 'civicrm_contact';
997 $entity_tag->tag_id
= mt_rand(1, 3);
998 $this->_insert($entity_tag);
1001 // add categories 4,5 for Individuals.
1002 for ($i = 0; $i < $this->numIndividual
; $i +
= 2) {
1003 $entity_tag->entity_table
= 'civicrm_contact';
1004 $entity_tag->entity_id
= $this->Individual
[$i];
1005 if (($entity_tag->entity_id
) %
3) {
1006 $entity_tag->tag_id
= mt_rand(4, 5);
1007 $this->_insert($entity_tag);
1010 // some of the individuals are in both categories (4 and 5).
1011 $entity_tag->tag_id
= 4;
1012 $this->_insert($entity_tag);
1013 $entity_tag->tag_id
= 5;
1014 $this->_insert($entity_tag);
1020 * This method populates the civicrm_group_contact table
1022 private function addGroup() {
1023 // add the 3 groups first
1024 foreach ($this->sampleData
['group'] as $groupName) {
1025 $group = new CRM_Contact_BAO_Group();
1026 $group->name
= $group->title
= $groupName;
1027 $group->group_type
= "\ 11\ 12\ 1";
1028 $group->visibility
= 'Public Pages';
1029 $group->is_active
= 1;
1031 $group->buildClause();
1035 // 60 are for newsletter
1036 for ($i = 0; $i < 60; $i++
) {
1037 $groupContact = new CRM_Contact_DAO_GroupContact();
1038 // newsletter subscribers
1039 $groupContact->group_id
= 2;
1040 $groupContact->contact_id
= $this->Individual
[$i];
1041 // always add members
1042 $groupContact->status
= 'Added';
1045 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1046 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1048 $subscriptionHistory->group_id
= $groupContact->group_id
;
1049 $subscriptionHistory->status
= $groupContact->status
;
1051 $subscriptionHistory->method
= $this->randomItem($this->subscriptionHistoryMethod
);
1052 $subscriptionHistory->date
= $this->randomDate();
1053 if ($groupContact->status
!= 'Pending') {
1054 $this->_insert($groupContact);
1056 $this->_insert($subscriptionHistory);
1060 for ($i = 0; $i < 15; $i++
) {
1061 $groupContact = new CRM_Contact_DAO_GroupContact();
1063 $groupContact->group_id
= 3;
1064 $groupContact->contact_id
= $this->Individual
[$i +
60];
1065 // membership status
1066 $groupContact->status
= 'Added';
1068 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1069 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1070 $subscriptionHistory->group_id
= $groupContact->group_id
;
1071 $subscriptionHistory->status
= $groupContact->status
;
1073 $subscriptionHistory->method
= $this->randomItem($this->subscriptionHistoryMethod
);
1074 $subscriptionHistory->date
= $this->randomDate();
1076 if ($groupContact->status
!= 'Pending') {
1077 $this->_insert($groupContact);
1079 $this->_insert($subscriptionHistory);
1082 // 8 advisory board group
1083 for ($i = 0; $i < 8; $i++
) {
1084 $groupContact = new CRM_Contact_DAO_GroupContact();
1085 // advisory board group
1086 $groupContact->group_id
= 4;
1087 $groupContact->contact_id
= $this->Individual
[$i * 7];
1088 // membership status
1089 $groupContact->status
= 'Added';
1091 $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory();
1092 $subscriptionHistory->contact_id
= $groupContact->contact_id
;
1093 $subscriptionHistory->group_id
= $groupContact->group_id
;
1094 $subscriptionHistory->status
= $groupContact->status
;
1096 $subscriptionHistory->method
= $this->randomItem($this->subscriptionHistoryMethod
);
1097 $subscriptionHistory->date
= $this->randomDate();
1099 if ($groupContact->status
!= 'Pending') {
1100 $this->_insert($groupContact);
1102 $this->_insert($subscriptionHistory);
1105 //In this function when we add groups that time we are cache the contact fields
1106 //But at the end of setup we are appending sample custom data, so for consistency
1108 CRM_Core_BAO_Cache
::deleteGroup('contact fields');
1112 * This method populates the civicrm_note table
1114 private function addNote() {
1116 'entity_table' => 'civicrm_contact',
1120 for ($i = 0; $i < self
::NUM_CONTACT
; $i +
= 10) {
1121 $params['entity_id'] = $this->randomItem($this->contact
);
1122 $params['note'] = $this->randomItem('note');
1123 $params['modified_date'] = $this->randomDate();
1124 $this->_addDAO('Note', $params);
1129 * This method populates the civicrm_activity_history table
1131 private function addActivity() {
1132 $contactDAO = new CRM_Contact_DAO_Contact();
1133 $contactDAO->contact_type
= 'Individual';
1134 $contactDAO->selectAdd();
1135 $contactDAO->selectAdd('id');
1136 $contactDAO->orderBy('sort_name');
1137 $contactDAO->find();
1140 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
1141 while ($contactDAO->fetch()) {
1145 for ($i = 0; $i < self
::NUM_ACTIVITY
; $i++
) {
1146 $activityDAO = new CRM_Activity_DAO_Activity();
1147 $activityTypeID = mt_rand(7, 10);
1148 $activity = CRM_Core_PseudoConstant
::activityType();
1149 $activityDAO->activity_type_id
= $activityTypeID;
1150 $activityDAO->subject
= "Subject for $activity[$activityTypeID]";
1151 $activityDAO->activity_date_time
= $this->randomDate();
1152 $activityDAO->duration
= mt_rand(1, 6);
1153 $activityDAO->status_id
= 2;
1154 $this->_insert($activityDAO);
1156 $activityContactDAO = new CRM_Activity_DAO_ActivityContact();
1157 $activityContactDAO->activity_id
= $activityDAO->id
;
1158 $activityContactDAO->contact_id
= $contactDAO->id
;
1159 $activityContactDAO->record_type_id
= CRM_Utils_Array
::key('Activity Source', $activityContacts);
1160 $this->_insert($activityContactDAO);
1162 if (in_array($activityTypeID, array(6, 9))) {
1163 $activityContactDAO = new CRM_Activity_DAO_ActivityContact();
1164 $activityContactDAO->activity_id
= $activityDAO->id
;
1165 $activityContactDAO->contact_id
= mt_rand(1, 101);
1166 $activityContactDAO->record_type_id
= CRM_Utils_Array
::key('Activity Targets', $activityContacts);
1167 $this->_insert($activityContactDAO);
1170 if ($activityTypeID == 7) {
1171 $activityContactDAO = new CRM_Activity_DAO_ActivityContact();
1172 $activityContactDAO->activity_id
= $activityDAO->id
;
1173 $activityContactDAO->contact_id
= mt_rand(1, 101);
1174 $activityContactDAO->record_type_id
= CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
1175 $this->_insert($activityContactDAO);
1181 function getZipCodeInfo() {
1183 if (!$this->stateMap
) {
1184 $query = 'SELECT id, name, abbreviation from civicrm_state_province where country_id = 1228';
1185 $dao = new CRM_Core_DAO();
1186 $dao->query($query);
1187 $this->stateMap
= array();
1188 while ($dao->fetch()) {
1189 $this->stateMap
[$dao->abbreviation
] = $dao->id
;
1190 $this->states
[$dao->id
] = $dao->name
;
1195 $offset = mt_rand(1, 43000);
1196 $query = "SELECT city, state, zip, latitude, longitude FROM zipcodes LIMIT $offset, 1";
1197 $dao = new CRM_Core_DAO();
1198 $dao->query($query);
1199 while ($dao->fetch()) {
1200 if ($this->stateMap
[$dao->state
]) {
1201 $stateID = $this->stateMap
[$dao->state
];
1207 $zip = str_pad($dao->zip
, 5, '0', STR_PAD_LEFT
);
1208 return array(1228, $stateID, $dao->city
, $zip, $dao->latitude
, $dao->longitude
);
1212 static function getLatLong($zipCode) {
1213 $query = "http://maps.google.com/maps?q=$zipCode&output=js";
1214 $userAgent = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0";
1217 curl_setopt($ch, CURLOPT_URL
, $query);
1218 curl_setopt($ch, CURLOPT_HEADER
, FALSE);
1219 curl_setopt($ch, CURLOPT_USERAGENT
, $userAgent);
1220 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
1222 // grab URL and pass it to the browser
1223 $outstr = curl_exec($ch);
1225 // close CURL resource, and free up system resources
1228 $preg = "/'(<\?xml.+?)',/s";
1229 preg_match($preg, $outstr, $matches);
1231 $xml = simplexml_load_string($matches[1]);
1232 $attributes = $xml->center
->attributes();
1233 if (!empty($attributes)) {
1234 return array((float ) $attributes['lat'], (float ) $attributes['lng']);
1237 return array(NULL, NULL);
1240 private function addMembershipType() {
1241 $organizationDAO = new CRM_Contact_DAO_Contact();
1242 $organizationDAO->id
= 5;
1243 $organizationDAO->find(TRUE);
1244 $contact_id = $organizationDAO->contact_id
;
1246 $membershipType = "INSERT INTO civicrm_membership_type
1247 (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)
1249 ('General', 'Regular annual membership.', " . $contact_id . ", 2, 100, 'year', 1, 'rolling',null, null, 7, 'b_a', 'Public', 1, 1),
1250 ('Student', 'Discount membership for full-time students.', " . $contact_id . ", 2, 50, 'year', 1, 'rolling', null, null, 7, 'b_a', 'Public', 2, 1),
1251 ('Lifetime', 'Lifetime membership.', " . $contact_id . ", 2, 1200, 'lifetime', 1, 'rolling', null, null, 7, 'b_a', 'Admin', 3, 1);
1253 $this->_query($membershipType);
1256 private function addMembership() {
1257 $contact = new CRM_Contact_DAO_Contact();
1258 $contact->query("SELECT id FROM civicrm_contact where contact_type = 'Individual'");
1259 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
1260 while ($contact->fetch()) {
1261 $contacts[] = $contact->id
;
1265 $randomContacts = array_slice($contacts, 20, 30);
1267 $sources = array('Payment', 'Donation', 'Check');
1268 $membershipTypes = array(1, 2);
1269 $membershipTypeNames = array('General', 'Student');
1270 $statuses = array(3, 4);
1273 INSERT INTO civicrm_membership
1274 (contact_id, membership_type_id, join_date, start_date, end_date, source, status_id)
1279 INSERT INTO civicrm_activity
1280 (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)
1284 $activityContact = "
1285 INSERT INTO civicrm_activity_contact
1286 (activity_id, contact_id, record_type_id)
1290 $currentActivityID = CRM_Core_DAO
::singleValueQuery("SELECT MAX(id) FROM civicrm_activity");
1291 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
1292 foreach ($randomContacts as $count => $dontCare) {
1293 $source = $this->randomItem($sources);
1294 $activitySourceId = $count +
1;
1295 $currentActivityID++
;
1296 $activityContact .= "( $currentActivityID, {$randomContacts[$count]}, {$sourceID} )";
1297 if ((($count +
1) %
11 == 0)) {
1298 // lifetime membership, status can be anything
1299 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1300 $membership .= "( {$randomContacts[$count]}, 3, '{$startDate}', '{$startDate}', null, '{$source}', 1)";
1301 $activity .= "( {$activitySourceId}, 7, 'Lifetime', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1303 elseif (($count +
1) %
5 == 0) {
1304 // Grace or expired, memberhsip type is random of 1 & 2
1305 $randIndex = array_rand($membershipTypes);
1306 $membershipTypeId = $membershipTypes[$randIndex];
1307 $membershipStatusId = $statuses[$randIndex];
1308 $membershipTypeName = $membershipTypeNames[$randIndex];
1309 $YearFactor = $membershipTypeId * 2;
1310 //reverse the type and consider as year factor.
1311 if ($YearFactor != 2) {
1314 $dateFactor = ($count * ($YearFactor) * ($YearFactor) * ($YearFactor));
1315 $startDate = date('Y-m-d', mktime(0, 0, 0,
1317 (date('d') - ($dateFactor)),
1318 (date('Y') - ($YearFactor))
1320 $partOfDate = explode('-', $startDate);
1321 $endDate = date('Y-m-d', mktime(0, 0, 0,
1323 ($partOfDate[2] - 1),
1324 ($partOfDate[0] +
($YearFactor))
1327 $membership .= "( {$randomContacts[$count]}, {$membershipTypeId}, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', {$membershipStatusId})";
1328 $activity .= "( {$activitySourceId}, 7, '{$membershipTypeName}', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1330 elseif (($count +
1) %
2 == 0) {
1331 // membership type 2
1332 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1333 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - ($count +
1)), (date('Y') +
1)));
1334 $membership .= "( {$randomContacts[$count]}, 2, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1335 $activity .= "( {$activitySourceId}, 7, 'Student', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1338 // membership type 1
1339 $startDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - $count), date('Y')));
1340 $endDate = date('Y-m-d', mktime(0, 0, 0, date('m'), (date('d') - ($count +
1)), (date('Y') +
2)));
1341 $membership .= "( {$randomContacts[$count]}, 1, '{$startDate}', '{$startDate}', '{$endDate}', '{$source}', 1)";
1342 $activity .= "( {$activitySourceId}, 7, 'General', '{$startDate} 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )";
1348 $activityContact .= ",";
1352 $this->_query($membership);
1353 $this->_query($activity);
1354 $this->_query($activityContact);
1357 static function repairDate($date) {
1358 $dropArray = array('-' => '', ':' => '', ' ' => '');
1359 return strtr($date, $dropArray);
1362 private function addMembershipLog() {
1363 $membership = new CRM_Member_DAO_Membership();
1364 $membership->query("SELECT id FROM civicrm_membership");
1365 while ($membership->fetch()) {
1366 $ids[] = $membership->id
;
1368 foreach ($ids as $id) {
1369 $membership = new CRM_Member_DAO_Membership();
1370 $membership->id
= $id;
1371 $membershipLog = new CRM_Member_DAO_MembershipLog();
1372 if ($membership->find(TRUE)) {
1373 $membershipLog->membership_id
= $membership->id
;
1374 $membershipLog->status_id
= $membership->status_id
;
1375 $membershipLog->start_date
= self
::repairDate($membership->start_date
);
1376 $membershipLog->end_date
= self
::repairDate($membership->end_date
);
1377 $membershipLog->modified_id
= $membership->contact_id
;
1378 $membershipLog->modified_date
= date("Ymd");
1379 $membershipLog->membership_type_id
= $membership->membership_type_id
;
1380 $membershipLog->save();
1382 $membershipLog = NULL;
1386 private function addEvent() {
1387 $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)
1389 ( NULL, 1, 1, 1, '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),
1390 ( NULL, 1, 1, 1, '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),
1391 ( NULL, 1, 1, 1, '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)
1393 $this->_query($event);
1395 $sql = "SELECT id from civicrm_address where street_address = '14S El Camino Way E'";
1396 $eventAdd1 = CRM_Core_DAO
::singleValueQuery($sql);
1397 $sql = "SELECT id from civicrm_address where street_address = '11B Woodbridge Path SW'";
1398 $eventAdd2 = CRM_Core_DAO
::singleValueQuery($sql);
1399 $sql = "SELECT id from civicrm_address where street_address = '581O Lincoln Dr SW'";
1400 $eventAdd3 = CRM_Core_DAO
::singleValueQuery($sql);
1402 $event = "INSERT INTO civicrm_email (contact_id, location_type_id, email, is_primary, is_billing, on_hold, hold_date, reset_date)
1404 (NULL, 1, 'development@example.org', 0, 0, 0, NULL, NULL),
1405 (NULL, 1, 'tournaments@example.org', 0, 0, 0, NULL, NULL),
1406 (NULL, 1, 'celebration@example.org', 0, 0, 0, NULL, NULL)
1408 $this->_query($event);
1410 $sql = "SELECT id from civicrm_email where email = 'development@example.org'";
1411 $eventEmail1 = CRM_Core_DAO
::singleValueQuery($sql);
1412 $sql = "SELECT id from civicrm_email where email = 'tournaments@example.org'";
1413 $eventEmail2 = CRM_Core_DAO
::singleValueQuery($sql);
1414 $sql = "SELECT id from civicrm_email where email = 'celebration@example.org'";
1415 $eventEmail3 = CRM_Core_DAO
::singleValueQuery($sql);
1417 $event = "INSERT INTO civicrm_phone (contact_id, location_type_id, is_primary, is_billing, mobile_provider_id, phone, phone_numeric, phone_type_id)
1419 (NULL, 1, 0, 0, NULL, '204 222-1000', '2042221000', '1'),
1420 (NULL, 1, 0, 0, NULL, '204 223-1000', '2042231000', '1'),
1421 (NULL, 1, 0, 0, NULL, '303 323-1000', '3033231000', '1')
1423 $this->_query($event);
1425 $sql = "SELECT id from civicrm_phone where phone = '204 222-1000'";
1426 $eventPhone1 = CRM_Core_DAO
::singleValueQuery($sql);
1427 $sql = "SELECT id from civicrm_phone where phone = '204 223-1000'";
1428 $eventPhone2 = CRM_Core_DAO
::singleValueQuery($sql);
1429 $sql = "SELECT id from civicrm_phone where phone = '303 323-1000'";
1430 $eventPhone3 = CRM_Core_DAO
::singleValueQuery($sql);
1432 $event = "INSERT INTO civicrm_loc_block ( address_id, email_id, phone_id, address_2_id, email_2_id, phone_2_id)
1434 ( $eventAdd1, $eventEmail1, $eventPhone1, NULL,NULL,NULL),
1435 ( $eventAdd2, $eventEmail2, $eventPhone2, NULL,NULL,NULL),
1436 ( $eventAdd3, $eventEmail3, $eventPhone3, NULL,NULL,NULL)
1439 $this->_query($event);
1441 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone1 AND email_id = $eventEmail1 AND address_id = $eventAdd1";
1442 $eventLok1 = CRM_Core_DAO
::singleValueQuery($sql);
1443 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone2 AND email_id = $eventEmail2 AND address_id = $eventAdd2";
1444 $eventLok2 = CRM_Core_DAO
::singleValueQuery($sql);
1445 $sql = "SELECT id from civicrm_loc_block where phone_id = $eventPhone3 AND email_id = $eventEmail3 AND address_id = $eventAdd3";
1446 $eventLok3 = CRM_Core_DAO
::singleValueQuery($sql);
1448 $event = "INSERT INTO civicrm_event
1449 ( 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, currency )
1451 ( '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, '" . date('Y-m-d 17:00:00', strtotime("+6 months")) . "', '" . date('Y-m-d 17:00:00', strtotime("+6 months +2 days")) . "', 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, NULL, '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=http://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', 1, 0, 'USD' ),
1452 ( '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, '" . date('Y-m-d 12:00:00', strtotime("-1 day")) . "', '" . date('Y-m-d 17:00:00', strtotime("-1 day")) . "', 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, NULL, '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=http://civicrm.org>Back to CiviCRM Home Page</a></p>', 0, NULL, NULL, 1, 0, 'USD' ),
1453 ( '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, '" . date('Y-m-d 07:00:00', strtotime("+7 months")) . "', '" . date('Y-m-d 17:00:00', strtotime("+7 months +3 days")) . "', 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, NULL, 'Thanks for Your Support!', '<p>Thank you for your support. Your participation will help save thousands of acres of rainforest.</p>', '<p><a href=http://civicrm.org>Back to CiviCRM Home Page</a></p>', 0, NULL, NULL, 0, 0, 'USD' )
1455 $this->_query($event);
1458 $eventTemplates = "INSERT INTO civicrm_event
1459 ( is_template, template_title, event_type_id, default_role_id, participant_listing_id, is_public, is_monetary, is_online_registration, is_multiple_registrations, allow_same_participant_emails, is_email_confirm, financial_type_id, fee_label, confirm_title, thankyou_title, confirm_from_name, confirm_from_email, is_active, currency )
1461 ( 1, 'Free Meeting without Online Registration', 4, 1, 1, 1, 0, 0, null, null, null, null, null, null, null, null, null, 1, 'USD' ),
1462 ( 1, 'Free Meeting with Online Registration', 4, 1, 1, 1, 0, 1, 1, 1, 0, null, null, 'Confirm Your Registration Information', 'Thanks for Registering!', null, null, 1, 'USD' ),
1463 ( 1, 'Paid Conference with Online Registration', 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 'Conference Fee', 'Confirm Your Registration Information', 'Thanks for Registering!', 'Event Template Dept.', 'event_templates@example.org', 1, 'USD' )";
1465 $this->_query($eventTemplates);
1467 $ufJoinValues = $tellFriendValues = array();
1468 $profileID = CRM_Core_DAO
::singleValueQuery("Select id from civicrm_uf_group where name ='event_registration'");
1470 // grab id's for all events and event templates
1473 FROM civicrm_event";
1475 $template = CRM_Core_DAO
::executeQuery($query);
1476 while ($template->fetch()) {
1478 $ufJoinValues[] = "( 1, 'CiviEvent', 'civicrm_event', {$template->id}, 1, {$profileID} )";
1480 $tellFriendValues[] = "( 'civicrm_event', {$template->id}, 'Tell A Friend', '<p>Help us spread the word about this event. Use the space below to personalize your email message - let your friends know why you''re attending. Then fill in the name(s) and email address(es) and click ''Send Your Message''.</p>', 'Thought you might be interested in checking out this event. I''m planning on attending.', NULL, 'Thanks for Spreading the Word', '<p>Thanks for spreading the word about this event to your friends.</p>', 1)";
1483 //insert values in civicrm_uf_join for the required event_registration profile - CRM-9587
1484 if (!empty($ufJoinValues)) {
1485 $includeProfile = "INSERT INTO civicrm_uf_join
1486 (is_active, module, entity_table, entity_id, weight, uf_group_id )
1487 VALUES " . implode(',', $ufJoinValues);
1488 $this->_query($includeProfile);
1491 //insert values in civicrm_tell_friend
1492 if (!empty($tellFriendValues)) {
1493 $tellFriend = "INSERT INTO civicrm_tell_friend
1494 (entity_table, entity_id, title, intro, suggested_message,
1495 general_link, thankyou_title, thankyou_text, is_active)
1496 VALUES " . implode(',', $tellFriendValues);
1497 $this->_query($tellFriend);
1501 private function addParticipant() {
1502 $contact = new CRM_Contact_DAO_Contact();
1503 $contact->query("SELECT id FROM civicrm_contact");
1504 while ($contact->fetch()) {
1505 $contacts[] = $contact->id
;
1508 $randomContacts = array_slice($contacts, 20, 50);
1511 INSERT INTO civicrm_participant
1512 (contact_id, event_id, status_id, role_id, register_date, source, fee_level, is_test, fee_amount, fee_currency)
1514 ( " . $randomContacts[0] . ", 1, 1, 1, '2009-01-21', 'Check', 'Single', 0, 50, 'USD'),
1515 ( " . $randomContacts[1] . ", 2, 2, 2, '2008-05-07', 'Credit Card', 'Soprano', 0, 50, 'USD'),
1516 ( " . $randomContacts[2] . ", 3, 3, 3, '2008-05-05', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD') ,
1517 ( " . $randomContacts[3] . ", 1, 4, 4, '2008-10-21', 'Direct Transfer', 'Single', 0, 50, 'USD'),
1518 ( " . $randomContacts[4] . ", 2, 1, 1, '2008-01-10', 'Check', 'Soprano', 0, 50, 'USD'),
1519 ( " . $randomContacts[5] . ", 3, 2, 2, '2008-03-05', 'Direct Transfer', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1520 ( " . $randomContacts[6] . ", 1, 3, 3, '2009-07-21', 'Direct Transfer', 'Single', 0, 50, 'USD'),
1521 ( " . $randomContacts[7] . ", 2, 4, 4, '2009-03-07', 'Credit Card', 'Soprano', 0, 50, 'USD'),
1522 ( " . $randomContacts[8] . ", 3, 1, 1, '2008-02-05', 'Direct Transfer', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1523 ( " . $randomContacts[9] . ", 1, 2, 2, '2008-02-01', 'Check', 'Single', 0, 50, 'USD'),
1524 ( " . $randomContacts[10] . ", 2, 3, 3, '2009-01-10', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1525 ( " . $randomContacts[11] . ", 3, 4, 4, '2009-03-06', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1526 ( " . $randomContacts[12] . ", 1, 1, 2, '2008-06-04', 'Credit Card', 'Single', 0, 50, 'USD'),
1527 ( " . $randomContacts[13] . ", 2, 2, 3, '2008-01-10', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1528 ( " . $randomContacts[14] . ", 3, 4, 1, '2008-07-04', 'Check', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1529 ( " . $randomContacts[15] . ", 1, 4, 2, '2009-01-21', 'Credit Card', 'Single', 0, 50, 'USD'),
1530 ( " . $randomContacts[16] . ", 2, 2, 3, '2008-01-10', 'Credit Card', 'Soprano', 0, 50, 'USD'),
1531 ( " . $randomContacts[17] . ", 3, 3, 1, '2009-03-05', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1532 ( " . $randomContacts[18] . ", 1, 2, 1, '2008-10-21', 'Direct Transfer', 'Single', 0, 50, 'USD'),
1533 ( " . $randomContacts[19] . ", 2, 4, 1, '2009-01-10', 'Credit Card', 'Soprano', 0, 50, 'USD'),
1534 ( " . $randomContacts[20] . ", 3, 1, 4, '2008-03-25', 'Check', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1535 ( " . $randomContacts[21] . ", 1, 2, 3, '2009-10-21', 'Direct Transfer', 'Single', 0, 50, 'USD'),
1536 ( " . $randomContacts[22] . ", 2, 4, 1, '2008-01-10', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1537 ( " . $randomContacts[23] . ", 3, 3, 1, '2008-03-11', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1538 ( " . $randomContacts[24] . ", 3, 2, 2, '2008-04-05', 'Direct Transfer', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1539 ( " . $randomContacts[25] . ", 1, 1, 1, '2009-01-21', 'Check', 'Single', 0, 50, 'USD'),
1540 ( " . $randomContacts[26] . ", 2, 2, 2, '2008-05-07', 'Credit Card', 'Soprano', 0, 50, 'USD'),
1541 ( " . $randomContacts[27] . ", 3, 3, 3, '2009-12-12', 'Direct Transfer', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1542 ( " . $randomContacts[28] . ", 1, 4, 4, '2009-12-13', 'Credit Card', 'Single', 0, 50, 'USD'),
1543 ( " . $randomContacts[29] . ", 2, 1, 1, '2009-12-14', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1544 ( " . $randomContacts[30] . ", 3, 2, 2, '2009-12-15', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1545 ( " . $randomContacts[31] . ", 1, 3, 3, '2009-07-21', 'Check', 'Single', 0, 50, 'USD'),
1546 ( " . $randomContacts[32] . ", 2, 4, 4, '2009-03-07', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1547 ( " . $randomContacts[33] . ", 3, 1, 1, '2009-12-15', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1548 ( " . $randomContacts[34] . ", 1, 2, 2, '2009-12-13', 'Direct Transfer', 'Single', 0, 50, 'USD'),
1549 ( " . $randomContacts[35] . ", 2, 3, 3, '2009-01-10', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1550 ( " . $randomContacts[36] . ", 3, 4, 4, '2009-03-06', 'Check', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1551 ( " . $randomContacts[37] . ", 1, 1, 2, '2009-12-13', 'Direct Transfer', 'Single', 0, 50, 'USD'),
1552 ( " . $randomContacts[38] . ", 2, 2, 3, '2008-01-10', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1553 ( " . $randomContacts[39] . ", 3, 4, 1, '2009-12-14', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1554 ( " . $randomContacts[40] . ", 1, 4, 2, '2009-01-21', 'Credit Card', 'Single', 0, 50, 'USD'),
1555 ( " . $randomContacts[41] . ", 2, 2, 3, '2009-12-15', 'Credit Card', 'Soprano', 0, 50, 'USD'),
1556 ( " . $randomContacts[42] . ", 3, 3, 1, '2009-03-05', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1557 ( " . $randomContacts[43] . ", 1, 2, 1, '2009-12-13', 'Direct Transfer', 'Single', 0, 50, 'USD'),
1558 ( " . $randomContacts[44] . ", 2, 4, 1, '2009-01-10', 'Direct Transfer', 'Soprano', 0, 50, 'USD'),
1559 ( " . $randomContacts[45] . ", 3, 1, 4, '2009-12-13', 'Check', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1560 ( " . $randomContacts[46] . ", 1, 2, 3, '2009-10-21', 'Credit Card', 'Single', 0, 50, 'USD'),
1561 ( " . $randomContacts[47] . ", 2, 4, 1, '2009-12-10', 'Credit Card', 'Soprano', 0, 50, 'USD'),
1562 ( " . $randomContacts[48] . ", 3, 3, 1, '2009-03-11', 'Credit Card', 'Tiny-tots (ages 5-8)', 0, 800, 'USD'),
1563 ( " . $randomContacts[49] . ", 3, 2, 2, '2009-04-05', 'Check', 'Tiny-tots (ages 5-8)', 0, 800, 'USD');
1565 $this->_query($participant);
1568 INSERT INTO civicrm_activity
1569 (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)
1571 (01, 5, 'NULL', '2009-01-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1572 (02, 5, 'NULL', '2008-05-07 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1573 (03, 5, 'NULL', '2008-05-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1574 (04, 5, 'NULL', '2008-10-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1575 (05, 5, 'NULL', '2008-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1576 (06, 5, 'NULL', '2008-03-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1577 (07, 5, 'NULL', '2009-07-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1578 (08, 5, 'NULL', '2009-03-07 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1579 (09, 5, 'NULL', '2008-02-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1580 (10, 5, 'NULL', '2008-02-01 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1581 (11, 5, 'NULL', '2009-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1582 (12, 5, 'NULL', '2009-03-06 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1583 (13, 5, 'NULL', '2008-06-04 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1584 (14, 5, 'NULL', '2008-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1585 (15, 5, 'NULL', '2008-07-04 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1586 (16, 5, 'NULL', '2009-01-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1587 (17, 5, 'NULL', '2008-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1588 (18, 5, 'NULL', '2009-03-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1589 (19, 5, 'NULL', '2008-10-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1590 (20, 5, 'NULL', '2009-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1591 (21, 5, 'NULL', '2008-03-25 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1592 (22, 5, 'NULL', '2009-10-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1593 (23, 5, 'NULL', '2008-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1594 (24, 5, 'NULL', '2008-03-11 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1595 (25, 5, 'NULL', '2008-04-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1596 (26, 5, 'NULL', '2009-01-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1597 (27, 5, 'NULL', '2008-05-07 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1598 (28, 5, 'NULL', '2009-12-12 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1599 (29, 5, 'NULL', '2009-12-13 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1600 (30, 5, 'NULL', '2009-12-14 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1601 (31, 5, 'NULL', '2009-12-15 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1602 (32, 5, 'NULL', '2009-07-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1603 (33, 5, 'NULL', '2009-03-07 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1604 (34, 5, 'NULL', '2009-12-15 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1605 (35, 5, 'NULL', '2009-12-13 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1606 (36, 5, 'NULL', '2009-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1607 (37, 5, 'NULL', '2009-03-06 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1608 (38, 5, 'NULL', '2009-12-13 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1609 (39, 5, 'NULL', '2008-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1610 (40, 5, 'NULL', '2009-12-14 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1611 (41, 5, 'NULL', '2009-01-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1612 (42, 5, 'NULL', '2009-12-15 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1613 (43, 5, 'NULL', '2009-03-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1614 (44, 5, 'NULL', '2009-12-13 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1615 (45, 5, 'NULL', '2009-01-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1616 (46, 5, 'NULL', '2009-12-13 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1617 (47, 5, 'NULL', '2009-10-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1618 (48, 5, 'NULL', '2009-12-10 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1619 (49, 5, 'NULL', '2009-03-11 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1620 (50, 5, 'NULL', '2009-04-05 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 )
1622 $this->_query($query);
1624 $activityContact = "
1625 INSERT INTO civicrm_activity_contact
1626 (contact_id, activity_id, record_type_id)
1629 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
1630 $currentActivityID = CRM_Core_DAO
::singleValueQuery("SELECT MAX(id) FROM civicrm_activity");
1631 $currentActivityID -= 50;
1632 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
1633 for ($i = 0; $i < 50; $i++
) {
1634 $currentActivityID++
;
1635 $activityContact .= "({$randomContacts[$i]}, $currentActivityID, $sourceID)";
1637 $activityContact .= ", ";
1640 $this->_query($activityContact);
1643 private function addPCP() {
1645 INSERT INTO `civicrm_pcp`
1646 (contact_id, status_id, title, intro_text, page_text, donate_link_text, page_id, page_type, is_thermometer, is_honor_roll, goal_amount, currency, is_active, pcp_block_id)
1648 ({$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=\"http://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, 'contribute', 1, 1, 5000.00, 'USD', 1, 1);
1650 $this->_query($query);
1653 private function addContribution() {
1655 INSERT INTO civicrm_contribution
1656 (contact_id, financial_type_id, payment_instrument_id, receive_date, non_deductible_amount, total_amount, trxn_id, check_number, currency, cancel_date, cancel_reason, receipt_date, thankyou_date, source )
1658 (2, 1, 4, '2010-04-11 00:00:00', 0.00, 125.00, NULL, '1041', 'USD', NULL, NULL, NULL, NULL, 'Apr 2007 Mailer 1' ),
1659 (4, 1, 1, '2010-03-21 00:00:00', 0.00, 50.00, 'P20901X1', NULL, 'USD', NULL, NULL, NULL, NULL, 'Online: Save the Penguins' ),
1660 (6, 1, 4, '2010-04-29 00:00:00', 0.00, 25.00, NULL, '2095', 'USD', NULL, NULL, NULL, NULL, 'Apr 2007 Mailer 1' ),
1661 (8, 1, 4, '2010-04-11 00:00:00', 0.00, 50.00, NULL, '10552', 'USD', NULL, NULL, NULL, NULL, 'Apr 2007 Mailer 1' ),
1662 (16, 1, 4, '2010-04-15 00:00:00', 0.00, 500.00, NULL, '509', 'USD', NULL, NULL, NULL, NULL, 'Apr 2007 Mailer 1' ),
1663 (19, 1, 4, '2010-04-11 00:00:00', 0.00, 175.00, NULL, '102', 'USD', NULL, NULL, NULL, NULL, 'Apr 2007 Mailer 1' ),
1664 (82, 1, 1, '2010-03-27 00:00:00', 0.00, 50.00, 'P20193L2', NULL, 'USD', NULL, NULL, NULL, NULL, 'Online: Save the Penguins' ),
1665 (92, 1, 1, '2010-03-08 00:00:00', 0.00, 10.00, 'P40232Y3', NULL, 'USD', NULL, NULL, NULL, NULL, 'Online: Help CiviCRM' ),
1666 (34, 1, 1, '2010-04-22 00:00:00', 0.00, 250.00, 'P20193L6', NULL, 'USD', NULL, NULL, NULL, NULL, 'Online: Help CiviCRM' ),
1667 (71, 1, 1, '2009-07-01 11:53:50', 0.00, 500.00, 'PL71', NULL, 'USD', NULL, NULL, NULL, NULL, NULL ),
1668 (43, 1, 1, '2009-07-01 12:55:41', 0.00, 200.00, 'PL43II', NULL, 'USD', NULL, NULL, NULL, NULL, NULL ),
1669 (32, 1, 1, '2009-10-01 11:53:50', 0.00, 200.00, 'PL32I', NULL, 'USD', NULL, NULL, NULL, NULL, NULL ),
1670 (32, 1, 1, '2009-12-01 12:55:41', 0.00, 200.00, 'PL32II', NULL, 'USD', NULL, NULL, NULL, NULL, NULL );
1672 $this->_query($query);
1674 $currentActivityID = CRM_Core_DAO
::singleValueQuery("SELECT MAX(id) FROM civicrm_activity");
1676 INSERT INTO civicrm_activity
1677 (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)
1679 (1, 6, '$ 125.00-Apr 2007 Mailer 1', '2010-04-11 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1680 (2, 6, '$ 50.00-Online: Save the Penguins', '2010-03-21 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1681 (3, 6, '$ 25.00-Apr 2007 Mailer 1', '2010-04-29 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1682 (4, 6, '$ 50.00-Apr 2007 Mailer 1', '2010-04-11 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1683 (5, 6, '$ 500.00-Apr 2007 Mailer 1', '2010-04-15 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1684 (6, 6, '$ 175.00-Apr 2007 Mailer 1', '2010-04-11 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1685 (7, 6, '$ 50.00-Online: Save the Penguins', '2010-03-27 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1686 (8, 6, '$ 10.00-Online: Save the Penguins', '2010-03-08 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1687 (9, 6, '$ 250.00-Online: Save the Penguins', '2010-04-22 00:00:00', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1688 (10, 6, NULL, '2009-07-01 11:53:50', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1689 (11, 6, NULL, '2009-07-01 12:55:41', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1690 (12, 6, NULL, '2009-10-01 11:53:50', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 ),
1691 (13, 6, NULL, '2009-12-01 12:55:41', NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 2 );
1693 $this->_query($query);
1695 $activityContact = "
1696 INSERT INTO civicrm_activity_contact
1697 (contact_id, activity_id, record_type_id)
1701 $arbitraryNumbers = array(2, 4, 6, 8, 16, 19, 82, 92, 34, 71, 43, 32, 32);
1702 for ($i = 0; $i < count($arbitraryNumbers); $i++
) {
1703 $currentActivityID++
;
1704 $activityContact .= "({$arbitraryNumbers[$i]}, $currentActivityID, 2)";
1705 if ($i != count($arbitraryNumbers) - 1) {
1706 $activityContact .= ", ";
1709 $this->_query($activityContact);
1712 private function addSoftContribution() {
1714 $sql = "SELECT id from civicrm_contribution where contact_id = 92";
1715 $contriId1 = CRM_Core_DAO
::singleValueQuery($sql);
1717 $sql = "SELECT id from civicrm_contribution where contact_id = 34";
1718 $contriId2 = CRM_Core_DAO
::singleValueQuery($sql);
1721 INSERT INTO `civicrm_contribution_soft`
1722 ( contribution_id, contact_id ,amount , currency, pcp_id , pcp_display_in_roll ,pcp_roll_nickname,pcp_personal_note )
1724 ( $contriId1, {$this->Individual[3]}, 10.00, 'USD', 1, 1, 'Jones Family', 'Helping Hands'),
1725 ( $contriId2, {$this->Individual[3]}, 250.00, 'USD', 1, 1, 'Annie and the kids', 'Annie Helps');
1727 $this->_query($query);
1730 private function addPledge() {
1731 $pledge = "INSERT INTO civicrm_pledge
1732 (contact_id, financial_type_id, contribution_page_id, amount, original_installment_amount, currency,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)
1734 (71, 1, 1, 500.00, '500', 'USD', 'month', 1, 1, 1, '2009-07-01 00:00:00', '2009-06-26 00:00:00', NULL, NULL, NULL,'2009-07-01 00:00:00', NULL, NULL, 1, 0),
1735 (43, 1, 1, 800.00, '200', 'USD', 'month', 3, 1, 4, '2009-07-01 00:00:00', '2009-06-23 00:00:00', '2009-06-23 00:00:00', NULL, NULL, '2009-04-01 10:11:40', NULL, NULL, 5, 0),
1736 (32, 1, 1, 600.00, '200', 'USD', 'month', 1, 1, 3, '2009-10-01 00:00:00', '2009-09-14 00:00:00', '2009-09-14 00:00:00', NULL, NULL, '2009-12-01 00:00:00', NULL, NULL, 5, 0);
1738 $this->_query($pledge);
1741 private function addPledgePayment() {
1742 $pledgePayment = "INSERT INTO civicrm_pledge_payment
1743 ( pledge_id, contribution_id, scheduled_amount, actual_amount, currency, scheduled_date, reminder_date, reminder_count, status_id)
1745 (1, 10, 500.00, 500.00, 'USD','2009-07-01 00:00:00', null, 0, 1 ),
1746 (2, 11, 200.00, 200.00, 'USD','2009-07-01 00:00:00', null, 0, 1 ),
1747 (2, null, 200.00, null, 'USD', '2009-10-01 00:00:00', null, 0, 2 ),
1748 (2, null, 200.00, null, 'USD', '2009-01-01 00:00:00', null, 0, 2 ),
1749 (2, null, 200.00, null, 'USD', '2009-04-01 00:00:00', null, 0, 2 ),
1751 (3, 12, 200.00, 200.00, 'USD', '2009-10-01 00:00:00', null, 0, 1 ),
1752 (3, 13, 200.00, 200.00, 'USD', '2009-11-01 00:0:00', '2009-10-28 00:00:00', 1, 1),
1753 (3, null, 200.00, null, 'USD', '2009-12-01 00:00:00', null, 0, 2 );
1755 $this->_query($pledgePayment);
1758 private function addContributionLineItem() {
1759 $query = " INSERT INTO civicrm_line_item (`entity_table`, `entity_id`, `price_field_id`, `label`, `qty`, `unit_price`, `line_total`, `participant_count`, `price_field_value_id`, `financial_type_id`)
1760 SELECT 'civicrm_contribution', cc.id, cpf.id as price_field, cpfv.label, 1, cc.total_amount, cc.total_amount line_total, 0, cpfv.id as price_field_value, cpfv.financial_type_id
1761 FROM civicrm_contribution cc
1762 LEFT JOIN civicrm_price_set cps ON cps.name = 'default_contribution_amount'
1763 LEFT JOIN civicrm_price_field cpf ON cpf.price_set_id = cps.id
1764 LEFT JOIN civicrm_price_field_value cpfv ON cpfv.price_field_id = cpf.id
1766 $this->_query($query);
1769 private function addContributionFinancialItem() {
1771 $sql = " SELECT cc.id contribution_id, cli.id as line_item_id, cc.contact_id, cc.receive_date, cc.total_amount, cc.currency, cli.label, cli.financial_type_id, cefa.financial_account_id, cc.payment_instrument_id, cc.check_number, cc.trxn_id
1772 FROM `civicrm_contribution` cc
1773 INNER JOIN civicrm_line_item cli ON cli.entity_id = cc.id and cli.entity_table = 'civicrm_contribution'
1774 INNER JOIN civicrm_entity_financial_account cefa ON cefa.entity_id = cli.financial_type_id
1775 WHERE cefa.account_relationship = 1; ";
1776 $result = CRM_Core_DAO
::executeQuery($sql);
1777 $financialAccountId = CRM_Financial_BAO_FinancialTypeAccount
::getInstrumentFinancialAccount();
1778 $this->addFinancialItem($result, $financialAccountId);
1781 private function addParticipantFinancialItem() {
1783 $sql = " SELECT cpp.contribution_id, cli.id as line_item_id, cp.contact_id, now() as receive_date, cp.fee_amount as total_amount, cp.fee_currency as currency, cli.label, cli.financial_type_id, cefa.financial_account_id, NULL as payment_instrument_id, NULL as check_number, NULL as trxn_id
1784 FROM `civicrm_participant` cp
1785 INNER JOIN civicrm_participant_payment cpp ON cpp.participant_id = cp.id
1786 INNER JOIN civicrm_line_item cli ON cli.entity_id = cp.id and cli.entity_table = 'civicrm_participant'
1787 INNER JOIN civicrm_entity_financial_account cefa ON cefa.entity_id = cli.financial_type_id
1788 WHERE cefa.account_relationship = 1";
1789 $result = CRM_Core_DAO
::executeQuery($sql);
1790 $this->addFinancialItem($result);
1793 private function addFinancialItem($result, $financialAccountId = NULL) {
1794 $defaultFinancialAccount = CRM_Core_DAO
::singleValueQuery("SELECT id FROM civicrm_financial_account WHERE is_default = 1");
1795 while($result->fetch()){
1796 $trxnParams = array(
1797 'trxn_date' => CRM_Utils_Date
::processDate($result->receive_date
),
1798 'total_amount' => $result->total_amount
,
1799 'currency' => $result->currency
,
1801 'trxn_id' => $result->trxn_id
,
1802 'contribution_id' => $result->contribution_id
,
1803 'to_financial_account_id' => $result->payment_instrument_id ?
$financialAccountId[$result->payment_instrument_id
] : $defaultFinancialAccount,
1804 'payment_instrument_id' => $result->payment_instrument_id
,
1805 'check_number' => $result->check_number
1807 $trxn = CRM_Core_BAO_FinancialTrxn
::create($trxnParams);
1808 $financialItem = array(
1809 'transaction_date' => CRM_Utils_Date
::processDate($result->receive_date
),
1810 'amount' => $result->total_amount
,
1811 'currency' => $result->currency
,
1813 'entity_id' => $result->line_item_id
,
1814 'contact_id' => $result->contact_id
,
1815 'entity_table' => 'civicrm_line_item',
1816 'description' => $result->label
,
1817 'financial_account_id' => $result->financial_account_id
1819 $trxnId['id'] = $trxn->id
;
1820 CRM_Financial_BAO_FinancialItem
::create($financialItem, null, $trxnId);
1824 private function addLineItemParticipants() {
1825 $participant = new CRM_Event_DAO_Participant();
1826 $participant->query("INSERT INTO civicrm_line_item (`entity_table`, `entity_id`, `price_field_id`, `label`, `qty`, `unit_price`, `line_total`, `participant_count`, `price_field_value_id`, `financial_type_id`)
1827 SELECT 'civicrm_participant',cp.id, cpfv.price_field_id, cpfv.label, 1, cpfv.amount, cpfv.amount as line_total, 0, cpfv.id, cpfv.financial_type_id FROM civicrm_participant cp LEFT JOIN civicrm_price_set_entity cpe ON cpe.entity_id = cp.event_id LEFT JOIN civicrm_price_field cpf ON cpf.price_set_id = cpe.price_set_id LEFT JOIN civicrm_price_field_value cpfv ON cpfv.price_field_id = cpf.id WHERE cpfv.label = cp.fee_level");
1830 private function addMembershipPayment() {
1831 $maxContribution = CRM_Core_DAO
::singleValueQuery("select max(id) from civicrm_contribution");
1832 $financialTypeID = CRM_Core_DAO
::singleValueQuery("select id from civicrm_financial_type where name = 'Member Dues'");
1833 $sql = "INSERT INTO civicrm_contribution (contact_id,financial_type_id,receive_date, total_amount, currency, source, contribution_status_id)
1834 SELECT cm.contact_id, $financialTypeID, now(), cmt.minimum_fee, 'USD', CONCAT(cmt.name, ' Membership: Offline signup'), 1 FROM `civicrm_membership` cm
1835 LEFT JOIN civicrm_membership_type cmt ON cmt.id = cm.membership_type_id;";
1837 $this->_query($sql);
1839 $sql = "INSERT INTO civicrm_membership_payment (contribution_id,membership_id)
1840 SELECT cc.id, cm.id FROM civicrm_contribution cc
1841 LEFT JOIN civicrm_membership cm ON cm.contact_id = cc.contact_id
1842 WHERE cc.id > $maxContribution;";
1844 $this->_query($sql);
1846 $sql = "INSERT INTO civicrm_line_item (entity_table, entity_id, price_field_value_id, price_field_id, label, qty, unit_price, line_total, financial_type_id)
1847 SELECT 'civicrm_contribution', cmp.contribution_id, cpfv.id, cpfv.price_field_id, cpfv.label, 1, cpfv.amount, cpfv.amount as unit_price, cpfv.financial_type_id FROM `civicrm_membership` cm
1848 LEFT JOIN civicrm_membership_payment cmp ON cmp.membership_id = cm.id
1849 LEFT JOIN civicrm_price_field_value cpfv ON cpfv.membership_type_id = cm.membership_type_id
1850 LEFT JOIN civicrm_price_field cpf ON cpf.id = cpfv.price_field_id
1851 LEFT JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id
1852 WHERE cps.name = 'default_membership_type_amount'";
1853 $this->_query($sql);
1855 $sql = "INSERT INTO civicrm_activity(source_record_id, activity_type_id, subject, activity_date_time, status_id, details)
1856 SELECT id, 6, CONCAT('$ ', total_amount, ' - ', source), now(), 2, 'Membership Payment' FROM civicrm_contribution WHERE id > $maxContribution";
1857 $this->_query($sql);
1859 $sql = "INSERT INTO civicrm_activity_contact(contact_id, activity_id, record_type_id)
1860 SELECT c.contact_id, a.id, 2
1861 FROM civicrm_contribution c, civicrm_activity a
1862 WHERE c.id > $maxContribution
1863 AND a.source_record_id = c.id
1864 AND a.details = 'Membership Payment'
1866 $this->_query($sql);
1869 private function addParticipantPayment() {
1870 $maxContribution = CRM_Core_DAO
::singleValueQuery("select max(id) from civicrm_contribution");
1871 $financialTypeID = CRM_Core_DAO
::singleValueQuery("select id from civicrm_financial_type where name = 'Event Fee'");
1872 $sql = "INSERT INTO civicrm_contribution (contact_id, financial_type_id, receive_date, total_amount, currency, receipt_date, source, contribution_status_id)
1873 SELECT `contact_id`, $financialTypeID, now(), `fee_amount`, 'USD', now(), CONCAT(ce.title, ' : Offline registration'), 1 FROM `civicrm_participant` cp
1874 LEFT JOIN civicrm_event ce ON ce.id = cp.event_id
1875 group by `contact_id`;";
1877 $this->_query($sql);
1879 $sql = "INSERT INTO civicrm_participant_payment (contribution_id,participant_id)
1880 SELECT cc.id, cp.id FROM civicrm_contribution cc
1881 LEFT JOIN civicrm_participant cp ON cp.contact_id = cc.contact_id
1882 WHERE cc.id > $maxContribution";
1884 $this->_query($sql);
1886 $sql = "INSERT INTO civicrm_activity(source_record_id, activity_type_id, subject, activity_date_time, status_id, details)
1887 SELECT id, 6, CONCAT('$ ', total_amount, ' - ', source), now(), 2, 'Participant' FROM `civicrm_contribution` WHERE id > $maxContribution";
1888 $this->_query($sql);
1890 $sql = "INSERT INTO civicrm_activity_contact(contact_id, activity_id, record_type_id)
1891 SELECT c.contact_id, a.id, 2
1892 FROM civicrm_contribution c, civicrm_activity a
1893 WHERE c.id > $maxContribution
1894 AND a.source_record_id = c.id
1895 AND a.details = 'Participant Payment'
1897 $this->_query($sql);
1901 function user_access($str = NULL) {
1905 function module_list() {
1909 echo ("Starting data generation on " . date("F dS h:i:s A") . "\n");
1910 $gcd = new CRM_GCD();
1912 $gcd->generate('Domain');
1913 $gcd->generate('Contact');
1914 $gcd->generate('Individual');
1915 $gcd->generate('Household');
1916 $gcd->generate('Organization');
1917 $gcd->generate('Relationship');
1918 $gcd->generate('EntityTag');
1919 $gcd->generate('Group');
1920 $gcd->generate('Note');
1921 $gcd->generate('Activity');
1922 $gcd->generate('Event');
1923 $gcd->generate('Contribution');
1924 $gcd->generate('ContributionLineItem');
1925 $gcd->generate('Membership');
1926 $gcd->generate('MembershipPayment');
1927 $gcd->generate('MembershipLog');
1928 $gcd->generate('PCP');
1929 $gcd->generate('SoftContribution');
1930 $gcd->generate('Pledge');
1931 $gcd->generate('PledgePayment');
1932 $gcd->generate('ContributionFinancialItem');
1933 $gcd->generate('Participant');
1934 $gcd->generate('ParticipantPayment');
1935 $gcd->generate('LineItemParticipants');
1936 $gcd->generate('ParticipantFinancialItem');
1937 echo ("Ending data generation on " . date("F dS h:i:s A") . "\n");