All Data Structures Functions Variables Pages
ModelAttributeRulesToDefaultValueMappingRuleUtil.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  {
52  public static function getApplicableRulesByModelClassNameAndAttributeName($modelClassName, $attributeName,
53  $ruleAttributeName,
54  $requiredRuleIsApplicable = false,
55  $treatDateTimeAsDate = false,
56  $readOnlyRuleIsApplicable = true)
57  {
58  assert('is_string($modelClassName)');
59  assert('is_string($attributeName)');
60  assert('is_string($ruleAttributeName)');
61  assert('is_bool($requiredRuleIsApplicable)');
62  assert('$modelClassName::isAnAttribute($attributeName)');
63  $metadata = $modelClassName::getMetadata();
64  assert('isset($metadata[$modelClassName])');
65  $applicableRules = array();
66  if ($attributeName == 'id')
67  {
68  return $applicableRules;
69  }
70  $modelAttributeClassName = $modelClassName::getAttributeModelClassName($attributeName);
71  if (isset($metadata[$modelAttributeClassName]['rules']))
72  {
73  $i = 0;
74  while ($i < count($metadata[$modelAttributeClassName]['rules']))
75  {
76  $rule = $metadata[$modelAttributeClassName]['rules'][$i];
77  if ($rule[0] == $attributeName)
78  {
79  switch ($rule[1])
80  {
81  case 'type':
82  if ($rule['type'] == 'date' || $rule['type'] == 'datetime')
83  {
84  if ($treatDateTimeAsDate)
85  {
86  $rule['type'] = 'date';
87  }
88  $rule[1] = 'TypeValidator';
89  }
90  $rule[0] = $ruleAttributeName;
91  $applicableRules[] = $rule;
92  continue;
93  case 'numerical':
94  if (isset($rule['precision']))
95  {
96  $rule[1] = 'RedBeanModelNumberValidator';
97  }
98  $rule[0] = $ruleAttributeName;
99  $applicableRules[] = $rule;
100  continue;
101  case 'default':
102  case 'safe':
103  continue;
104  case 'required':
105  if ($requiredRuleIsApplicable)
106  {
107  $rule[0] = $ruleAttributeName;
108  $applicableRules[] = $rule;
109  }
110  continue;
111  case 'readOnly':
112  if ($readOnlyRuleIsApplicable)
113  {
114  $rule[0] = $ruleAttributeName;
115  $applicableRules[] = $rule;
116  }
117  continue;
118  case 'dateTimeDefault':
119  //Ignore dateTimeDefault validator for this as it is not applicable to import
120  //It would map to RedBeanModelDateTimeDefaultValueValidator and is unneeded
121  continue;
122  case 'probability':
123  //Ignore probability validator for this as it is not applicable to import
124  //It would map to RedBeanModelProbabilityValidator and is unneeded
125  continue;
126  case 'RedBeanModelCompareDateTimeValidator':
127  //Ignore dateTimeDefault validator for this as it is not applicable to import
128  //We can't control if the user is mapping both the dates that are part of this
129  continue;
130  default:
131  $rule[0] = $ruleAttributeName;
132  $applicableRules[] = $rule;
133  }
134  }
135  $i++;
136  }
137  }
138  return $applicableRules;
139  }
140  }
141 ?>
static getApplicableRulesByModelClassNameAndAttributeName($modelClassName, $attributeName, $ruleAttributeName, $requiredRuleIsApplicable=false, $treatDateTimeAsDate=false, $readOnlyRuleIsApplicable=true)
Generated on Wed Feb 26 2020 07:10:39