All Data Structures Functions Variables Pages
ModelRelationsAndAttributesToSummationReportAdapter.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  {
55  public function getAttributesForOrderBys($existingGroupBys = array(), $existingDisplayAttributes = array(),
56  RedBeanModel $precedingModel = null, $precedingRelation = null)
57  {
58  assert('is_array($existingGroupBys)');
59  if (($precedingModel != null && $precedingRelation == null) ||
60  ($precedingModel == null && $precedingRelation != null))
61  {
62  throw new NotSupportedException();
63  }
64  if (empty($existingGroupBys) && empty($existingDisplayAttributes))
65  {
66  return array();
67  }
68  $attributes = array();
69  foreach ($existingGroupBys as $groupBy)
70  {
71  $addAttribute = false;
72  //is there is preceding model/relation info
73  if ($precedingModel != null && $precedingRelation != null)
74  {
75  if ($groupBy->hasRelatedData() &&
76  $groupBy->getPenultimateModelClassName() == get_class($precedingModel) &&
77  $groupBy->getPenultimateRelation() == $precedingRelation &&
78  $groupBy->getResolvedAttributeModelClassName() == get_class($this->model))
79  {
80  $addAttribute = true;
81  }
82  }
83  else
84  {
85  //is there is no preceding model/relation info
86  //if the groupBy attribute is part of a related data chain, ignore,
87  //since must be at the wrong spot in the chain.
88  if (!$groupBy->hasRelatedData() &&
89  $groupBy->getResolvedAttributeModelClassName() == get_class($this->model))
90  {
91  $addAttribute = true;
92  }
93  }
94  if ($addAttribute)
95  {
96  $resolvedAttribute = $groupBy->getResolvedAttribute();
97  if ($this->isAttributeACalculationOrModifier($resolvedAttribute))
98  {
99  $realAttributeName = static::resolveRealAttributeName($resolvedAttribute);
100  $attributes[$resolvedAttribute] = array('label' =>
101  $this->resolveDisplayCalculationLabel($realAttributeName,
102  $this->getCalculationOrModifierType($resolvedAttribute)));
103  }
104  else
105  {
106  $realAttributeName = static::resolveRealAttributeName($resolvedAttribute);
107  $attributes[$resolvedAttribute] = array('label' => $this->model->getAttributeLabel($realAttributeName));
108  }
109  }
110  }
111  foreach ($existingDisplayAttributes as $displayAttribute)
112  {
113  $resolvedAttribute = $displayAttribute->getResolvedAttribute();
114  if ($this->isAttributeACalculationOrModifier($resolvedAttribute))
115  {
116  //We don't have to check penultimate information like GroupBys, because all display calculations are
117  //valid
118  //if the displayAttribute is part of a related data chain, ignore,
119  //since must be at the wrong spot in the chain.
120  if (!$displayAttribute->hasRelatedData() &&
121  $displayAttribute->getResolvedAttributeModelClassName() == get_class($this->model))
122  {
123  $realAttributeName = static::resolveRealAttributeName($resolvedAttribute);
124  $attributes[$resolvedAttribute] = array('label' =>
125  $this->resolveDisplayCalculationLabel($realAttributeName,
126  $this->getCalculationOrModifierType($resolvedAttribute)));
127  }
128  }
129  }
130  return $attributes;
131  }
132 
136  public function getForDrillDownAttributes()
137  {
138  $attributes = $this->getAttributesNotIncludingDerivedAttributesData();
139  $attributes = array_merge($attributes, $this->getDerivedAttributesData());
140  $attributes = array_merge($attributes, $this->getDynamicallyDerivedAttributesData());
141  return $attributes;
142  }
143 
149  public function getAttributesForChartSeries($existingGroupBys = array(), $existingDisplayAttributes = array())
150  {
151  $attributes = array();
152  foreach ($existingDisplayAttributes as $displayAttribute)
153  {
154  foreach ($existingGroupBys as $groupBy)
155  {
156  if ($groupBy->attributeIndexOrDerivedType == $displayAttribute->attributeIndexOrDerivedType)
157  {
158  $attributes[$displayAttribute->attributeIndexOrDerivedType] =
159  array('label' => $displayAttribute->getDisplayLabel());
160  }
161  }
162  }
163  return $attributes;
164  }
165 
170  public function getAttributesForChartRange ($existingDisplayAttributes = array())
171  {
172  $attributes = array();
173  foreach ($existingDisplayAttributes as $displayAttribute)
174  {
175  if (static::
176  isAttributeIndexOrDerivedTypeADisplayCalculation($displayAttribute->attributeIndexOrDerivedType))
177  {
178  $attributes[$displayAttribute->attributeIndexOrDerivedType] =
179  array('label' => $displayAttribute->getDisplayLabel());
180  }
181  }
182  return $attributes;
183  }
184  }
185 ?>
getAttributesForOrderBys($existingGroupBys=array(), $existingDisplayAttributes=array(), RedBeanModel $precedingModel=null, $precedingRelation=null)
getAttributesForChartSeries($existingGroupBys=array(), $existingDisplayAttributes=array())
Generated on Tue Feb 25 2020 07:10:35