Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
FilterForReportForm.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  {
46  public $availableAtRunTime = false;
47 
52  public $currencyIdForValue;
53 
57  public $value;
58 
63  public $secondValue;
64 
70  public $stringifiedModelForValue;
71 
77  public $valueType;
78 
82  private $_operator;
83 
87  private $_availableOperatorsType;
88 
92  public static function getType()
93  {
94  return static::TYPE_FILTERS;
95  }
96 
100  public function attributeNames()
101  {
102  return array_merge(parent::attributeNames(), array('operator'));
103  }
104 
110  public function __set($name, $value)
111  {
112  parent::__set($name, $value);
113  if ($name == 'attributeIndexOrDerivedType')
114  {
115  $this->_availableOperatorsType = null;
116  }
117  }
118 
123  public function setOperator($value)
124  {
125  if (!in_array($value, OperatorRules::availableTypes()) && $value != null)
126  {
127  throw new NotSupportedException('Invalid operator type ' . $value);
128  }
129  $this->_operator = $value;
130  }
131 
135  public function getOperator()
136  {
137  return $this->_operator;
138  }
139 
143  public function rules()
144  {
145  return array_merge(parent::rules(), array(
146  array('operator', 'type', 'type' => 'string'),
147  array('operator', 'validateOperator'),
148  array('value', 'safe'),
149  array('value', 'validateValue'),
150  array('secondValue', 'safe'),
151  array('secondValue', 'validateSecondValue'),
152  array('currencyIdForValue', 'safe'),
153  array('stringifiedModelForValue', 'safe'),
154  array('availableAtRunTime', 'boolean'),
155  array('valueType', 'type', 'type' => 'string'),
156  array('valueType', 'validateValueType'),
157  ));
158  }
159 
163  public function validateOperator()
164  {
165  if ($this->getAvailableOperatorsType() != null && $this->operator == null)
166  {
167  $this->addError('operator', Zurmo::t('ZurmoModule', 'Operator cannot be blank.'));
168  return false;
169  }
170  }
171 
175  public function validateValue()
176  {
177  if ((in_array($this->operator, self::getOperatorsWhereValueIsRequired()) ||
178  in_array($this->valueType, self::getValueTypesWhereValueIsRequired()) ||
179  (
180  $this->getValueElementType() == 'BooleanForWizardStaticDropDown' ||
181  $this->getValueElementType() == 'UserNameId' ||
182  ($this->getValueElementType() == 'MixedDateTypesForReport' && $this->valueType == null)
183  )) &&
184  $this->value == null)
185  {
186  if ($this->getValueElementType() == 'MixedLoggedInUserTypesAndUsers' &&
187  in_array($this->valueType, MixedLoggedInUserTypesAndUsersSearchFormAttributeMappingRules::getValueTypesWhereValueIsNotRequired()))
188  {
189  // Do nothing
190  }
191  else
192  {
193  $this->addError('value', Zurmo::t('Core', 'Value cannot be blank.'));
194  }
195  }
196  $passedValidation = true;
197  $rules = array();
198  if (!is_array($this->value))
199  {
200  $this->resolveAndValidateValueData($rules, $passedValidation, 'value');
201  }
202  else
203  {
204  //Assume array has only string values
205  foreach ($this->value as $subValue)
206  {
207  if (!is_string($subValue))
208  {
209  $this->addError('value', Zurmo::t('Core', 'Value must be a string.'));
210  $passedValidation = false;
211  }
212  }
213  }
214  return $passedValidation;
215  }
216 
223  public function validateSecondValue()
224  {
225  $passedValidation = true;
226  $rules = array();
227  if (!is_array($this->secondValue))
228  {
229  if (in_array($this->operator, self::getOperatorsWhereSecondValueIsRequired()) ||
230  in_array($this->valueType, self::getValueTypesWhereSecondValueIsRequired()))
231  {
232  $rules[] = array('secondValue', 'required');
233  }
234  $this->resolveAndValidateValueData($rules, $passedValidation, 'secondValue');
235  }
236  else
237  {
238  throw new NotSupportedException();
239  }
240  return $passedValidation;
241  }
242 
246  public function validateValueType()
247  {
248  if (
249  ($this->getValueElementType() == 'MixedDateTypesForReport' && $this->valueType == null) ||
250  ($this->getValueElementType() == 'MixedLoggedInUserTypesAndUsers' && $this->valueType == null))
251  {
252  $this->addError('valueType', Zurmo::t('ZurmoModule', 'Type cannot be blank.'));
253  return false;
254  }
255  }
256 
260  public function hasAvailableOperatorsType()
261  {
262  if ($this->getAvailableOperatorsType() != null)
263  {
264  return true;
265  }
266  return false;
267  }
268 
273  public function getOperatorValuesAndLabels()
274  {
275  if ($this->attributeIndexOrDerivedType == null)
276  {
277  throw new NotSupportedException();
278  }
279  $type = $this->getAvailableOperatorsType();
280  $data = array();
282  return $data;
283  }
284 
289  public function getValueElementType()
290  {
291  if ($this->attributeIndexOrDerivedType == null)
292  {
293  throw new NotSupportedException();
294  }
296  return $modelToReportAdapter->getFilterValueElementType($this->getResolvedAttribute());
297  }
298 
303  public function getCustomFieldDataAndLabels()
304  {
305  $modelClassName = $this->getResolvedAttributeModelClassName();
306  $attribute = $this->getResolvedAttribute();
307  if ($modelClassName::isAnAttribute($attribute))
308  {
309  $model = new $modelClassName(false);
310  $dataAndLabels = CustomFieldDataUtil::
311  getDataIndexedByDataAndTranslatedLabelsByLanguage($model->{$attribute}->data, Yii::app()->language);
312  return $dataAndLabels;
313  }
314  else
315  {
316  throw new NotSupportedException();
317  }
318  }
319 
324  protected function getAvailableOperatorsType()
325  {
326  if ($this->attributeIndexOrDerivedType == null)
327  {
328  throw new NotSupportedException();
329  }
330  if ($this->_availableOperatorsType != null)
331  {
332  return $this->_availableOperatorsType;
333  }
334  $modelToReportAdapter = $this->makeResolvedAttributeModelRelationsAndAttributesToReportAdapter();
335  $availableOperatorsType = $modelToReportAdapter->getAvailableOperatorsType($this->getResolvedAttribute());
336  $this->_availableOperatorsType = $availableOperatorsType;
337  return $availableOperatorsType;
338  }
339 
343  protected static function getValueTypesWhereValueIsRequired()
344  {
345  return array_merge(
348  );
349  }
350 
354  protected static function getValueTypesWhereSecondValueIsRequired()
355  {
357  }
358 
362  protected static function getOperatorsWhereValueIsRequired()
363  {
364  return OperatorRules::getOperatorsWhereValueIsRequired();
365  }
366 
370  protected static function getOperatorsWhereSecondValueIsRequired()
371  {
372  return OperatorRules:: getOperatorsWhereSecondValueIsRequired();
373  }
374 
380  private function createValueValidatorsByRules(Array $rules)
381  {
382  $validators = new CList;
383  foreach ($rules as $rule)
384  {
385  if (isset($rule[0], $rule[1]))
386  {
387  if ($rule[1] != 'unique')
388  {
389  $validators->add(CValidator::createValidator($rule[1], $this, $rule[0], array_slice($rule, 2)));
390  }
391  }
392  else
393  {
394  throw new CException(Zurmo::t('ReportsModule', '{class} has an invalid validation rule. The rule must specify ' .
395  'attributes to be validated and the validator name.' ,
396  array('{class}' => get_class($this))));
397  }
398  }
399  return $validators;
400  }
401 
407  private function resolveAndValidateValueData(Array $rules, & $passedValidation, $ruleAttributeName)
408  {
409  $modelToReportAdapter = $this->makeResolvedAttributeModelRelationsAndAttributesToReportAdapter();
410  $rules = array_merge($rules, $modelToReportAdapter->getFilterRulesByAttribute(
411  $this->getResolvedAttribute(), $ruleAttributeName));
412  $validators = $this->createValueValidatorsByRules($rules);
413  foreach ($validators as $validator)
414  {
415  $validated = $validator->validate($this);
416  if (!$validated)
417  {
418  $passedValidation = false;
419  }
420  }
421  }
422 
423  public function attributeLabels()
424  {
425  return array('availableAtRunTime' => Zurmo::t('ReportsModule', 'Available At Run Time'));
426  }
427  }
428 ?>
static getDataIndexedByDataAndTranslatedLabelsByLanguage(CustomFieldData $customFieldData, $language)
static getValueTypesWhereSecondValueIsRequired()
static getOperatorsWhereValueIsRequired()
static getOperatorsWhereSecondValueIsRequired()
static getValueTypesWhereValueIsRequired()
Generated on Fri Sep 25 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.