PageRenderTime 33ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/sql/GenerateReportData.php

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