All Data Structures Functions Variables Pages
ModulesSearchWithDataProviderTestHelper.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 
42  {
46  public static function createCustomFieldData($name)
47  {
48  $customFieldData = CustomFieldData::getByName($name);
49  assert('count(unserialize($customFieldData->serializedData)) == 0');
50  $values = array(
51  $name . '1',
52  $name . '2',
53  $name . '3',
54  $name . '4',
55  $name . '5',
56  );
57  $customFieldData->defaultValue = null;
58  $customFieldData->serializedData = serialize($values);
59  $saved = $customFieldData->save();
60  assert('$saved');
61  return $values;
62  }
63 
64  public static function createCustomAttributesForModel(RedBeanModel $model)
65  {
66  self::createCheckBoxAttribute ($model, 'checkBox');
67  self::createCurrencyValueAttribute ($model, 'currency');
68  self::createDateAttribute ($model, 'date');
69  self::createDateTimeAttribute ($model, 'dateTime');
70  self::createDecimalAttribute ($model, 'decimal');
71  self::createDropDownAttribute ($model, 'dropDown');
72  self::createIntegerAttribute ($model, 'integer');
73  //self::createMultiSelectDropDownAttribute($model, 'multiSelect');
74  self::createPhoneAttribute ($model, 'phone');
75  self::createRadioDropDownAttribute ($model, 'radio');
76  self::createTextAttribute ($model, 'text');
77  self::createTextAreaAttribute ($model, 'textArea');
78  self::createUrlAttribute ($model, 'url');
79  }
80 
84  public static function createAccounts()
85  {
86  //tbd - what we are going to do here.
87  /*
88  $user1 = User::getByUsername('user1');
89  $user2 = User::getByUsername('user2');
90  $user3 = User::getByUsername('user3');
91  $user4 = User::getByUsername('user4');
92  $user5 = User::getByUsername('user5');
93 
94  //create accounts with different things?
95 
96  AccountTestHelper::createAccountByNameForOwner('ABC', $user1);
97  AccountTestHelper::createAccountByNameForOwner('DEF', $user1);
98  */
99  }
100 
101  public static function createCheckBoxAttribute(RedBeanModel $model, $name, $isRequired = false)
102  {
103  $attributeForm = new CheckBoxAttributeForm();
104  $attributeForm->attributeName = $name;
105  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
106  $attributeForm->isRequired = $isRequired;
107  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
108  $adapter = new $modelAttributesAdapterClassName($model);
109  $adapter->setAttributeMetadataFromForm($attributeForm);
110  }
111 
112  public static function createCurrencyValueAttribute(RedBeanModel $model, $name, $isRequired = false)
113  {
114  $attributeForm = new CurrencyValueAttributeForm();
115  $attributeForm->attributeName = $name;
116  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
117  $attributeForm->isRequired = $isRequired;
118  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
119  $adapter = new $modelAttributesAdapterClassName($model);
120  $adapter->setAttributeMetadataFromForm($attributeForm);
121  }
122 
123  public static function createDateAttribute(RedBeanModel $model, $name, $isRequired = false)
124  {
125  $attributeForm = new DateAttributeForm();
126  $attributeForm->attributeName = $name;
127  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
128  $attributeForm->isRequired = $isRequired;
129  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
130  $adapter = new $modelAttributesAdapterClassName($model);
131  $adapter->setAttributeMetadataFromForm($attributeForm);
132  }
133 
134  public static function createDateTimeAttribute(RedBeanModel $model, $name, $isRequired = false)
135  {
136  $attributeForm = new DateTimeAttributeForm();
137  $attributeForm->attributeName = $name;
138  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
139  $attributeForm->isRequired = $isRequired;
140  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
141  $adapter = new $modelAttributesAdapterClassName($model);
142  $adapter->setAttributeMetadataFromForm($attributeForm);
143  }
144 
145  public static function createDecimalAttribute(RedBeanModel $model, $name, $isRequired = false)
146  {
147  $attributeForm = new DecimalAttributeForm();
148  $attributeForm->attributeName = $name;
149  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
150  $attributeForm->isRequired = $isRequired;
151  $attributeForm->maxLength = 6;
152  $attributeForm->precisionLength = 2;
153  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
154  $adapter = new $modelAttributesAdapterClassName($model);
155  $adapter->setAttributeMetadataFromForm($attributeForm);
156  }
157 
158  public static function createDropDownAttribute(RedBeanModel $model, $name, $isRequired = false)
159  {
160  $attributeForm = new DropDownAttributeForm();
161  $attributeForm->attributeName = $name;
162  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
163  $attributeForm->isRequired = $isRequired;
164  $attributeForm->customFieldDataData = self::createCustomFieldData($name . 'List');
165  $attributeForm->customFieldDataName = $name . 'List';
166  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
167  $adapter = new $modelAttributesAdapterClassName($model);
168  $adapter->setAttributeMetadataFromForm($attributeForm);
169  }
170 
171  public static function createIntegerAttribute(RedBeanModel $model, $name, $isRequired = false)
172  {
173  $attributeForm = new IntegerAttributeForm();
174  $attributeForm->attributeName = $name;
175  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
176  $attributeForm->isRequired = $isRequired;
177  $attributeForm->maxLength = 11;
178  $attributeForm->minValue = -500000;
179  $attributeForm->maxValue = 500000;
180  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
181  $adapter = new $modelAttributesAdapterClassName($model);
182  $adapter->setAttributeMetadataFromForm($attributeForm);
183  }
184 
185  public static function createMultiSelectDropDownAttribute(RedBeanModel $model, $name)
186  {
187  //todo: once multiSelect is completed.
188  }
189 
190  public static function createPhoneAttribute(RedBeanModel $model, $name, $isRequired = false)
191  {
192  $attributeForm = new PhoneAttributeForm();
193  $attributeForm->attributeName = $name;
194  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
195  $attributeForm->isRequired = $isRequired;
196  $attributeForm->maxLength = 20;
197  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
198  $adapter = new $modelAttributesAdapterClassName($model);
199  $adapter->setAttributeMetadataFromForm($attributeForm);
200  }
201 
202  public static function createRadioDropDownAttribute(RedBeanModel $model, $name, $isRequired = false)
203  {
204  $attributeForm = new RadioDropDownAttributeForm();
205  $attributeForm->attributeName = $name;
206  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
207  $attributeForm->isRequired = $isRequired;
208  $attributeForm->customFieldDataData = self::createCustomFieldData($name . 'List');
209  $attributeForm->customFieldDataName = $name . 'List';
210  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
211  $adapter = new $modelAttributesAdapterClassName($model);
212  $adapter->setAttributeMetadataFromForm($attributeForm);
213  }
214 
215  public static function createTextAttribute(RedBeanModel $model, $name, $isRequired = false)
216  {
217  $attributeForm = new TextAttributeForm();
218  $attributeForm->attributeName = $name;
219  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
220  $attributeForm->isRequired = $isRequired;
221  $attributeForm->maxLength = 50;
222  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
223  $adapter = new $modelAttributesAdapterClassName($model);
224  $adapter->setAttributeMetadataFromForm($attributeForm);
225  }
226 
227  public static function createTextAreaAttribute(RedBeanModel $model, $name, $isRequired = false)
228  {
229  $attributeForm = new TextAreaAttributeForm();
230  $attributeForm->attributeName = $name;
231  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
232  $attributeForm->isRequired = $isRequired;
233  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
234  $adapter = new $modelAttributesAdapterClassName($model);
235  $adapter->setAttributeMetadataFromForm($attributeForm);
236  }
237 
238  public static function createUrlAttribute(RedBeanModel $model, $name, $isRequired = false)
239  {
240  $attributeForm = new UrlAttributeForm();
241  $attributeForm->attributeName = $name;
242  $attributeForm->attributeLabels = self::generateAtrributeLabelsByName($name);
243  $attributeForm->isRequired = $isRequired;
244  $attributeForm->maxLength = 50;
245  $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
246  $adapter = new $modelAttributesAdapterClassName($model);
247  $adapter->setAttributeMetadataFromForm($attributeForm);
248  }
249 
250  protected static function generateAtrributeLabelsByName($name)
251  {
252  return array(
253  'de' => $name. ' de',
254  'en' => $name. ' en',
255  'es' => $name. ' es',
256  'fr' => $name. ' fr',
257  'it' => $name. ' it',
258  );
259  }
260  }
261 ?>
static getByName($name, $shouldCache=true)
Generated on Fri Jun 5 2020 07:10:36