Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DropDownDependencyToMappingLayoutAdapter.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  {
43  protected $modelClassName;
44 
45  protected $attributeName;
46 
47  protected $maxDepth;
48 
54  public function __construct($modelClassName, $attributeName, $maxDepth)
55  {
56  assert('is_string($modelClassName)');
57  assert('is_string($attributeName) || $this->attributeName == null');
58  assert('is_int($maxDepth) && $maxDepth > 1 && $maxDepth < 5');
59  $this->modelClassName = $modelClassName;
60  $this->attributeName = $attributeName;
61  $this->maxDepth = $maxDepth;
62  }
63 
71  public function makeDependencyCollectionByMappingData($mappingData)
72  {
73  assert('is_array($mappingData)');
74  $collection = array();
75  $depthCount = 0;
76  $availableCustomFieldAttributes = self::getCustomFieldAttributesNotUsedInOtherDependencyAttributes();
77  $parentAttributeName = null;
78  foreach ($mappingData as $dependencyData)
79  {
80  if ($dependencyData['attributeName'] == null)
81  {
82  break;
83  }
84  self::resolveAvailableCustomFieldAttributes($availableCustomFieldAttributes, $parentAttributeName);
85  $valuesToParentValues = self::resolveValuesToParentValues($dependencyData);
86  $dependencyMapping = new DropDownDependencyCustomFieldMapping(
87  $depthCount,
88  $dependencyData['attributeName'],
89  $availableCustomFieldAttributes,
90  self::getAttributeCustomFieldData($dependencyData['attributeName']),
91  $valuesToParentValues);
92  $collection[] = $dependencyMapping;
93  $parentAttributeName = $dependencyData['attributeName'];
94  $depthCount++;
95  }
96  if ($this->maxDepth > $depthCount)
97  {
98  self::resolveAvailableCustomFieldAttributes($availableCustomFieldAttributes, $parentAttributeName);
99  $allowSelection = true;
100  for ($i = $depthCount; $i < $this->maxDepth; $i++)
101  {
102  $dependencyMapping = new DropDownDependencyCustomFieldMapping(
103  $depthCount,
104  null,
105  $availableCustomFieldAttributes,
106  null,
107  null
108  );
109  if (!$allowSelection)
110  {
111  $dependencyMapping->doNotAllowAttributeSelection();
112  }
113  $collection[] = $dependencyMapping;
114  $allowSelection = false;
115  $depthCount++;
116  }
117  }
118  return $collection;
119  }
120 
125  {
126  $modelClassName = $this->modelClassName;
127  $attributeNames = CustomFieldUtil::getCustomFieldAttributeNames($modelClassName);
128  $dropDownDependencyModels = DropDownDependencyDerivedAttributeMetadata::getAllByModelClassName($this->modelClassName);
129  foreach ($dropDownDependencyModels as $dropDownDependency)
130  {
131  if ($dropDownDependency->name != $this->attributeName)
132  {
133  $usedAttributeNames = $dropDownDependency->getUsedAttributeNames();
134  foreach ($usedAttributeNames as $usedAttributeName)
135  {
136  if (in_array($usedAttributeName, $attributeNames))
137  {
138  $key = array_search($usedAttributeName, $attributeNames);
139  unset($attributeNames[$key]);
140  }
141  }
142  }
143  }
144  $attributeNamesAndLabels = array();
145  foreach ($attributeNames as $attributeName)
146  {
147  $attributeNamesAndLabels[$attributeName] = $modelClassName::getAnAttributeLabel($attributeName);
148  }
149  return $attributeNamesAndLabels;
150  }
151 
152  protected function resolveAvailableCustomFieldAttributes(& $availableCustomFieldAttributes, $parentAttributeName)
153  {
154  assert('is_array($availableCustomFieldAttributes)');
155  assert('is_string($parentAttributeName) || $parentAttributeName == null');
156  if ($parentAttributeName != null && isset($availableCustomFieldAttributes[$parentAttributeName]))
157  {
158  unset($availableCustomFieldAttributes[$parentAttributeName]);
159  }
160  }
161 
162  protected function getAttributeCustomFieldData($attributeName)
163  {
164  assert('is_string($attributeName) || $attributeName == null');
165  if ($attributeName == null)
166  {
167  return null;
168  }
170  getDataByModelClassNameAndAttributeName($this->modelClassName, $attributeName);
171  }
172 
173  protected function resolveValuesToParentValues($dependencyData)
174  {
175  assert('is_array($dependencyData)');
176  if (isset($dependencyData['valuesToParentValues']))
177  {
178  return $dependencyData['valuesToParentValues'];
179  }
180  return null;
181  }
182  }
183 ?>
__construct($modelClassName, $attributeName, $maxDepth)
static getCustomFieldAttributeNames($modelClassName)
static getAllByModelClassName($modelClassName)
static getDataByModelClassNameAndAttributeName($modelClassName, $attributeName)
Generated on Thu Aug 6 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.