00001 <?php 00002 /********************************************************************************* 00003 * Zurmo is a customer relationship management program developed by 00004 * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc. 00005 * 00006 * Zurmo is free software; you can redistribute it and/or modify it under 00007 * the terms of the GNU Affero General Public License version 3 as published by the 00008 * Free Software Foundation with the addition of the following permission added 00009 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK 00010 * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY 00011 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. 00012 * 00013 * Zurmo is distributed in the hope that it will be useful, but WITHOUT 00014 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00015 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 00016 * details. 00017 * 00018 * You should have received a copy of the GNU Affero General Public License along with 00019 * this program; if not, see http://www.gnu.org/licenses or write to the Free 00020 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00021 * 02110-1301 USA. 00022 * 00023 * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive 00024 * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com. 00025 * 00026 * The interactive user interfaces in original and modified versions 00027 * of this program must display Appropriate Legal Notices, as required under 00028 * Section 5 of the GNU Affero General Public License version 3. 00029 * 00030 * In accordance with Section 7(b) of the GNU Affero General Public License version 3, 00031 * these Appropriate Legal Notices must retain the display of the Zurmo 00032 * logo and Zurmo copyright notice. If the display of the logo is not reasonably 00033 * feasible for technical reasons, the Appropriate Legal Notices must display the words 00034 * "Copyright Zurmo Inc. 2017. All rights reserved". 00035 ********************************************************************************/ 00036 00040 class LeadsDemoDataMaker extends ContactsDemoDataMaker 00041 { 00042 protected $ratioToLoad = 2; 00043 00044 public static function getDependencies() 00045 { 00046 return array('accounts'); 00047 } 00048 00052 public function makeAll(& $demoDataHelper) 00053 { 00054 assert('$demoDataHelper instanceof DemoDataHelper'); 00055 assert('$demoDataHelper->isSetRange("User")'); 00056 00057 $contactStates = ContactState::getAll(); 00058 $statesBeginningWithStartingState = $this->getStatesBeforeOrStartingWithStartingState($contactStates); 00059 //If leads are turned off as part of custom management then ignore lead data 00060 if (count($statesBeginningWithStartingState) == 0) 00061 { 00062 return; 00063 } 00064 $contacts = array(); 00065 for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++) 00066 { 00067 $contact = new Contact(); 00068 $contact->owner = $demoDataHelper->getRandomByModelName('User'); 00069 $contact->state = RandomDataUtil::getRandomValueFromArray($statesBeginningWithStartingState); 00070 $this->populateModel($contact); 00071 $saved = $contact->save(); 00072 assert('$saved'); 00073 $contacts[] = $contact->id; 00074 } 00075 //We can use dummy model name here ContactsThatAreLeads, so we can distinct between contacts are leads 00076 $demoDataHelper->setRangeByModelName('ContactsThatAreLeads', $contacts[0], $contacts[count($contacts)-1]); 00077 } 00078 00079 public function populateModel(& $model) 00080 { 00081 assert('$model instanceof Contact'); 00082 parent::populateModel($model); 00083 $accountRandomData = ZurmoRandomDataUtil::getRandomDataByModuleAndModelClassNames('AccountsModule', 'Account'); 00084 $name = RandomDataUtil::getRandomValueFromArray($accountRandomData['names']); 00085 $model->companyName = $name; 00086 } 00087 00088 protected static function shouldIncludeState($stateOrder, $startingStateOrder) 00089 { 00090 return $stateOrder < $startingStateOrder; 00091 } 00092 } 00093 ?>