Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ReportWizardForm.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  abstract class ReportWizardForm extends WizardForm
42  {
43  const MODULE_VALIDATION_SCENARIO = 'ValidateForModule';
44 
45  const FILTERS_VALIDATION_SCENARIO = 'ValidateForFilters';
46 
47  const DISPLAY_ATTRIBUTES_VALIDATION_SCENARIO = 'ValidateForDisplayAttributes';
48 
49  const DRILL_DOWN_DISPLAY_ATTRIBUTES_VALIDATION_SCENARIO = 'ValidateForDisplayAttributes';
50 
51  const ORDER_BYS_VALIDATION_SCENARIO = 'ValidateForOrderBys';
52 
53  const GROUP_BYS_VALIDATION_SCENARIO = 'ValidateForGroupBys';
54 
55  const CHART_VALIDATION_SCENARIO = 'ValidateForChart';
56 
57  const GENERAL_DATA_VALIDATION_SCENARIO = 'ValidateForGeneralData';
58 
59  public $description;
60 
64  public $moduleClassName;
65 
70  public $name;
71 
76  public $type;
77 
81  public $ownerId;
82 
86  public $ownerName;
87 
91  public $filtersStructure;
92 
96  public $filters = array();
97 
101  public $groupBys = array();
102 
106  public $orderBys = array();
107 
111  public $displayAttributes = array();
112 
116  public $drillDownDisplayAttributes = array();
117 
121  public $chart;
122 
127  public $currencyConversionType;
128 
133  public $spotConversionCurrencyCode;
134 
141  protected $explicitReadWriteModelPermissions;
142 
143  public function rules()
144  {
145  return array(
146  array('description', 'type', 'type' => 'string'),
147  array('name', 'type', 'type' => 'string'),
148  array('name', 'length', 'max' => 64),
149  array('name', 'required', 'on' => self::GENERAL_DATA_VALIDATION_SCENARIO),
150  array('moduleClassName', 'type', 'type' => 'string'),
151  array('moduleClassName', 'length', 'max' => 64),
152  array('moduleClassName', 'required', 'on' => self::MODULE_VALIDATION_SCENARIO),
153  array('type', 'type', 'type' => 'string'),
154  array('type', 'length', 'max' => 64),
155  array('type', 'required'),
156  array('ownerId', 'type', 'type' => 'integer'),
157  array('ownerId', 'required', 'on' => self::GENERAL_DATA_VALIDATION_SCENARIO),
158  array('ownerName', 'required', 'on' => self::GENERAL_DATA_VALIDATION_SCENARIO),
159  array('filters', 'validateFilters',
160  'on' => self::FILTERS_VALIDATION_SCENARIO),
161  array('filtersStructure', 'validateFiltersStructure',
162  'on' => self::FILTERS_VALIDATION_SCENARIO),
163  array('displayAttributes', 'validateDisplayAttributes',
164  'on' => self::DISPLAY_ATTRIBUTES_VALIDATION_SCENARIO),
165  array('drillDownAttributes', 'validateDrillDownDisplayAttributes',
166  'on' => self::DRILL_DOWN_DISPLAY_ATTRIBUTES_VALIDATION_SCENARIO),
167  array('orderBys', 'validateOrderBys', 'on' => self::ORDER_BYS_VALIDATION_SCENARIO),
168  array('groupBys', 'validateGroupBys', 'on' => self::GROUP_BYS_VALIDATION_SCENARIO),
169  array('chart', 'validateChart', 'on' => self::CHART_VALIDATION_SCENARIO),
170  array('currencyConversionType', 'type', 'type' => 'integer'),
171  array('currencyConversionType', 'required', 'on' => self::GENERAL_DATA_VALIDATION_SCENARIO),
172  array('spotConversionCurrencyCode', 'type', 'type' => 'string'),
173  array('spotConversionCurrencyCode', 'validateSpotConversionCurrencyCode', 'on' => self::GENERAL_DATA_VALIDATION_SCENARIO),
174  );
175  }
176 
177  public function attributeLabels()
178  {
179  return array(
180  'name' => Zurmo::t('Core', 'Name'),
181  'ownerId' => Zurmo::t('ReportsModule', 'Owner Id'),
182  'ownerName' => Zurmo::t('ReportsModule', 'Owner Name'),
183  'currencyConversionType' => Zurmo::t('ReportsModule', 'Currency Conversion'),
184  'spotConversionCurrencyCode' => Zurmo::t('ReportsModule', 'Spot Currency'),
185  );
186  }
187 
192  {
193  return $this->explicitReadWriteModelPermissions;
194  }
195 
199  public function setExplicitReadWriteModelPermissions(ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions)
200  {
201  $this->explicitReadWriteModelPermissions = $explicitReadWriteModelPermissions;
202  }
203 
207  public function validateFilters()
208  {
210  }
211 
215  public function validateFiltersStructure()
216  {
217  if (count($this->filters) > 0)
218  {
219  if (null != $errorMessage = SQLOperatorUtil::
220  resolveValidationForATemplateSqlStatementAndReturnErrorMessage($this->filtersStructure,
221  count($this->filters)))
222  {
223  $this->addError('filtersStructure', $errorMessage);
224  }
225  }
226  }
227 
231  public function validateOrderBys()
232  {
234  }
235 
239  public function validateDisplayAttributes()
240  {
241  $validated = $this->validateComponent(ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES, 'displayAttributes');
242  if (count($this->displayAttributes) == 0)
243  {
244  $this->addError( 'displayAttributes', Zurmo::t('ReportsModule', 'At least one display column must be selected'));
245  $validated = false;
246  }
247  return $validated;
248  }
249 
254  {
255  return $this->validateComponent(ComponentForReportForm::TYPE_DRILL_DOWN_DISPLAY_ATTRIBUTES, 'drillDownDisplayAttributes');
256  }
257 
261  public function validateGroupBys()
262  {
263  $validated = $this->validateComponent(ComponentForReportForm::TYPE_GROUP_BYS, 'groupBys');
264  $existingGroupByAttributeIndexOrDerivedTypes = array();
265  $duplicateGroupByFound = false;
266  foreach ($this->groupBys as $groupBy)
267  {
268  if (in_array($groupBy->attributeIndexOrDerivedType, $existingGroupByAttributeIndexOrDerivedTypes))
269  {
270  $duplicateGroupByFound = true;
271  }
272  else
273  {
274  $existingGroupByAttributeIndexOrDerivedTypes[] = $groupBy->attributeIndexOrDerivedType;
275  }
276  }
277  if ($duplicateGroupByFound)
278  {
279  $this->addError( 'groupBys', Zurmo::t('ReportsModule', 'Each grouping must be unique'));
280  $validated = false;
281  }
282  return $validated;
283  }
284 
288  public function validateChart()
289  {
290  $passedValidation = true;
291  if ($this->chart != null)
292  {
293  $validated = $this->chart->validate();
294  if (!$validated)
295  {
296  foreach ($this->chart->getErrors() as $attribute => $error)
297  {
298  $this->addError( 'ChartForReportForm_' . $attribute, $error);
299  }
300  $passedValidation = false;
301  }
302  }
303  return $passedValidation;
304  }
305 
310  {
311  $passedValidation = true;
312  if ($this->currencyConversionType == Report::CURRENCY_CONVERSION_TYPE_SPOT &&
313  $this->spotConversionCurrencyCode == null)
314  {
315  $this->addError('spotConversionCurrencyCode', Zurmo::t('ReportsModule', 'Spot Currency cannot be blank.'));
316  $passedValidation = false;
317  }
318  return $passedValidation;
319  }
320 
325  {
326  $baseCurrencyCode = Yii::app()->currencyHelper->getBaseCode();
327  return array(
329  Zurmo::t('ReportsModule', 'Do not convert (Can produce mixed results)'),
331  Zurmo::t('ReportsModule', 'Convert to base currency ({baseCurrencyCode})',
332  array('{baseCurrencyCode}' => $baseCurrencyCode)),
334  Zurmo::t('ReportsModule', 'Convert to base currency ({baseCurrencyCode}) and then to a spot currency',
335  array('{baseCurrencyCode}' => $baseCurrencyCode))
336  );
337  }
338 
344  protected function validateComponent($componentType, $componentName)
345  {
346  assert('is_string($componentType)');
347  assert('is_string($componentName)');
348  $passedValidation = true;
349  foreach ($this->{$componentName} as $model)
350  {
351  if (!$model->validate())
352  {
353  foreach ($model->getErrors() as $attribute => $error)
354  {
355  $attributePrefix = static::resolveErrorAttributePrefix($componentType, $model->getRowKey());
356  $this->addError( $attributePrefix . $attribute, $error);
357  }
358  $passedValidation = false;
359  }
360  }
361  return $passedValidation;
362  }
363  }
364 ?>
const CURRENCY_CONVERSION_TYPE_SPOT
Definition: Report.php:82
setExplicitReadWriteModelPermissions(ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions)
const CURRENCY_CONVERSION_TYPE_BASE
Definition: Report.php:76
const CURRENCY_CONVERSION_TYPE_ACTUAL
Definition: Report.php:70
validateComponent($componentType, $componentName)
Generated on Fri Jul 10 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.