All Data Structures Functions Variables Pages
DataToReportUtil.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 resolveReportByWizardPostData(Report $report, $postData, $wizardFormClassName)
48  {
49  assert('is_array($postData)');
50  assert('is_string($wizardFormClassName)');
51  $data = ArrayUtil::getArrayValue($postData, $wizardFormClassName);
52  if (isset($data['description']))
53  {
54  $report->setDescription($data['description']);
55  }
56  if (isset($data['moduleClassName']))
57  {
58  $report->setModuleClassName($data['moduleClassName']);
59  }
60  if (isset($data['name']))
61  {
62  $report->setName($data['name']);
63  }
64  self::resolveFiltersStructure($data, $report);
65  if (null != ArrayUtil::getArrayValue($data, 'ownerId'))
66  {
67  $owner = User::getById((int)$data['ownerId']);
68  $report->setOwner($owner);
69  }
70  else
71  {
72  $report->setOwner(new User());
73  }
74  if (isset($data['currencyConversionType']))
75  {
76  $report->setCurrencyConversionType((int)$data['currencyConversionType']);
77  }
78  if (isset($data['spotConversionCurrencyCode']))
79  {
80  $report->setSpotConversionCurrencyCode($data['spotConversionCurrencyCode']);
81  }
82  self::resolveFilters ($data, $report);
83  self::resolveOrderBys ($data, $report);
84  self::resolveDisplayAttributes ($data, $report);
85  self::resolveDrillDownDisplayAttributes ($data, $report);
86  self::resolveGroupBys ($data, $report);
87  self::resolveChart ($data, $report);
88  }
89 
94  public static function resolveFilters($data, Report $report, $shouldRemoveOnlyRuntimeFilters = false)
95  {
96  if ($shouldRemoveOnlyRuntimeFilters)
97  {
98  $report->removeRuntimeFilters();
99  }
100  else
101  {
102  $report->removeAllFilters();
103  }
104  $moduleClassName = $report->getModuleClassName();
105  if (count($filtersData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_FILTERS)) > 0)
106  {
107  $sanitizedFiltersData = self::sanitizeFiltersData($moduleClassName, $report->getType(), $filtersData);
108  foreach ($sanitizedFiltersData as $key => $filterData)
109  {
110  $filter = new FilterForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(),
111  $report->getType(), $key);
112  $filter->setAttributes($filterData);
113  $report->addFilter($filter);
114  }
115  }
116  else
117  {
118  $report->removeAllFilters();
119  }
120  }
121 
129  public static function sanitizeFiltersData($moduleClassName, $reportType, array $filtersData)
130  {
131  assert('is_string($moduleClassName)');
132  assert('is_string($reportType)');
133  $sanitizedFiltersData = array();
134  foreach ($filtersData as $key => $filterData)
135  {
136  $sanitizedFiltersData[$key] = static::sanitizeFilterData($moduleClassName,
137  $moduleClassName::getPrimaryModelName(),
138  $reportType,
139  $filterData);
140  }
141  return $sanitizedFiltersData;
142  }
143 
151  protected static function sanitizeFilterData($moduleClassName, $modelClassName, $reportType, $filterData)
152  {
153  assert('is_string($moduleClassName)');
154  assert('is_string($modelClassName)');
155  assert('is_string($reportType)');
156  assert('is_array($filterData)');
157  $filterForSanitizing = new FilterForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(),
158  $reportType);
159 
160  $filterForSanitizing->setAttributes($filterData);
161  $valueElementType = null;
162  $valueElementType = $filterForSanitizing->getValueElementType();
163  if ($valueElementType == 'MixedDateTypesForReport')
164  {
165  if (isset($filterData['value']) && $filterData['value'] !== null)
166  {
167  $filterData['value'] = DateTimeUtil::resolveValueForDateDBFormatted($filterData['value']);
168  }
169  if (isset($filterData['secondValue']) && $filterData['secondValue'] !== null)
170  {
171  $filterData['secondValue'] = DateTimeUtil::resolveValueForDateDBFormatted($filterData['secondValue']);
172  }
173  }
174  return $filterData;
175  }
176 
181  protected static function resolveOrderBys($data, Report $report)
182  {
183  $report->removeAllOrderBys();
184  $moduleClassName = $report->getModuleClassName();
185  if (count($orderBysData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_ORDER_BYS)) > 0)
186  {
187  foreach ($orderBysData as $key => $orderByData)
188  {
189  $orderBy = new OrderByForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(),
190  $report->getType(), $key);
191  $orderBy->setAttributes($orderByData);
192  $report->addOrderBy($orderBy);
193  }
194  }
195  else
196  {
197  $report->removeAllOrderBys();
198  }
199  }
200 
205  protected static function resolveDisplayAttributes($data, Report $report)
206  {
207  $report->removeAllDisplayAttributes();
209  $moduleClassName = $report->getModuleClassName();
210  if (count($displayAttributesData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES)) > 0)
211  {
212  foreach ($displayAttributesData as $key => $displayAttributeData)
213  {
214  $displayAttribute = new DisplayAttributeForReportForm($moduleClassName,
215  $moduleClassName::getPrimaryModelName(),
216  $report->getType(), $key);
217  $displayAttribute->setAttributes($displayAttributeData);
218  $report->addDisplayAttribute($displayAttribute);
219  }
220  }
221  else
222  {
223  $report->removeAllDisplayAttributes();
224  }
225  }
226 
231  protected static function resolveDrillDownDisplayAttributes($data, Report $report)
232  {
235  $moduleClassName = $report->getModuleClassName();
236  if (count($drillDownDisplayAttributesData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_DRILL_DOWN_DISPLAY_ATTRIBUTES)) > 0)
237  {
238  foreach ($drillDownDisplayAttributesData as $key => $drillDownDisplayAttributeData)
239  {
240  $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm($moduleClassName,
241  $moduleClassName::getPrimaryModelName(),
242  $report->getType(), $key);
243  $drillDownDisplayAttribute->setAttributes($drillDownDisplayAttributeData);
244  $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute);
245  }
246  }
247  else
248  {
250  }
251  }
252 
257  protected static function resolveGroupBys($data, Report $report)
258  {
259  $report->removeAllGroupBys();
260  $moduleClassName = $report->getModuleClassName();
261  if (count($groupBysData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_GROUP_BYS)) > 0)
262  {
263  foreach ($groupBysData as $key => $groupByData)
264  {
265  $groupBy = new GroupByForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(),
266  $report->getType(), $key);
267  $groupBy->setAttributes($groupByData);
268  $report->addGroupBy($groupBy);
269  }
270  }
271  else
272  {
273  $report->removeAllGroupBys();
274  }
275  }
276 
281  protected static function resolveChart($data, Report $report)
282  {
283  if ($report->getType() != Report::TYPE_SUMMATION)
284  {
285  return;
286  }
287  $moduleClassName = $report->getModuleClassName();
288  if ($moduleClassName != null)
289  {
290  $modelClassName = $moduleClassName::getPrimaryModelName();
292  make($moduleClassName, $modelClassName, $report->getType());
293  $seriesDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange(
294  $adapter->getAttributesForChartSeries($report->getGroupBys(),
295  $report->getDisplayAttributes()));
296  $rangeDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange(
297  $adapter->getAttributesForChartRange($report->getDisplayAttributes()));
298  }
299  else
300  {
301  $seriesDataAndLabels = array();
302  $rangeDataAndLabels = array();
303  }
304 
305  $chart = new ChartForReportForm($seriesDataAndLabels, $rangeDataAndLabels);
306  if (null != $chartData = ArrayUtil::getArrayValue($data, 'ChartForReportForm'))
307  {
308  $chart->setAttributes($chartData);
309  }
310  $report->setChart($chart);
311  }
312 
318  public static function resolveFiltersStructure($data, Report $report)
319  {
320  if (isset($data['filtersStructure']))
321  {
322  $report->setFiltersStructure($data['filtersStructure']);
323  }
324  }
325  }
326 ?>
static resolveReportByWizardPostData(Report $report, $postData, $wizardFormClassName)
removeAllFilters()
Definition: Report.php:480
addDrillDownDisplayAttribute(DrillDownDisplayAttributeForReportForm $drillDownDisplayAttribute)
Definition: Report.php:584
static resolveOrderBys($data, Report $report)
setOwner(User $owner)
Definition: Report.php:456
static resolveDrillDownDisplayAttributes($data, Report $report)
addDisplayAttribute(DisplayAttributeForReportForm $displayAttribute)
Definition: Report.php:560
Definition: User.php:37
getType()
Definition: Report.php:373
setCurrencyConversionType($currencyConversionType)
Definition: Report.php:398
getGroupBys()
Definition: Report.php:504
static resolveFiltersStructure($data, Report $report)
setName($name)
Definition: Report.php:364
setDescription($description)
Definition: Report.php:313
setChart(ChartForReportForm $chart)
Definition: Report.php:612
setSpotConversionCurrencyCode($spotConversionCurrencyCode)
Definition: Report.php:415
removeAllOrderBys()
Definition: Report.php:544
static sanitizeFiltersData($moduleClassName, $reportType, array $filtersData)
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
const TYPE_SUMMATION
Definition: Report.php:57
getDisplayAttributes()
Definition: Report.php:552
setFiltersStructure($filtersStructure)
Definition: Report.php:322
removeAllGroupBys()
Definition: Report.php:520
removeRuntimeFilters()
Definition: Report.php:488
removeAllDisplayAttributes()
Definition: Report.php:568
addFilter(FilterForReportForm $filter)
Definition: Report.php:472
static resolveGroupBys($data, Report $report)
getModuleClassName()
Definition: Report.php:288
static getById($id, $modelClassName=null)
static makeDataAndLabelsForSeriesOrRange(Array $attributesData)
Definition: ReportUtil.php:74
static sanitizeFilterData($moduleClassName, $modelClassName, $reportType, $filterData)
addOrderBy(OrderByForReportForm $orderBy)
Definition: Report.php:536
addGroupBy(GroupByForReportForm $groupBy)
Definition: Report.php:512
static resolveFilters($data, Report $report, $shouldRemoveOnlyRuntimeFilters=false)
removeAllDrillDownDisplayAttributes()
Definition: Report.php:592
setModuleClassName($moduleClassName)
Definition: Report.php:296
static resolveDisplayAttributes($data, Report $report)
static resolveChart($data, Report $report)
static make($moduleClassName, $modelClassName, $reportType)
Generated on Fri Jun 5 2020 07:10:34