Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SearchFormAttributesToSearchDataProviderMetadataUtil.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  {
46  public static function getMetadata($model, $attributeName, $value)
47  {
48  assert('$model instanceof SearchForm');
49  $metadata = $model->getAttributesMappedToRealAttributesMetadata();
50  $model->resolveMixedSearchAttributeMappedToRealAttributesMetadata($metadata);
51  $adaptedMetadata = array();
52  if (isset($metadata[$attributeName]))
53  {
54  static::resolveMetadataForResolveEntireMappingByRules($model, $metadata, $attributeName, $value);
55  foreach ($metadata[$attributeName] as $attributesAndRelations)
56  {
57  $attributesAndRelationsValue = $value;
58  assert('count($attributesAndRelations) > 0 && count($attributesAndRelations) < 6');
59  $adaptedMetadataClause = array();
60  if (isset($attributesAndRelations['concatedAttributeNames']))
61  {
62  assert('count($attributesAndRelations["concatedAttributeNames"]) == 2');
63  $adaptedMetadataClause['concatedAttributeNames'] = array($attributesAndRelations['concatedAttributeNames'],
64  'value' => $attributesAndRelationsValue);
65  }
66  else
67  {
68  if (isset($attributesAndRelations[3]))
69  {
70  if ($attributesAndRelations[3] == 'resolveValueByRules')
71  {
72  $searchFormAttributeMappingRules = $model::getSearchFormAttributeMappingRulesTypeByAttribute(
73  $attributeName);
74  $className = $searchFormAttributeMappingRules . 'SearchFormAttributeMappingRules';
75  $attributesAndRelationsValue = $className::resolveValueDataIntoUsableValue(
76  $attributesAndRelationsValue);
77  }
78  elseif ($attributesAndRelations[3] != null)
79  {
80  $attributesAndRelationsValue = $attributesAndRelations[3];
81  }
82  }
83  if (isset($attributesAndRelations[1]) && $attributesAndRelations[1] != null)
84  {
85  $adaptedMetadataClause[$attributesAndRelations[0]] = array('value' =>
86  array($attributesAndRelations[1] =>
87  $attributesAndRelationsValue));
88  }
89  else
90  {
91  $adaptedMetadataClause[$attributesAndRelations[0]] = array('value' => $attributesAndRelationsValue);
92  }
93  $adaptedMetadataClause[$attributesAndRelations[0]] = array_merge($adaptedMetadataClause[$attributesAndRelations[0]],
94  static::resolveOperatorTypeDataFromAttributesAndRelations($attributesAndRelations));
95  $adaptedMetadataClause[$attributesAndRelations[0]] = array_merge($adaptedMetadataClause[$attributesAndRelations[0]],
96  static::resolveAppendTypeDataFromAttributesAndRelations($attributesAndRelations));
97  }
98  $adaptedMetadata[] = $adaptedMetadataClause;
99  }
100  return $adaptedMetadata;
101  }
102  return array();
103  }
104 
105  protected static function resolveMetadataForResolveEntireMappingByRules($model, & $metadata, $attributeName,
106  $value)
107  {
108  assert('$model instanceof SearchForm');
109  assert('is_array($metadata)');
110  assert('is_string($attributeName)');
111  if (!is_array($metadata[$attributeName]))
112  {
113  if ($metadata[$attributeName] == 'resolveEntireMappingByRules')
114  {
115  $searchFormAttributeMappingRules = $model::getSearchFormAttributeMappingRulesTypeByAttribute(
116  $attributeName);
117  $className = $searchFormAttributeMappingRules .
118  'SearchFormAttributeMappingRules';
119  $className::resolveAttributesAndRelations($attributeName, $metadata[$attributeName], $value);
120  }
121  else
122  {
123  throw new NotSupportedException();
124  }
125  }
126  else
127  {
128  //Special use-case where there is a Mixed Date or DateTime search form attribute that is from a related
129  //model. So for example if you are in Accounts and searching on Opportunity Date.
130  //Currently this requires the definition for this search attribute to be in AccountSearchForm.
131  //@see ASearchFormModel for an example.
132  foreach ($metadata[$attributeName] as $index => $attributesAndRelations)
133  {
134  $attributesAndRelationsValue = $value;
135  assert('count($attributesAndRelations) > 0 && count($attributesAndRelations) < 6');
136  if (isset($attributesAndRelations[3]) && $attributesAndRelations[3] == 'resolveRelatedAttributeValueByRules')
137  {
138  $searchFormAttributeMappingRules = $model::getSearchFormAttributeMappingRulesTypeByAttribute(
139  $attributeName);
140  //Only supports Date and DateTime. Could support more types, but would need additional testing
141  //and research first before allowing for that.
142  assert('$searchFormAttributeMappingRules == "MixedDateTimeTypes" ||
143  $searchFormAttributeMappingRules == "MixedDateTypes"');
144  $className = $searchFormAttributeMappingRules . 'SearchFormAttributeMappingRules';
145  $attributesAndRelationsValue = $className::resolveValueDataIntoUsableValue(
146  $attributesAndRelationsValue);
147  $newAttributesAndRelations = 'resolveEntireMappingByRules';
148  $className::resolveAttributesAndRelations($attributeName, $newAttributesAndRelations, $value);
149 
150  unset($metadata[$attributeName][$index]);
151  foreach ($newAttributesAndRelations as $newAttributesAndRelationsItem)
152  {
153  $newAttributesAndRelationsItem[0] = $attributesAndRelations[0];
154  $newAttributesAndRelationsItem[1] = $attributesAndRelations[1];
155  $metadata[$attributeName][] = $newAttributesAndRelationsItem;
156  }
157  }
158  }
159  }
160  }
161 
162  protected static function resolveOperatorTypeDataFromAttributesAndRelations($attributesAndRelations)
163  {
164  assert('is_array($attributesAndRelations)');
165  if (isset($attributesAndRelations[2]) && $attributesAndRelations[2] != null)
166  {
167  return array('operatorType' => $attributesAndRelations[2]);
168  }
169  return array();
170  }
171 
172  protected static function resolveAppendTypeDataFromAttributesAndRelations($attributesAndRelations)
173  {
174  assert('is_array($attributesAndRelations)');
175  if (isset($attributesAndRelations[4]) && $attributesAndRelations[4] == true)
176  {
177  return array('appendStructureAsAnd' => true);
178  }
179  return array();
180  }
181  }
182 ?>
Generated on Sat Jul 11 2020 07:10:26
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.