Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelRelationsAndAttributesToSummableReportAdapter.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  const DISPLAY_CALCULATION_COUNT = 'Count';
43 
44  const DISPLAY_CALCULATION_SUMMMATION = 'Summation';
45 
46  const DISPLAY_CALCULATION_AVERAGE = 'Average';
47 
48  const DISPLAY_CALCULATION_MINIMUM = 'Minimum';
49 
50  const DISPLAY_CALCULATION_MAXIMUM = 'Maximum';
51 
52  const GROUP_BY_CALCULATION_DAY = 'Day';
53 
54  const GROUP_BY_CALCULATION_WEEK = 'Week';
55 
56  const GROUP_BY_CALCULATION_MONTH = 'Month';
57 
58  const GROUP_BY_CALCULATION_QUARTER = 'Quarter';
59 
60  const GROUP_BY_CALCULATION_YEAR = 'Year';
61 
65  protected $shouldIncludeIdAsGroupByAttribute = true;
66 
71  private static $displayCalculationAttributes;
72 
77  private static $groupByCalculatedModifierAttributes;
78 
79  public static function forgetAll()
80  {
81  parent::forgetAll();
82  self::$displayCalculationAttributes = null;
83  self::$groupByCalculatedModifierAttributes = null;
84  }
85 
90  protected static function getTranslatedDisplayCalculationShortLabel($type)
91  {
92  assert('is_string($type)');
93  $labels = array_merge(static::translatedDisplayCalculationShortLabels(),
94  static::translatedGroupByCalculationShortLabels());
95  if (isset($labels[$type]))
96  {
97  return $labels[$type];
98  }
99  return $type;
100  }
101 
105  protected static function getDisplayCalculationTypes()
106  {
107  return array(
108  self::DISPLAY_CALCULATION_COUNT,
109  self::DISPLAY_CALCULATION_SUMMMATION,
110  self::DISPLAY_CALCULATION_AVERAGE,
111  self::DISPLAY_CALCULATION_MINIMUM,
112  self::DISPLAY_CALCULATION_MAXIMUM,
113  );
114  }
115 
119  protected static function translatedDisplayCalculationShortLabels()
120  {
121  return array(
122  self::DISPLAY_CALCULATION_COUNT => Zurmo::t('ReportsModule', 'Count'),
123  self::DISPLAY_CALCULATION_SUMMMATION => Zurmo::t('ReportsModule', 'Sum'),
124  self::DISPLAY_CALCULATION_AVERAGE => Zurmo::t('ReportsModule', 'Avg'),
125  self::DISPLAY_CALCULATION_MINIMUM => Zurmo::t('ReportsModule', 'Min'),
126  self::DISPLAY_CALCULATION_MAXIMUM => Zurmo::t('ReportsModule', 'Max'),
127  );
128  }
129 
134  protected static function getTranslatedGroupByCalculationShortLabel($type)
135  {
136  assert('is_string($type)');
137  $labels = static::translatedGroupByCalculationShortLabels();
138  return $labels[$type];
139  }
140 
144  protected static function translatedGroupByCalculationShortLabels()
145  {
146  return array(
147  self::GROUP_BY_CALCULATION_DAY => Zurmo::t('Core', 'Day'),
148  self::GROUP_BY_CALCULATION_WEEK => Zurmo::t('Core', 'Week'),
149  self::GROUP_BY_CALCULATION_MONTH => Zurmo::t('Core', 'Month'),
150  self::GROUP_BY_CALCULATION_QUARTER => Zurmo::t('Core', 'Quarter'),
151  self::GROUP_BY_CALCULATION_YEAR => Zurmo::t('Core', 'Year'),
152  );
153  }
154 
158  public function getAttributesForFilters()
159  {
160  $attributes = $this->getAttributesNotIncludingDerivedAttributesData();
161  $attributes = array_merge($attributes, $this->getDynamicallyDerivedAttributesData());
162  $sortedAttributes = ArrayUtil::subValueSort($attributes, 'label', 'asort');
163  return $sortedAttributes;
164  }
165 
169  public function getAttributeLabel($attribute)
170  {
171  assert('is_string($attribute)');
172  $calculatedDisplayAttributes = $this->getDisplayCalculationAttributes();
173  $groupByModifierAttributes = $this->getGroupByModifierAttributes();
174  if (isset($calculatedDisplayAttributes[$attribute]))
175  {
176  return $calculatedDisplayAttributes[$attribute]['label'];
177  }
178  elseif (isset($groupByModifierAttributes[$attribute]))
179  {
180  return $groupByModifierAttributes[$attribute]['label'];
181  }
182  return parent::getAttributeLabel($attribute);
183  }
184 
193  public function getAttributesForDisplayAttributes($existingGroupBys = array(),
194  RedBeanModel $precedingModel = null, $precedingRelation = null)
195  {
196  assert('is_array($existingGroupBys)');
197  if (($precedingModel != null && $precedingRelation == null) ||
198  ($precedingModel == null && $precedingRelation != null))
199  {
200  throw new NotSupportedException();
201  }
202  if (empty($existingGroupBys))
203  {
204  return array();
205  }
206  $attributes = array();
207  $this->resolveGroupByAttributesForDisplayAttributes($precedingModel, $precedingRelation, $attributes,
208  $existingGroupBys);
209  $attributes = array_merge($attributes, $this->getDisplayCalculationAttributes());
210  $sortedAttributes = ArrayUtil::subValueSort($attributes, 'label', 'asort');
211  return $sortedAttributes;
212  }
213 
223  $attribute, $tableName, $columnName,
224  $columnAliasName, $queryStringExtraPart = null)
225  {
226  assert('is_string($attribute)');
227  assert('is_string($columnAliasName)');
228  assert('is_string($queryStringExtraPart) || $queryStringExtraPart == null');
229  $type = $this->getDisplayAttributeForMakingViaSelectType($attribute);
230  if ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_COUNT)
231  {
232  $selectQueryAdapter->addCountClause($tableName, $columnName, $columnAliasName);
233  }
234  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_SUMMMATION)
235  {
236  $selectQueryAdapter->addSummationClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart);
237  }
238  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_AVERAGE)
239  {
240  $selectQueryAdapter->addAverageClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart);
241  }
242  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_MINIMUM)
243  {
244  $selectQueryAdapter->addMinimumClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart);
245  }
246  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_MAXIMUM)
247  {
248  $selectQueryAdapter->addMaximumClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart);
249  }
250  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_DAY)
251  {
252  $selectQueryAdapter->addDayClause($tableName, $columnName, $columnAliasName,
253  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
254  }
255  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_WEEK)
256  {
257  $selectQueryAdapter->addWeekClause($tableName, $columnName, $columnAliasName,
258  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
259  }
260  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_MONTH)
261  {
262  $selectQueryAdapter->addMonthClause($tableName, $columnName, $columnAliasName,
263  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
264  }
265  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_QUARTER)
266  {
267  $selectQueryAdapter->addQuarterClause($tableName, $columnName, $columnAliasName,
268  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
269  }
270  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_YEAR)
271  {
272  $selectQueryAdapter->addYearClause($tableName, $columnName, $columnAliasName,
273  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
274  }
275  else
276  {
277  $selectQueryAdapter->addClause($tableName, $columnName, $columnAliasName);
278  }
279  }
280 
289  public function resolveOrderByStringForCalculationOrModifier($attribute, $tableName, $columnName, $queryStringExtraPart = null)
290  {
291  assert('is_string($attribute)');
292  assert('is_string($columnName)');
293  assert('is_string($queryStringExtraPart) || $queryStringExtraPart == null');
294  $type = $this->getDisplayAttributeForMakingViaSelectType($attribute);
295  if ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_COUNT)
296  {
297  return RedBeanModelSelectQueryAdapter::makeCountString($tableName, $columnName);
298  }
299  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_SUMMMATION)
300  {
301  return RedBeanModelSelectQueryAdapter::makeSummationString($tableName, $columnName, $queryStringExtraPart);
302  }
303  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_AVERAGE)
304  {
305  return RedBeanModelSelectQueryAdapter::makeAverageString($tableName, $columnName, $queryStringExtraPart);
306  }
307  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_MINIMUM)
308  {
309  return RedBeanModelSelectQueryAdapter::makeMinimumString($tableName, $columnName, $queryStringExtraPart);
310  }
311  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_MAXIMUM)
312  {
313  return RedBeanModelSelectQueryAdapter::makeMaximumString($tableName, $columnName, $queryStringExtraPart);
314  }
315  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_DAY)
316  {
317  return RedBeanModelSelectQueryAdapter::makeDayModifierString($tableName, $columnName,
318  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
319  }
320  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_WEEK)
321  {
322  return RedBeanModelSelectQueryAdapter::makeWeekModifierString($tableName, $columnName,
323  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
324  }
325  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_MONTH)
326  {
327  return RedBeanModelSelectQueryAdapter::makeMonthModifierString($tableName, $columnName,
328  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
329  }
330  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_QUARTER)
331  {
332  return RedBeanModelSelectQueryAdapter::makeQuarterModifierString($tableName, $columnName,
333  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
334  }
335  elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_YEAR)
336  {
337  return RedBeanModelSelectQueryAdapter::makeYearModifierString($tableName, $columnName,
338  $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute));
339  }
340  else
341  {
342  throw new NotSupportedException();
343  }
344  }
345 
350  public function relationIsReportedAsAttribute($relation)
351  {
352  assert('is_string($relation)');
353  if ($this->isAttributeACalculationOrModifier($relation))
354  {
355  return false;
356  }
357  return parent::relationIsReportedAsAttribute($relation);
358  }
359 
364  public function isAttributeACalculationOrModifier($attribute)
365  {
366  assert('is_string($attribute)');
367  $displayCalculationAttributes = $this->getDisplayCalculationAttributes();
368  $groupByModifiersAttributes = $this->getGroupByCalculatedModifierAttributes();
369  if (isset($displayCalculationAttributes[$attribute]) || isset($groupByModifiersAttributes[$attribute]))
370  {
371  return true;
372  }
373  return false;
374  }
375 
380  public function isAttributeACalculatedGroupByModifier($attribute)
381  {
382  assert('is_string($attribute)');
383  $groupByModifiersAttributes = $this->getGroupByCalculatedModifierAttributes();
384  if (isset($groupByModifiersAttributes[$attribute]))
385  {
386  return true;
387  }
388  return false;
389  }
390 
395  public static function resolveRealAttributeName($attribute)
396  {
397  assert('is_string($attribute)');
398  if ($attribute == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_COUNT)
399  {
400  return 'id';
401  }
402  return parent::resolveRealAttributeName($attribute);
403  }
404 
409  public function getCalculationOrModifierType($attribute)
410  {
411  $parts = explode(FormModelUtil::DELIMITER, $attribute);
412  if (count($parts) > 1)
413  {
414  if ($parts[1] == static::GROUP_BY_CALCULATION_WEEK)
415  {
416  return 'WeekOfYear';
417  }
418  else
419  {
420  return $parts[1];
421  }
422  }
423  return $attribute;
424  }
425 
429  public function getAttributesForGroupBys()
430  {
431  $attributes = array();
432  if ($this->shouldIncludeIdAsGroupByAttribute)
433  {
434  $attributes['id'] = array('label' => Zurmo::t('Core', 'Id'));
435  }
436  $attributes = array_merge($attributes, $this->getGroupByModifierAttributes());
437  $attributes = array_merge($attributes, $this->getDynamicallyDerivedAttributesData());
438  $sortedAttributes = ArrayUtil::subValueSort($attributes, 'label', 'asort');
439  return $sortedAttributes;
440  }
441 
446  public function isAttributeIndexOrDerivedTypeADisplayCalculation($attributeIndexOrDerivedType)
447  {
448  assert('is_string($attributeIndexOrDerivedType)');
449  $parts = explode(FormModelUtil::DELIMITER, $attributeIndexOrDerivedType);
450  if (count($parts) > 1 && in_array(array_pop($parts), static::getDisplayCalculationTypes()))
451  {
452  return true;
453  }
454  elseif (count($parts) == 1 && $parts[0] == self::DISPLAY_CALCULATION_COUNT)
455  {
456  return true;
457  }
458  return false;
459  }
460 
465  public function isDisplayAttributeMadeViaSelect($attribute)
466  {
467  $displayCalculationAttributes = $this->getDisplayCalculationAttributes();
468  $groupByModifiersAttributes = $this->getGroupByCalculatedModifierAttributes();
469  if (isset($displayCalculationAttributes[$attribute]) ||
470  isset($groupByModifiersAttributes[$attribute]))
471  {
472  return true;
473  }
474  return parent::isDisplayAttributeMadeViaSelect($attribute);
475  }
476 
482  public function getDisplayElementType($attribute)
483  {
484  assert('is_string($attribute)');
486  {
487  if ($attribute == self::DISPLAY_CALCULATION_COUNT)
488  {
489  return 'Integer';
490  }
491  list($realAttribute, $notUsed) = explode(FormModelUtil::DELIMITER, $attribute);
492  $attributeType = ModelAttributeToMixedTypeUtil::getType($this->model, $realAttribute);
493  if ($attributeType == 'Decimal' || $attributeType == 'Integer')
494  {
495  return 'Decimal';
496  }
497  elseif ($attributeType == 'Date')
498  {
499  return 'Date';
500  }
501  elseif ($attributeType == 'DateTime')
502  {
503  return 'DateTime';
504  }
505  elseif ($this->model->isRelation($realAttribute) &&
506  $this->model->getRelationModelClassName($realAttribute) == 'CurrencyValue')
507  {
508  return 'CalculatedCurrencyValue';
509  }
510  else
511  {
512  throw new NotSupportedException();
513  }
514  }
515  elseif ($this->isAttributeACalculatedGroupByModifier($attribute) &&
516  $this->getGroupByCalculationTypeByAttribute($attribute) == self::GROUP_BY_CALCULATION_MONTH)
517  {
518  return 'GroupByModifierMonth';
519  }
520  elseif ($this->isAttributeACalculatedGroupByModifier($attribute))
521  {
522  return 'Text';
523  }
524  return parent::getDisplayElementType($attribute);
525  }
526 
531  {
532  return array('MultiSelectDropDown', 'TagCloud', 'TextArea', 'Date', 'DateTime');
533  }
534 
538  protected function getDisplayCalculationAttributes()
539  {
540  if (isset(self::$displayCalculationAttributes[get_class($this->model)]))
541  {
542  return self::$displayCalculationAttributes[get_class($this->model)];
543  }
544  $attributes = array(self::DISPLAY_CALCULATION_COUNT => array('label' => Zurmo::t('ReportsModule', 'Count')));
545  foreach ($this->model->getAttributes() as $attribute => $notUsed)
546  {
547  $this->getDisplayCalculationAttribute($attributes, $attribute);
548  }
549  self::$displayCalculationAttributes[get_class($this->model)] = $attributes;
550  return self::$displayCalculationAttributes[get_class($this->model)];
551  }
552 
557  protected function getDisplayCalculationAttribute(& $attributes, $attribute)
558  {
559  $attributeType = ModelAttributeToMixedTypeUtil::getType($this->model, $attribute);
560  if ($attributeType == 'Decimal' || $attributeType == 'Integer')
561  {
562  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_SUMMMATION);
563  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_AVERAGE);
564  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_MINIMUM);
565  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_MAXIMUM);
566  }
567  elseif ($attributeType == 'Date' || $attributeType == 'DateTime')
568  {
569  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_MINIMUM);
570  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_MAXIMUM);
571  }
572  elseif ($this->model->isRelation($attribute) &&
573  $this->model->getRelationModelClassName($attribute) == 'CurrencyValue')
574  {
575  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_SUMMMATION);
576  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_AVERAGE);
577  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_MINIMUM);
578  $this->resolveDisplayCalculationAttributeData($attributes, $attribute, self::DISPLAY_CALCULATION_MAXIMUM);
579  }
580  }
581 
588  protected function resolveGroupByAttributesForDisplayAttributes(RedBeanModel $precedingModel = null,
589  $precedingRelation = null,
590  & $attributes,
591  $existingGroupBys)
592  {
593  assert('is_array($attributes)');
594  assert('is_array($existingGroupBys)');
595  foreach ($existingGroupBys as $groupBy)
596  {
597  $addAttribute = false;
598  //is there is preceding model/relation info
599  if ($precedingModel != null && $precedingRelation != null)
600  {
601  if ($groupBy->hasRelatedData() &&
602  $groupBy->getPenultimateModelClassName() == get_class($precedingModel) &&
603  $groupBy->getPenultimateRelation() == $precedingRelation &&
604  $groupBy->getResolvedAttributeModelClassName() == get_class($this->model))
605  {
606  $addAttribute = true;
607  }
608  }
609  else
610  {
611  //is there is no preceding model/relation info
612  //if the groupBy attribute is part of a related data chain, ignore,
613  //since must be at the wrong spot in the chain.
614  if (!$groupBy->hasRelatedData() &&
615  $groupBy->getResolvedAttributeModelClassName() == get_class($this->model))
616  {
617  $addAttribute = true;
618  }
619  }
620  if ($addAttribute)
621  {
622  $resolvedAttribute = $groupBy->getResolvedAttribute();
623  $calculationOrModifierType = $this->getCalculationOrModifierType($resolvedAttribute);
624  if ($this->isAttributeACalculationOrModifier($resolvedAttribute) && $calculationOrModifierType !== $resolvedAttribute)
625  {
626  $realAttributeName = static::resolveRealAttributeName($resolvedAttribute);
627  $label = $this->resolveDisplayCalculationLabel($realAttributeName,
628  $this->getCalculationOrModifierType($calculationOrModifierType));
629  }
630  else
631  {
632  $realAttributeName = static::resolveRealAttributeName($resolvedAttribute);
633  $label = $this->model->getAttributeLabel($realAttributeName);
634  }
635  $attributes[$resolvedAttribute] = array('label' => $label);
636  }
637  }
638  }
639 
645  protected function resolveDisplayCalculationAttributeData(& $attributes, $attribute, $type)
646  {
647  assert('is_array($attributes)');
648  assert('is_string($attribute)');
649  assert('is_string($type)');
650  $attributes[$attribute . FormModelUtil::DELIMITER . $type] =
651  array('label' => $this->resolveDisplayCalculationLabel($attribute, $type));
652  }
653 
659  protected function resolveDisplayCalculationLabel($attribute, $type)
660  {
661  assert('is_string($type)');
662  return $this->model->getAttributeLabel($attribute) .
663  ' -(' . static::getTranslatedDisplayCalculationShortLabel($type) . ')';
664  }
665 
669  protected function getGroupByModifierAttributes()
670  {
671  $attributes = array();
672  foreach ($this->getAttributesNotIncludingDerivedAttributesData() as $attribute => $data)
673  {
674  $attributeType = ModelAttributeToMixedTypeUtil::getType($this->model, $attribute);
675  if (!in_array($attributeType, static::getAttributeTypesToExcludeAsGroupByModifiers()))
676  {
677  $attributes[$attribute] = $data;
678  }
679  }
680  return array_merge($this->getGroupByCalculatedModifierAttributes(), $attributes);
681  }
682 
687  {
688  if (isset(self::$groupByCalculatedModifierAttributes[get_class($this->model)]))
689  {
690  return self::$groupByCalculatedModifierAttributes[get_class($this->model)];
691  }
692  $attributes = array();
693  foreach ($this->getAttributesNotIncludingDerivedAttributesData() as $attribute => $data)
694  {
695  $attributeType = ModelAttributeToMixedTypeUtil::getType($this->model, $attribute);
696  if ($attributeType == 'Date' || $attributeType == 'DateTime')
697  {
698  $this->resolveGroupByCalculationAttributeData($attributes, $attribute, self::GROUP_BY_CALCULATION_DAY);
699  $this->resolveGroupByCalculationAttributeData($attributes, $attribute, self::GROUP_BY_CALCULATION_WEEK);
700  $this->resolveGroupByCalculationAttributeData($attributes, $attribute, self::GROUP_BY_CALCULATION_MONTH);
701  $this->resolveGroupByCalculationAttributeData($attributes, $attribute, self::GROUP_BY_CALCULATION_QUARTER);
702  $this->resolveGroupByCalculationAttributeData($attributes, $attribute, self::GROUP_BY_CALCULATION_YEAR);
703  }
704  }
705  self::$groupByCalculatedModifierAttributes[get_class($this->model)] = $attributes;
706  return self::$groupByCalculatedModifierAttributes[get_class($this->model)];
707  }
708 
714  protected function resolveGroupByCalculationAttributeData(& $attributes, $attribute, $type)
715  {
716  assert('is_array($attributes)');
717  assert('is_string($attribute)');
718  assert('is_string($type)');
719  $attributes[$attribute . FormModelUtil::DELIMITER . $type] =
720  array('label' => $this->resolveGroupByCalculationLabel($attribute, $type));
721  }
722 
727  protected function getGroupByCalculationTypeByAttribute($attribute)
728  {
729  assert('is_string($attribute)');
730  list($attribute, $calculationType) = explode(FormModelUtil::DELIMITER, $attribute);
731  return $calculationType;
732  }
733 
739  protected function resolveGroupByCalculationLabel($attribute, $type)
740  {
741  assert('is_string($type)');
742  return $this->model->getAttributeLabel($attribute) .
743  ' -(' . static::getTranslatedGroupByCalculationShortLabel($type) . ')';
744  }
745 
750  protected function getDisplayAttributeForMakingViaSelectType($attribute)
751  {
752  assert('is_string($attribute)');
753  $displayCalculationAttributes = $this->getDisplayCalculationAttributes();
754  $groupByModifiersAttributes = $this->getGroupByCalculatedModifierAttributes();
755  if ($attribute == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_COUNT)
756  {
757  return ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_COUNT;
758  }
759  elseif (isset($displayCalculationAttributes[$attribute]) || isset($groupByModifiersAttributes[$attribute]))
760  {
761  $parts = explode(FormModelUtil::DELIMITER, $attribute);
762  return $parts[1];
763  }
764  }
765 
770  private function shouldDoTimeZoneAdjustmentOnModifierClause($attribute)
771  {
772  assert('is_string($attribute)');
773  if ($this->getRealModelAttributeType(static::resolveRealAttributeName($attribute)) == 'DateTime')
774  {
775  return true;
776  }
777  return false;
778  }
779  }
780 ?>
resolveDisplayAttributeTypeAndAddSelectClause(RedBeanModelSelectQueryAdapter $selectQueryAdapter, $attribute, $tableName, $columnName, $columnAliasName, $queryStringExtraPart=null)
static subValueSort($array, $subKey, $sortFunctionName)
Definition: ArrayUtil.php:153
resolveOrderByStringForCalculationOrModifier($attribute, $tableName, $columnName, $queryStringExtraPart=null)
resolveGroupByAttributesForDisplayAttributes(RedBeanModel $precedingModel=null, $precedingRelation=null, &$attributes, $existingGroupBys)
getAttributesForDisplayAttributes($existingGroupBys=array(), RedBeanModel $precedingModel=null, $precedingRelation=null)
static getType($model, $attributeName)
Generated on Sat Aug 15 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.