Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ImportRulesUtil.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  {
47  public static function getImportRulesClassNameByType($importRulesType)
48  {
49  assert('is_string($importRulesType)');
50  $importRulesClassName = $importRulesType . 'ImportRules';
51  if (@class_exists($importRulesClassName) === false)
52  {
53  throw new NotSupportedException($importRulesClassName);
54  }
55  return $importRulesClassName;
56  }
57 
62  public static function makeImportRulesByType($importRulesType)
63  {
64  assert('is_string($importRulesType)');
65  $importRulesClassName = self::getImportRulesClassNameByType($importRulesType);
66  return new $importRulesClassName();
67  }
68 
74  public static function getImportRulesTypesForCurrentUser()
75  {
76  //todo: cache results to improve performance if needed.
77  $importRulesTypes = array();
78  $modules = Module::getModuleObjects();
79  foreach ($modules as $module)
80  {
81  $rulesClassNames = $module::getAllClassNamesByPathFolder('rules');
82  foreach ($rulesClassNames as $ruleClassName)
83  {
84  $classToEvaluate = new ReflectionClass($ruleClassName);
85  if (is_subclass_of($ruleClassName, 'ImportRules') && !$classToEvaluate->isAbstract())
86  {
87  $moduleClassNames = $ruleClassName::getModuleClassNames();
88  $addToArray = true;
89  foreach ($moduleClassNames as $moduleClassNameToCheckAccess)
90  {
91  if (!RightsUtil::canUserAccessModule($moduleClassNameToCheckAccess,
92  Yii::app()->user->userModel) ||
93  !RightsUtil::
94  doesUserHaveAllowByRightName($moduleClassNameToCheckAccess,
95  $moduleClassNameToCheckAccess::getCreateRight(),
96  Yii::app()->user->userModel))
97  {
98  $addToArray = false;
99  }
100  }
101  if ($addToArray)
102  {
103  $importRulesTypes[$ruleClassName::getType()] = $ruleClassName::getDisplayLabel();
104  }
105  }
106  }
107  }
108  return $importRulesTypes;
109  }
110 
120  public static function areAllRequiredAttributesMappedOrHaveRules(& $requiredAttributeCollection,
121  $mappedAttributeImportRulesCollection)
122  {
123  assert('is_array($requiredAttributeCollection)');
124  assert('is_array($mappedAttributeImportRulesCollection)');
125  foreach ($mappedAttributeImportRulesCollection as $attributeIndex => $attributeImportRules)
126  {
127  $modelAttributeNames = array();
128  if ($attributeImportRules instanceof DerivedAttributeImportRules)
129  {
130  $modelAttributeNames = $attributeImportRules->getRealModelAttributeNames();
131  }
132  elseif ($attributeImportRules instanceof NonDerivedAttributeImportRules)
133  {
134  $modelAttributeNames[0] = $attributeIndex;
135  }
136  else
137  {
138  throw new NotSupportedException();
139  }
140  foreach ($modelAttributeNames as $modelAttributeName)
141  {
142  if (isset($requiredAttributeCollection[$modelAttributeName]))
143  {
144  unset($requiredAttributeCollection[$modelAttributeName]);
145  }
146  }
147  }
148  if (count($requiredAttributeCollection) > 0)
149  {
150  return false;
151  }
152  else
153  {
154  return true;
155  }
156  }
157 
168  public static function checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection)
169  {
170  assert('is_array($mappedAttributeImportRulesCollection)');
171  $mappedModelAttributeNames = array();
172  foreach ($mappedAttributeImportRulesCollection as $attributeIndexOrDerivedAttributeType => $attributeImportRules)
173  {
174  $relationNameAndAttributeName = explode(FormModelUtil::DELIMITER, $attributeIndexOrDerivedAttributeType);
175  if (count($relationNameAndAttributeName) == 2)
176  {
177  $relationName = $relationNameAndAttributeName[0];
178  }
179  else
180  {
181  $relationName = 'None';
182  }
183  if ($attributeImportRules instanceof AttributeImportRules)
184  {
185  $modelAttributeNames = $attributeImportRules->getRealModelAttributeNames();
186  foreach ($modelAttributeNames as $modelAttributeName)
187  {
188  if (isset($mappedModelAttributeNames[$relationName]) &&
189  in_array($modelAttributeName, $mappedModelAttributeNames[$relationName]))
190  {
191  $displayLabel = $attributeImportRules->getDisplayLabelByAttributeName($modelAttributeName);
192  throw new ImportAttributeMappedMoreThanOnceException($displayLabel);
193  }
194  $mappedModelAttributeNames[$relationName][] = $modelAttributeName;
195  }
196  }
197  else
198  {
199  throw new NotSupportedException();
200  }
201  }
202  }
203  }
204 ?>
static makeImportRulesByType($importRulesType)
static getImportRulesTypesForCurrentUser()
static getModuleObjects()
Definition: Module.php:51
static areAllRequiredAttributesMappedOrHaveRules(&$requiredAttributeCollection, $mappedAttributeImportRulesCollection)
static getImportRulesClassNameByType($importRulesType)
static checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection)
static canUserAccessModule($moduleClassName, $user)
Definition: RightsUtil.php:103
Generated on Thu Jul 9 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.