All Data Structures Functions Variables Pages
RequiredAttributesValidViewUtil.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 
57  {
63  public static function setAsMissingRequiredAttributes($moduleClassName, $viewClassName)
64  {
65  assert('is_string($moduleClassName)');
66  assert('is_string($viewClassName)');
67  $key = $viewClassName . '_layoutMissingRequiredAttributes';
68 
69  $value = ZurmoConfigurationUtil::getByModuleName($moduleClassName, $key);
70  if ($value == null)
71  {
72  $value = 1;
73  }
74  else
75  {
76  $value++;
77  if ($value <= 1)
78  {
79  throw new NotSupportedException();
80  }
81  }
82  ZurmoConfigurationUtil::setByModuleName($moduleClassName, $key, $value);
83  }
84 
90  public static function removeAttributeAsMissingRequiredAttribute($moduleClassName, $viewClassName)
91  {
92  assert('is_string($moduleClassName)');
93  assert('is_string($viewClassName)');
94  $key = $viewClassName . '_layoutMissingRequiredAttributes';
95 
96  $value = ZurmoConfigurationUtil::getByModuleName($moduleClassName, $key);
97  if ($value == null)
98  {
99  return;
100  }
101  else
102  {
103  if ($value == 1)
104  {
105  $value = null;
106  }
107  else
108  {
109  $value = $value - 1;
110  if ($value >= 1)
111  {
112  throw new NotSupportedException();
113  }
114  }
115  }
116  ZurmoConfigurationUtil::setByModuleName($moduleClassName, $key, $value);
117  }
118 
123  public static function setAsContainingRequiredAttributes($moduleClassName, $viewClassName)
124  {
125  assert('is_string($moduleClassName)');
126  assert('is_string($viewClassName)');
127  $key = $viewClassName . '_layoutMissingRequiredAttributes';
128  ZurmoConfigurationUtil::setByModuleName($moduleClassName, $key, null);
129  }
130 
136  public static function isViewMissingRequiredAttributes($moduleClassName, $viewClassName)
137  {
138  assert('is_string($moduleClassName)');
139  assert('is_string($viewClassName)');
140  $key = $viewClassName . '_layoutMissingRequiredAttributes';
141  $value = ZurmoConfigurationUtil::getByModuleName($moduleClassName, $key);
142  if ($value !== null)
143  {
144  return true;
145  }
146  return false;
147  }
148 
154  public static function resolveValidView($moduleClassName, $viewClassName)
155  {
156  assert('is_string($moduleClassName)');
157  assert('is_string($viewClassName)');
158  if (!static::isViewMissingRequiredAttributes($moduleClassName, $viewClassName))
159  {
160  return;
161  }
162  $designerRules = DesignerRulesFactory::createDesignerRulesByView($viewClassName);
163  $viewDisplayName = $moduleClassName::getModuleLabelByTypeAndLanguage('Plural');
164  $viewDisplayName .= ' ' . $designerRules->resolveDisplayNameByView($viewClassName);
165  return Zurmo::t('ZurmoModule', 'There are required fields missing from the following' .
166  ' layout: {view}. Please contact your administrator.',
167  array('{view}' => $viewDisplayName));
168  }
169 
174  public static function resolveToSetAsMissingRequiredAttributesByModelClassName($modelClassName, $attributeName)
175  {
176  assert('is_string($modelClassName)');
177  assert('is_string($attributeName)');
178  $modules = Module::getModuleObjects();
179  foreach ($modules as $module)
180  {
181  try
182  {
183  if ($module::getPrimaryModelName() == $modelClassName)
184  {
185  $viewClassNames = $module::getViewClassNames();
186  foreach ($viewClassNames as $viewClassName)
187  {
188  $classToEvaluate = new ReflectionClass($viewClassName);
189  if (is_subclass_of($viewClassName, 'MetadataView') && !$classToEvaluate->isAbstract() &&
190  $viewClassName::getDesignerRulesType() != null)
191  {
192  $designerRules = DesignerRulesFactory::createDesignerRulesByView($viewClassName);
193  if ($designerRules->allowEditInLayoutTool() &&
194  $designerRules->requireAllRequiredFieldsInLayout())
195  {
196  $attributesLayoutAdapter = AttributesLayoutAdapterUtil::
198  $modelClassName,
199  $designerRules);
200  if (!in_array($attributeName, $attributesLayoutAdapter->getEffectivePlacedAttributes()))
201  {
202  self::setAsMissingRequiredAttributes(get_class($module), $viewClassName);
203  }
204  }
205  }
206  }
207  }
208  }
209  catch (NotSupportedException $e)
210  {
211  }
212  }
213  }
214 
219  public static function resolveToRemoveAttributeAsMissingRequiredAttribute($modelClassName, $attributeName)
220  {
221  assert('is_string($modelClassName)');
222  assert('is_string($attributeName)');
223  $modules = Module::getModuleObjects();
224  foreach ($modules as $module)
225  {
226  try
227  {
228  if ($module::getPrimaryModelName() == $modelClassName)
229  {
230  $viewClassNames = $module::getViewClassNames();
231  foreach ($viewClassNames as $viewClassName)
232  {
233  $classToEvaluate = new ReflectionClass($viewClassName);
234  if (is_subclass_of($viewClassName, 'MetadataView') && !$classToEvaluate->isAbstract() &&
235  $viewClassName::getDesignerRulesType() != null)
236  {
237  $designerRules = DesignerRulesFactory::createDesignerRulesByView($viewClassName);
238  if ($designerRules->allowEditInLayoutTool() &&
239  $designerRules->requireAllRequiredFieldsInLayout())
240  {
241  $attributesLayoutAdapter = AttributesLayoutAdapterUtil::
243  $modelClassName,
244  $designerRules);
245  if (!in_array($attributeName, $attributesLayoutAdapter->getEffectivePlacedAttributes()))
246  {
247  self::
248  removeAttributeAsMissingRequiredAttribute(get_class($module), $viewClassName);
249  }
250  }
251  }
252  }
253  }
254  }
255  catch (NotSupportedException $e)
256  {
257  }
258  }
259  }
260  }
261 ?>
static isViewMissingRequiredAttributes($moduleClassName, $viewClassName)
static setAsContainingRequiredAttributes($moduleClassName, $viewClassName)
static getModuleObjects()
Definition: Module.php:51
static setAsMissingRequiredAttributes($moduleClassName, $viewClassName)
static resolveValidView($moduleClassName, $viewClassName)
static removeAttributeAsMissingRequiredAttribute($moduleClassName, $viewClassName)
static getByModuleName($moduleName, $key, $cache=true)
static resolveToSetAsMissingRequiredAttributesByModelClassName($modelClassName, $attributeName)
static resolveToRemoveAttributeAsMissingRequiredAttribute($modelClassName, $attributeName)
static makeByViewAndModelAndDesignerRules($viewClassName, $modelClassName, DesignerRules $designerRules)
static setByModuleName($moduleName, $key, $value, $cache=true)
Generated on Thu May 28 2020 07:10:36