All Data Structures Functions Variables Pages
ConstantBasedStaticDropDownTriggerRules.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  {
49  public function evaluateBeforeSave(RedBeanModel $model, $attribute)
50  {
51  assert('is_string($attribute)');
52  switch($this->trigger->getOperator())
53  {
54  case OperatorRules::TYPE_EQUALS:
55  if (static::sanitize($model->{$attribute}) == static::sanitize($this->trigger->value))
56  {
57  return true;
58  }
59  break;
60  case OperatorRules::TYPE_DOES_NOT_EQUAL:
61  if (static::sanitize($model->{$attribute}) != static::sanitize($this->trigger->value))
62  {
63  return true;
64  }
65  break;
66  case OperatorRules::TYPE_ONE_OF:
67  if (!is_array(static::sanitize($this->trigger->value)))
68  {
69  return false;
70  }
71  if (in_array(static::sanitize($model->{$attribute}), static::sanitize($this->trigger->value)))
72  {
73  return true;
74  }
75  break;
76  case OperatorRules::TYPE_CHANGES:
77  if (array_key_exists($attribute, $model->originalAttributeValues))
78  {
79  return true;
80  }
81  break;
82  case OperatorRules::TYPE_DOES_NOT_CHANGE:
83  if (!array_key_exists($attribute, $model->originalAttributeValues))
84  {
85  return true;
86  }
87  break;
88  case OperatorRules::TYPE_BECOMES:
89  if (array_key_exists($attribute, $model->originalAttributeValues) &&
90  static::sanitize($model->{$attribute}) == static::sanitize($this->trigger->value))
91  {
92  return true;
93  }
94  break;
95  case OperatorRules::TYPE_WAS:
96  if (array_key_exists($attribute, $model->originalAttributeValues) &&
97  static::sanitize($model->originalAttributeValues[$attribute]) ==
98  static::sanitize($this->trigger->value))
99  {
100  return true;
101  }
102  break;
103  case OperatorRules::TYPE_BECOMES_ONE_OF:
104  if (!is_array(static::sanitize($this->trigger->value)))
105  {
106  return false;
107  }
108  if (array_key_exists($attribute, $model->originalAttributeValues) &&
109  in_array(static::sanitize($model->{$attribute}), static::sanitize($this->trigger->value)))
110  {
111  return true;
112  }
113  break;
114  case OperatorRules::TYPE_WAS_ONE_OF:
115  if (!is_array(static::sanitize($this->trigger->value)))
116  {
117  return false;
118  }
119  if (array_key_exists($attribute, $model->originalAttributeValues) &&
120  in_array(static::sanitize($model->originalAttributeValues[$attribute]),
121  static::sanitize($this->trigger->value)))
122  {
123  return true;
124  }
125  break;
126  case OperatorRules::TYPE_IS_EMPTY:
127  if (empty($model->{$attribute}))
128  {
129  return true;
130  }
131  break;
132  case OperatorRules::TYPE_IS_NOT_EMPTY:
133  if (!empty($model->{$attribute}))
134  {
135  return true;
136  }
137  break;
138  default:
139  throw new NotSupportedException();
140  }
141  return false;
142  }
143 
151  public function evaluateTimeTriggerBeforeSave(RedBeanModel $model, $attribute, $changeRequiredToProcess = true)
152  {
153  assert('is_string($attribute)');
154  assert('is_bool($changeRequiredToProcess)');
155  if (array_key_exists($attribute, $model->originalAttributeValues) || !$changeRequiredToProcess)
156  {
157  if ($this->trigger->getOperator() == OperatorRules::TYPE_DOES_NOT_CHANGE)
158  {
159  return true;
160  }
161  return $this->evaluateBeforeSave($model, $attribute);
162  }
163  return false;
164  }
165  }
166 ?>
evaluateTimeTriggerBeforeSave(RedBeanModel $model, $attribute, $changeRequiredToProcess=true)
Generated on Thu Apr 2 2020 07:10:46