Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SummationReportDataProvider.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  {
42  protected $haveGrandTotals = true;
43 
49  private $resolvedDisplayAttributes;
50 
55  public function __construct(Report $report, array $config = array())
56  {
57  parent::__construct($report, $config);
58  }
59 
63  public function calculateTotalItemCount()
64  {
65  $selectQueryAdapter = new RedBeanModelSelectQueryAdapter();
66  $sql = $this->makeSqlQueryForFetchingTotalItemCount($selectQueryAdapter);
67  $rows = ZurmoRedBean::getAll($sql);
68  $count = count($rows);
69  return $count;
70  }
71 
76  {
77  if (ChartRules::isStacked($this->report->getChart()->type))
78  {
80  }
81  else
82  {
84  }
85  }
86 
90  public function resolveDisplayAttributes()
91  {
92  if ($this->resolvedDisplayAttributes != null)
93  {
94  return $this->resolvedDisplayAttributes;
95  }
96  $this->resolvedDisplayAttributes = array();
97  foreach ($this->report->getDisplayAttributes() as $displayAttribute)
98  {
99  $this->resolvedDisplayAttributes[] = $displayAttribute;
100  }
101 
102  if (($this->report->getDrillDownDisplayAttributes()) > 0)
103  {
104  $this->resolveGroupBysThatAreNotYetDisplayAttributesAsDisplayAttributes();
105  }
106  return $this->resolvedDisplayAttributes;
107  }
108 
112  public function resolveFirstSeriesLabel()
113  {
114  foreach ($this->report->getDisplayAttributes() as $key => $displayAttribute)
115  {
116  if ($displayAttribute->attributeIndexOrDerivedType == $this->report->getChart()->firstSeries)
117  {
118  return $displayAttribute->label;
119  }
120  }
121  }
122 
126  public function resolveFirstRangeLabel()
127  {
128  foreach ($this->report->getDisplayAttributes() as $key => $displayAttribute)
129  {
130  if ($displayAttribute->attributeIndexOrDerivedType == $this->report->getChart()->firstRange)
131  {
132  return $displayAttribute->label;
133  }
134  }
135  }
136 
141  {
142  foreach ($this->report->getDisplayAttributes() as $key => $displayAttribute)
143  {
144  if ($displayAttribute->attributeIndexOrDerivedType == $this->report->getChart()->firstRange)
145  {
146  return $displayAttribute->isATypeOfCurrencyValue();
147  }
148  }
149  return false;
150  }
151 
156  protected function isReportValidType()
157  {
158  if ($this->report->getType() != Report::TYPE_SUMMATION)
159  {
160  throw new NotSupportedException();
161  }
162  }
163 
167  protected function fetchChartData()
168  {
169  return $this->runQueryAndGetResolveResultsData(null, null);
170  }
171 
176  {
177  foreach ($this->report->getDisplayAttributes() as $key => $displayAttribute)
178  {
179  if ($displayAttribute->attributeIndexOrDerivedType == $this->report->getChart()->firstSeries)
180  {
181  return $displayAttribute->resolveAttributeNameForGridViewColumn($key);
182  }
183  }
184  }
185 
190  {
191  foreach ($this->report->getDisplayAttributes() as $key => $displayAttribute)
192  {
193  if ($displayAttribute->attributeIndexOrDerivedType == $this->report->getChart()->firstRange)
194  {
195  return $displayAttribute->resolveAttributeNameForGridViewColumn($key);
196  }
197  }
198  }
199 
204  {
205  foreach ($this->report->getDisplayAttributes() as $key => $displayAttribute)
206  {
207  if ($displayAttribute->attributeIndexOrDerivedType == $this->report->getChart()->secondSeries)
208  {
209  return $displayAttribute->resolveAttributeNameForGridViewColumn($key);
210  }
211  }
212  }
213 
218  {
219  foreach ($this->report->getDisplayAttributes() as $key => $displayAttribute)
220  {
221  if ($displayAttribute->attributeIndexOrDerivedType == $this->report->getChart()->secondRange)
222  {
223  return $displayAttribute->resolveAttributeNameForGridViewColumn($key);
224  }
225  }
226  }
227 
232  {
233  $resultsData = $this->fetchChartData();
234  $firstRangeAttributeName = $this->resolveChartFirstRangeAttributeNameForReportResultsRowData();
235  $firstSeriesDisplayAttributeKey = $this->getDisplayAttributeKeyByAttribute($this->report->getChart()->firstSeries);
236  $chartData = array();
237  foreach ($resultsData as $data)
238  {
239  $firstSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($firstSeriesDisplayAttributeKey);
241  => $data->$firstRangeAttributeName,
243  =>
244  $this->getDisplayAttributeByAttribute($this->report->getChart()->firstSeries)->
245  resolveValueAsLabelForHeaderCell($firstSeriesDataValue, true));
246  }
247  return new ReportDataProviderToAmChartMakerAdapter($this->report, $chartData);
248  }
249 
254  {
255  $resultsData = $this->fetchChartData();
256  $firstRangeAttributeName = $this->resolveChartFirstRangeAttributeNameForReportResultsRowData();
257  $secondRangeAttributeName = $this->resolveChartSecondRangeAttributeNameForReportResultsRowData();
258  $chartData = array();
259  $secondSeriesValueData = array();
260  $secondSeriesDisplayLabels = array();
261  $secondSeriesValueCount = 1;
262  $firstSeriesDisplayAttributeKey = $this->getDisplayAttributeKeyByAttribute($this->report->getChart()->firstSeries);
263  $secondSeriesDisplayAttributeKey = $this->getDisplayAttributeKeyByAttribute($this->report->getChart()->secondSeries);
264  foreach ($resultsData as $data)
265  {
266  $firstSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($firstSeriesDisplayAttributeKey);
267  $chartData[$firstSeriesDataValue] = array(
269  $this->getDisplayAttributeByAttribute($this->report->getChart()->firstSeries)->
270  resolveValueAsLabelForHeaderCell($firstSeriesDataValue, true));
271  $secondSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($secondSeriesDisplayAttributeKey);
272  if (!isset($secondSeriesValueData[$secondSeriesDataValue]))
273  {
274  $secondSeriesValueData[$secondSeriesDataValue] = $secondSeriesValueCount;
275  $secondSeriesDisplayLabels[$secondSeriesValueCount] = $this->getDisplayAttributeByAttribute(
276  $this->report->getChart()->secondSeries)->
277  resolveValueAsLabelForHeaderCell($secondSeriesDataValue, true);
278  $secondSeriesValueCount++;
279  }
280  }
281  foreach ($resultsData as $data)
282  {
283  $firstSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($firstSeriesDisplayAttributeKey);
284  $secondSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($secondSeriesDisplayAttributeKey);
285  $secondSeriesKey = $secondSeriesValueData[$secondSeriesDataValue];
286  if (!isset($chartData[$firstSeriesDataValue]
288  {
289  $chartData[$firstSeriesDataValue]
291  }
292  $chartData[$firstSeriesDataValue]
294  $data->$firstRangeAttributeName;
295  if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveFirstRangeDisplayLabelName($secondSeriesKey)]))
296  {
297  $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveFirstRangeDisplayLabelName($secondSeriesKey)] =
298  $this->getDisplayAttributeByAttribute($this->report->getChart()->firstRange)->label;
299  }
300  if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesValueName($secondSeriesKey)]))
301  {
302  $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesValueName($secondSeriesKey)] = 0;
303  }
304  $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesValueName($secondSeriesKey)] += $data->$secondRangeAttributeName;
305  if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)]))
306  {
307  $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)] =
308  $secondSeriesDisplayLabels[$secondSeriesKey];
309  }
310  if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)]))
311  {
312  $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)] =
313  $this->getDisplayAttributeByAttribute($this->report->getChart()->secondRange)->label;
314  }
315  }
316  return new ReportDataProviderToAmChartMakerAdapter($this->report, array_values($chartData),
317  $secondSeriesValueData, $secondSeriesDisplayLabels,
318  $secondSeriesValueCount - 1);
319  }
320 
321  private function resolveGroupBysThatAreNotYetDisplayAttributesAsDisplayAttributes()
322  {
323  foreach ($this->resolveGroupBys() as $groupBy)
324  {
325  if (null === $index = $this->report->getDisplayAttributeIndex($groupBy->attributeIndexOrDerivedType))
326  {
327  $displayAttribute = new DisplayAttributeForReportForm(
328  $groupBy->getModuleClassName(),
329  $groupBy->getModelClassName(),
330  $this->report->getType());
331  $displayAttribute->attributeIndexOrDerivedType = $groupBy->attributeIndexOrDerivedType;
332  $displayAttribute->queryOnly = true;
333  $displayAttribute->valueUsedAsDrillDownFilter = true;
334  $this->resolvedDisplayAttributes[] = $displayAttribute;
335  }
336  else
337  {
338  $this->resolvedDisplayAttributes[$index]->valueUsedAsDrillDownFilter = true;
339  }
340  }
341  }
342  }
343 ?>
getDisplayAttributeKeyByAttribute($attribute)
__construct(Report $report, array $config=array())
runQueryAndGetResolveResultsData($offset, $limit)
const TYPE_SUMMATION
Definition: Report.php:57
getDisplayAttributeByAttribute($attribute)
makeSqlQueryForFetchingTotalItemCount($selectQueryAdapter, $selectJustCount=false)
Generated on Fri Jul 10 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.