Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ProductsDemoDataMaker.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
42  protected $ratioToLoad = 1;
43 
48  public static function getDependencies()
49  {
50  return array('productTemplates');
51  }
52 
56  public function makeAll(& $demoDataHelper)
57  {
58  assert('$demoDataHelper instanceof DemoDataHelper');
59  assert('$demoDataHelper->isSetRange("Contact")');
60  assert('$demoDataHelper->isSetRange("Account")');
61  assert('$demoDataHelper->isSetRange("Opportunity")');
62  assert('$demoDataHelper->isSetRange("User")');
63  $products = array();
64  $productRandomData = self::getProductsRandomData();
65  for ($i = 0; $i < count($productRandomData['names']); $i++)
66  {
67  $product = new Product();
68  $product->contact = $demoDataHelper->getRandomByModelName('Contact');
69  $product->account = $demoDataHelper->getRandomByModelName('Account');
70  $product->opportunity = $demoDataHelper->getRandomByModelName('Opportunity');
71  $product->owner = $demoDataHelper->getRandomByModelName('User');
72  $name = $productRandomData['names'][$i];
73  $this->populateModelData($product, $i, $name);
74  $saved = $product->save();
75  assert('$saved');
76  $products[] = $product->id;
77  }
78  $demoDataHelper->setRangeByModelName('Product', $products[0], $products[count($products)-1]);
79  }
80 
81  public function populateModelData(& $model, $counter, $name)
82  {
83  assert('$model instanceof Product');
84  parent::populateModel($model);
85  $productTemplateName = self::getProductTemplateForProduct($name);
86  $allTemplates = ProductTemplate::getAll();
87 
88  foreach ($allTemplates as $template)
89  {
90  if ($template->name == $productTemplateName)
91  {
92  $templateId = $template->id;
93  }
94  }
95  $productTemplate = ProductTemplate::getById($templateId);
96  $model->name = $name;
97  $model->quantity = mt_rand(1, 95);
98  $model->productTemplate = $productTemplate;
99  $model->stage->value = 'Open';
100  $model->priceFrequency = $productTemplate->priceFrequency;
101  $model->sellPrice->value= $productTemplate->sellPrice->value;
102  $model->type = $productTemplate->type;
103  }
104 
105  public static function getProductTemplateForProduct($product)
106  {
107  $productTemplateMapping = array(
108  'Amazing Kid Sample' => 'Amazing Kid',
109  'You Can Do Anything Sample' => 'You Can Do Anything',
110  'A Bend in the River November Issue' => 'A Bend in the River',
111  'A Gift of Monotheists October Issue' => 'A Gift of Monotheists',
112  'Enjoy Once in a Lifetime Music' => 'Once in a Lifetime'
113  );
114  if (!array_key_exists($product, $productTemplateMapping))
115  {
116  $productNameSubstr = explode('-P', $product);
117  if ((strpos($product, 'Laptop') !== false) ||
118  (strpos($product, 'Camera') !== false) ||
119  (strpos($product, 'Handycam') !== false))
120  {
121  return $productNameSubstr[0];
122  }
123  }
124  return $productTemplateMapping[$product];
125  }
126 
131  public static function getProductsRandomData()
132  {
133  $productNames = array(
134  'names' => array(
135  'Amazing Kid Sample',
136  'You Can Do Anything Sample',
137  'A Bend in the River November Issue',
138  'A Gift of Monotheists October Issue',
139  'Enjoy Once in a Lifetime Music'
140  )
141  );
142 
143  $productTemplates = ProductTemplate::getAll();
144 
145  foreach ($productTemplates as $template)
146  {
147  if ((strpos($template->name, 'Laptop') !== false) ||
148  (strpos($template->name, 'Camera') !== false) ||
149  (strpos($template->name, 'Handycam') !== false))
150  {
151  for ($i = 1; $i < 3; $i++)
152  {
153  $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 2);
154  $productNames['names'][] = $template->name . '-P' . $randomString;
155  }
156  }
157  }
158 
159  return $productNames;
160  }
161  }
162 ?>
static getById($id, $modelClassName=null)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Sat Jul 11 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.