Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelRelationsAndAttributesToReportAdapter.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 DYNAMIC_ATTRIBUTE_USER = 'User';
43 
44  const DYNAMIC_RELATION_INFERRED = 'Inferred';
45 
49  private static $adaptersByModelClassNameAndType;
50 
54  protected $model;
55 
59  protected $rules;
60 
64  protected $reportType;
65 
69  protected $moduleClassName;
70 
75  private static $derivedAttributesData;
76 
81  private static $attributesNotIncludingDerivedAttributesData;
82 
87  private static $inferredRelationsData;
88 
93  private static $dynamicallyDerivedAttributesData;
94 
95  public static function forgetAll()
96  {
97  self::$derivedAttributesData = null;
98  self::$attributesNotIncludingDerivedAttributesData = null;
99  self::$inferredRelationsData = null;
100  self::$dynamicallyDerivedAttributesData = null;
101  }
102 
110  public static function make($moduleClassName, $modelClassName, $reportType)
111  {
112  assert('is_string($moduleClassName)');
113  assert('is_string($modelClassName)');
114  assert('is_string($reportType)');
115  if (!isset(self::$adaptersByModelClassNameAndType[$modelClassName . $reportType]))
116  {
117  $rules = ReportRules::makeByModuleClassName($moduleClassName);
118  $model = new $modelClassName(false);
119  if ($reportType == Report::TYPE_ROWS_AND_COLUMNS)
120  {
121  $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules,
122  $reportType, $moduleClassName);
123  }
124  elseif ($reportType == Report::TYPE_SUMMATION)
125  {
126  $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules,
127  $reportType, $moduleClassName);
128  }
129  elseif ($reportType == Report::TYPE_MATRIX)
130  {
131  $adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules,
132  $reportType, $moduleClassName);
133  }
134  else
135  {
136  throw new NotSupportedException();
137  }
138  self::$adaptersByModelClassNameAndType[$modelClassName . $reportType] = $adapter;
139  }
140  return self::$adaptersByModelClassNameAndType[$modelClassName . $reportType];
141  }
142 
146  public function getModel()
147  {
148  return $this->model;
149  }
150 
154  public function getModelClassName()
155  {
156  return get_class($this->model);
157  }
158 
162  public function getModuleClassName()
163  {
164  return $this->moduleClassName;
165  }
166 
170  public function getRules()
171  {
172  return $this->rules;
173  }
174 
183  public function __construct(RedBeanModel $model, ReportRules $rules, $reportType, $moduleClassName = null)
184  {
185  assert('is_string($reportType)');
186  assert('is_string($moduleClassName) || $moduleClassName == null');
187  $this->model = $model;
188  $this->rules = $rules;
189  $this->reportType = $reportType;
190  if ($moduleClassName == null)
191  {
192  $moduleClassName = $model::getModuleClassName();
193  }
194  $this->moduleClassName = $moduleClassName;
195  }
196 
203  public function getAttributeLabel($attribute)
204  {
205  assert('is_string($attribute)');
206  if ($this->isDynamicallyDerivedAttribute($attribute))
207  {
208  $resolvedAttribute = $attribute;
209  }
210  else
211  {
212  $resolvedAttribute = static::resolveRealAttributeName($attribute);
213  }
214  $attributesData = $this->getAttributesIncludingDerivedAttributesData();
215  if (!isset($attributesData[$resolvedAttribute]) && !$this->model->isAttribute($resolvedAttribute))
216  {
217  throw new NotSupportedException('Label not found for: ' . $resolvedAttribute);
218  }
219  //PrimaryAddress for example would not be an attribute that is reportable but is still required for getting labels
220  elseif ($this->model->isAttribute($resolvedAttribute))
221  {
222  return $this->model->getAttributeLabel($resolvedAttribute);
223  }
224  return $attributesData[$resolvedAttribute]['label'];
225  }
226 
232  public function getRelationLabel($relation)
233  {
234  assert('is_string($relation)');
235  $relationsData = $this->getSelectableRelationsData();
236  if (!isset($relationsData[$relation]))
237  {
238  throw new NotSupportedException();
239  }
240  return $relationsData[$relation]['label'];
241  }
242 
249  public function isReportedOnAsARelation($relationOrAttribute)
250  {
251  assert('is_string($relationOrAttribute)');
252  $relations = $this->getSelectableRelationsData();
253  if (isset($relations[$relationOrAttribute]))
254  {
255  return true;
256  }
257  else
258  {
259  return false;
260  }
261  }
262 
268  public function getRelationModuleClassName($relation)
269  {
270  assert('is_string($relation)');
271  $delimiter = FormModelUtil::DELIMITER;
272  $relationAndInferredData = explode($delimiter, $relation);
273  $derivedRelations = $this->getDerivedRelationsViaCastedUpModelData();
274  if (count($relationAndInferredData) == 3)
275  {
276  list($modelClassName, $notUsed, $notUsed2) = $relationAndInferredData;
277  return $modelClassName::getModuleClassName();
278  }
279  elseif (count($relationAndInferredData) == 1 && isset($derivedRelations[$relation]))
280  {
281  $modelClassName = get_class($this->model);
282  $modelClassName = $modelClassName::getDerivedRelationModelClassName($relation);
283  return $modelClassName::getModuleClassName();
284  }
285  elseif (count($relationAndInferredData) == 1)
286  {
287  $modelClassName = $this->model->getRelationModelClassName($relation);
288  return $modelClassName::getModuleClassName();
289  }
290  else
291  {
292  throw new NotSupportedException();
293  }
294  }
295 
301  public function getRelationModelClassName($relation)
302  {
303  assert('is_string($relation)');
304 
305  $delimiter = FormModelUtil::DELIMITER;
306  $relationAndInferredData = explode($delimiter, $relation);
307  $derivedRelations = $this->getDerivedRelationsViaCastedUpModelData();
308 
316  if (count($relationAndInferredData) == 3)
317  {
318  list($modelClassName, $notUsed, $notUsed2) = $relationAndInferredData;
319  return $modelClassName;
320  }
321 
329  elseif (count($relationAndInferredData) == 1 && isset($derivedRelations[$relation]))
330  {
331  $modelClassName = get_class($this->model);
332  return $modelClassName::getDerivedRelationModelClassName($relation);
333  }
334  elseif (count($relationAndInferredData) == 1)
335  {
336  return $this->model->getRelationModelClassName($relation);
337  }
338  else
339  {
340  throw new NotSupportedException();
341  }
342  }
343 
347  public function getAttributesForFilters()
348  {
349  throw new NotImplementedException();
350  }
351 
356  {
357  throw new NotImplementedException();
358  }
359 
363  public function getAttributesForOrderBys()
364  {
365  throw new NotImplementedException();
366  }
367 
371  public function getAttributesForGroupBys()
372  {
373  throw new NotImplementedException();
374  }
375 
381  public function getAvailableOperatorsType($attribute)
382  {
383  assert('is_string($attribute)');
384  if ($this->isDynamicallyDerivedAttribute($attribute))
385  {
386  return ModelAttributeToReportOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_HAS_ONE;
387  }
388  if ($this->isDerivedAttribute($attribute))
389  {
390  if ($attribute == 'UniqueIdentifier')
391  {
392  return ModelAttributeToReportOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER;
393  }
394  else
395  {
396  throw new NotSupportedException();
397  }
398  }
399  $resolvedAttribute = static::resolveRealAttributeName($attribute);
400  if (null != $availableOperatorsTypeFromRule = $this->rules->getAvailableOperatorsTypes($this->model,
401  $resolvedAttribute))
402  {
403  return $availableOperatorsTypeFromRule;
404  }
405  return ModelAttributeToReportOperatorTypeUtil::getAvailableOperatorsType($this->model, $resolvedAttribute);
406  }
407 
414  public function getFilterValueElementType($attribute)
415  {
416  assert('is_string($attribute)');
417  if ($this->isDerivedAttribute($attribute))
418  {
419  return null;
420  }
421  if ($this->isDynamicallyDerivedAttribute($attribute))
422  {
423  $parts = explode(FormModelUtil::DELIMITER, $attribute);
424  if ($parts[1] != 'User')
425  {
426  throw new NotSupportedException();
427  }
428  return 'MixedLoggedInUserTypesAndUsers';
429  }
430  $resolvedAttribute = static::resolveRealAttributeName($attribute);
431  if (null != $filterValueElementTypeFromRule = $this->rules->getFilterValueElementType($this->model,
432  $resolvedAttribute))
433  {
434  return $filterValueElementTypeFromRule;
435  }
436  return ModeAttributeToReportFilterValueElementTypeUtil::getType($this->model, $resolvedAttribute);
437  }
438 
445  public function getDisplayElementType($attribute)
446  {
447  assert('is_string($attribute)');
448  $derivedAttributes = $this->getDerivedAttributesData();
449  if (isset($derivedAttributes[$attribute]))
450  {
451  return $derivedAttributes[$attribute]['derivedAttributeType'];
452  }
453  if ($this->isDynamicallyDerivedAttribute($attribute))
454  {
455  $parts = explode(FormModelUtil::DELIMITER, $attribute);
456  if ($parts[1] != 'User')
457  {
458  throw new NotSupportedException();
459  }
460  return 'User';
461  }
462  $resolvedAttribute = static::resolveRealAttributeName($attribute);
463  return $this->getRealModelAttributeType($resolvedAttribute);
464  }
465 
470  public function getRealModelAttributeType($attribute)
471  {
472  assert('is_string($attribute)');
473  return ModelAttributeToMixedTypeUtil::getType($this->model, $attribute);
474  }
475 
479  public function getAllRelationsData()
480  {
481  $attributes = array();
482  foreach ($this->model->getAttributes() as $attribute => $notUsed)
483  {
484  if ($this->model->isRelation($attribute))
485  {
486  $attributes[$attribute] = array('label' => $this->model->getAttributeLabel($attribute));
487  }
488  }
489  return $attributes;
490  }
491 
500  public function getSelectableRelationsDataResolvedForUserAccess(User $user, Array $relations)
501  {
502  assert('$user->id > 0');
503  foreach ($relations as $relation => $data)
504  {
505  if (null != $moduleClassName = $this->getRelationModuleClassName($relation))
506  {
507  if ($moduleClassName != 'UsersModule' && !RightsUtil::canUserAccessModule($moduleClassName , $user))
508  {
509  unset($relations[$relation]);
510  }
511  }
512  else
513  {
514  throw new NotSupportedException($relation);
515  }
516  }
517  return $relations;
518  }
519 
531  public function getSelectableRelationsData(RedBeanModel $precedingModel = null, $precedingRelation = null)
532  {
533  if (($precedingModel != null && $precedingRelation == null) ||
534  ($precedingModel == null && $precedingRelation != null))
535  {
536  throw new NotSupportedException();
537  }
538  $attributes = array();
539  foreach ($this->model->getAttributes() as $attribute => $notUsed)
540  {
541  if ($this->model->isRelation($attribute) &&
542  !$this->rules->relationIsReportedAsAttribute($this->model, $attribute) &&
543  $this->rules->attributeIsReportable($this->model, $attribute) &&
544  !$this->relationLinksToPrecedingRelation($attribute, $precedingModel, $precedingRelation)
545  )
546  {
547  $this->resolveRelationToSelectableRelationData($attributes, $attribute);
548  }
549  }
550  $attributes = array_merge($attributes, $this->getDerivedRelationsViaCastedUpModelData($precedingModel, $precedingRelation));
551  $attributes = array_merge($attributes, $this->getInferredRelationsData($precedingModel, $precedingRelation));
552  $sortedAttributes = ArrayUtil::subValueSort($attributes, 'label', 'asort');
553  return $sortedAttributes;
554  }
555 
560  {
561  $attributes = array('id' => array('label' => Zurmo::t('Core', 'Id')));
562  $attributes = array_merge($attributes, $this->getAttributesNotIncludingDerivedAttributesData());
563  $attributes = array_merge($attributes, $this->getDerivedAttributesData());
564  $attributes = array_merge($attributes, $this->getDynamicallyDerivedAttributesData());
565  return $attributes;
566  }
567 
573  public function isRelationASingularRelation($relation)
574  {
575  assert('is_string($relation)');
576  $modelClassName = get_class($this->model);
577  $delimiter = FormModelUtil::DELIMITER;
578  $relationAndInferredData = explode($delimiter, $relation);
579  $derivedRelations = $this->getDerivedRelationsViaCastedUpModelData();
580  if (count($relationAndInferredData) == 3)
581  {
582  list($modelClassNameNotUsed, $relation, $notUsed) = $relationAndInferredData;
583  $type = $modelClassName::getRelationType($relation);
584  }
585  elseif (count($relationAndInferredData) == 2)
586  {
587  list($relation, $notUsed) = $relationAndInferredData;
588  $type = $modelClassName::getRelationType($relation);
589  }
590  elseif (count($relationAndInferredData) == 1 && isset($derivedRelations[$relation]))
591  {
592  $type = $modelClassName::getDerivedRelationType($relation);
593  }
594  elseif (count($relationAndInferredData) == 1)
595  {
596  $type = $modelClassName::getRelationType($relation);
597  }
598  else
599  {
600  throw new NotSupportedException();
601  }
602  if ( $type == RedBeanModel::HAS_ONE ||
605  {
606  return true;
607  }
608  return false;
609  }
610 
617  public function isOwnedRelation($relation)
618  {
619  assert('is_string($relation)');
620  $delimiter = FormModelUtil::DELIMITER;
621  $relationAndInferredData = explode($delimiter, $relation);
622  $derivedRelations = $this->getDerivedRelationsViaCastedUpModelData();
623  if (count($relationAndInferredData) == 3)
624  {
625  return false;
626  }
627  elseif (count($relationAndInferredData) == 2)
628  {
629  return false;
630  }
631  elseif (count($relationAndInferredData) == 1 && isset($derivedRelations[$relation]))
632  {
633  return false;
634  }
635  elseif (count($relationAndInferredData) == 1)
636  {
637  return $this->model->isOwnedRelation($relation);
638  }
639  else
640  {
641  throw new NotSupportedException();
642  }
643  }
644 
652  public function getInferredRelationsData(RedBeanModel $precedingModel = null, $precedingRelation = null)
653  {
654  if (($precedingModel != null && $precedingRelation == null) ||
655  ($precedingModel == null && $precedingRelation != null))
656  {
657  throw new NotSupportedException();
658  }
659  $cacheKey = get_class($this->model) . $precedingModel . $precedingRelation;
660  if (isset(self::$inferredRelationsData[$cacheKey]))
661  {
662  return self::$inferredRelationsData[$cacheKey];
663  }
664  $attributes = array();
665  foreach ($this->model->getAttributes() as $attribute => $notUsed)
666  {
667  $inferredRelationModelClassNames = $this->getInferredRelationModelClassNamesForRelation($attribute);
668  if ($this->model->isRelation($attribute) && $inferredRelationModelClassNames != null)
669  {
670  foreach ($inferredRelationModelClassNames as $modelClassName)
671  {
672  if (!$this->inferredRelationLinksToPrecedingRelation($modelClassName, $attribute, $precedingModel, $precedingRelation))
673  {
674  $attributes[$modelClassName . FormModelUtil::DELIMITER .
675  $attribute . FormModelUtil::DELIMITER . self::DYNAMIC_RELATION_INFERRED] =
676  array('label' => $modelClassName::getModelLabelByTypeAndLanguage('Plural'));
677  }
678  }
679  }
680  }
681  self::$inferredRelationsData[$cacheKey] = $attributes;
682  return self::$inferredRelationsData[$cacheKey];
683  }
684 
690  public function getFilterRulesByAttribute($attribute, $ruleAttributeName)
691  {
692  $rules = array();
693  $dynamicallyDerivedAttributes = $this->getDynamicallyDerivedAttributesData();
694  if ($this->model->isAttribute($attribute) && $this->model->{$attribute} instanceof CurrencyValue)
695  {
696  $rules[] = array($ruleAttributeName, 'type', 'type' => 'float');
697  }
698  elseif (in_array($attribute, $dynamicallyDerivedAttributes))
699  {
700  $rules[] = array($ruleAttributeName, 'type' => 'string');
701  }
702  elseif ($this->model->isAttribute($attribute))
703  {
706  get_class($this->model),
707  $attribute,
708  $ruleAttributeName,
709  false,
710  true,
711  false);
712  foreach ($rules as $key => $rule)
713  {
714  if (in_array('email', $rule))
715  {
716  $rules[$key] = array($ruleAttributeName, 'type', 'type' => 'string');
717  }
718  }
719  }
720  return $rules;
721  }
722 
727  public function relationIsReportedAsAttribute($relation)
728  {
729  assert('is_string($relation)');
730  if ($this->model->isAttribute($relation) && $this->isReportedOnAsARelation($relation))
731  {
732  return false;
733  }
734  if ($this->model->isAttribute($relation) && !$this->model->isRelation($relation))
735  {
736  return false;
737  }
738  if ($this->isDerivedAttribute($relation))
739  {
740  return false;
741  }
742  return $this->rules->relationIsReportedAsAttribute($this->model, $relation);
743  }
744 
750  {
751  assert('is_string($relation)');
752  $relationsData = $this->getDerivedRelationsViaCastedUpModelData();
753  if (isset($relationsData[$relation]))
754  {
755  return true;
756  }
757  return false;
758  }
759 
764  public function isInferredRelation($relation)
765  {
766  assert('is_string($relation)');
767  $relationsData = $this->getInferredRelationsData();
768  if (isset($relationsData[$relation]))
769  {
770  return true;
771  }
772  return false;
773  }
774 
779  public function isDynamicallyDerivedAttribute($attribute)
780  {
781  assert('is_string($attribute)');
782  $dynamicallyDerivedAttributes = $this->getDynamicallyDerivedAttributesData();
783  if (isset($dynamicallyDerivedAttributes[$attribute]))
784  {
785  return true;
786  }
787  return false;
788  }
789 
794  public function getRawValueRelatedAttribute($attribute)
795  {
796  if ($this->relationIsReportedAsAttribute($attribute))
797  {
798  return $this->getRules()->getRawValueRelatedAttributeForRelationReportedAsAttribute(
799  $this->getModel(), $attribute);
800  }
801  }
802 
807  public function isAttributeReadOptimization($attribute)
808  {
809  if ($attribute == 'ReadOptimization')
810  {
811  return true;
812  }
813  return false;
814  }
815 
820  public function isDerivedAttribute($attribute)
821  {
822  assert('is_string($attribute)');
823  $derivedAttributes = $this->getDerivedAttributesData();
824  if (isset($derivedAttributes[$attribute]))
825  {
826  return true;
827  }
828  return false;
829  }
830 
835  public static function resolveRealAttributeName($attribute)
836  {
837  assert('is_string($attribute)');
838  $delimiter = FormModelUtil::DELIMITER;
839  $attributeAndInferredData = explode($delimiter, $attribute);
840  if (count($attributeAndInferredData) == 3)
841  {
842  list($modelClassName, $attribute, $notUsed) = $attributeAndInferredData;
843  return $attribute;
844  }
845  elseif (count($attributeAndInferredData) == 2)
846  {
847  list($attribute, $notUsed) = $attributeAndInferredData;
848  return $attribute;
849  }
850  else
851  {
852  return $attribute;
853  }
854  }
855 
862  public function isDisplayAttributeMadeViaSelect($attribute)
863  {
864  assert('is_string($attribute)');
865  return false;
866  }
867 
872  {
873  if (isset(self::$attributesNotIncludingDerivedAttributesData[get_class($this->model)]))
874  {
875  return self::$attributesNotIncludingDerivedAttributesData[get_class($this->model)];
876  }
877  $attributes = array();
878  foreach ($this->model->getAttributes() as $attribute => $notUsed)
879  {
880  if ((($this->model->isRelation($attribute) &&
881  $this->rules->relationIsReportedAsAttribute($this->model, $attribute)) ||
882  !$this->model->isRelation($attribute) &&
883  $this->rules->attributeIsReportable($this->model, $attribute)))
884  {
885  $attributes[$attribute] = array('label' => $this->model->getAttributeLabel($attribute));
886  }
887  }
888  self::$attributesNotIncludingDerivedAttributesData[get_class($this->model)] = $attributes;
889  return self::$attributesNotIncludingDerivedAttributesData[get_class($this->model)];
890  }
891 
899  protected function derivedRelationLinksToPrecedingRelation($relationModelClassName, $opposingRelation, RedBeanModel $precedingModel = null,
900  $precedingRelation = null)
901  {
902  assert('is_string($relationModelClassName)');
903  assert('is_string($opposingRelation)');
904  if ($precedingModel == null || $precedingRelation == null)
905  {
906  return false;
907  }
908  if ($relationModelClassName == get_class($precedingModel) && $opposingRelation == $precedingRelation)
909  {
910  return true;
911  }
912  return false;
913  }
914 
922  protected function inferredRelationLinksToPrecedingRelation($inferredModelClassName, $relation, RedBeanModel $precedingModel = null,
923  $precedingRelation = null)
924  {
925  assert('is_string($inferredModelClassName)');
926  if ($precedingModel == null || $precedingRelation == null)
927  {
928  return false;
929  }
930  if ($inferredModelClassName != get_class($precedingModel))
931  {
932  return false;
933  }
934  $modelClassName = get_class($precedingModel);
935  if ($modelClassName::isADerivedRelationViaCastedUpModel($precedingRelation) &&
936  $modelClassName::getDerivedRelationViaCastedUpModelOpposingRelationName($precedingRelation) == $relation)
937  {
938  return true;
939  }
940  return false;
941  }
942 
949  protected function relationLinksToPrecedingRelation($relation, RedBeanModel $precedingModel = null,
950  $precedingRelation = null)
951  {
952  return RedBeanModel::relationLinksToPrecedingRelation(get_class($this->model), $relation,
953  get_class($precedingModel), $precedingRelation);
954  }
955 
963  protected function getDerivedRelationsViaCastedUpModelData(RedBeanModel $precedingModel = null, $precedingRelation = null)
964  {
965  if (($precedingModel != null && $precedingRelation == null) ||
966  ($precedingModel == null && $precedingRelation != null))
967  {
968  throw new NotSupportedException();
969  }
970  $attributes = array();
971  $metadata = $this->model->getMetadata();
972  foreach ($metadata as $modelClassName => $modelClassMetadata)
973  {
974  if (isset($metadata[$modelClassName]["derivedRelationsViaCastedUpModel"]))
975  {
976  foreach ($metadata[$modelClassName]["derivedRelationsViaCastedUpModel"] as $relation => $derivedRelationData)
977  {
978  $modelClassName = get_class($this->model);
979  if (!$this->derivedRelationLinksToPrecedingRelation(
980  $modelClassName::getDerivedRelationModelClassName($relation),
981  $modelClassName::getDerivedRelationViaCastedUpModelOpposingRelationName($relation),
982  $precedingModel,
983  $precedingRelation))
984  {
985  $attributes[$relation] = array('label' => $this->model->getAttributeLabel($relation));
986  }
987  }
988  }
989  }
990  return $attributes;
991  }
992 
996  protected function getDerivedAttributesData()
997  {
998  if (!isset(self::$derivedAttributesData[get_class($this->model)]) ||
999  self::$derivedAttributesData[get_class($this->model)] === null)
1000  {
1001  $attributes = array();
1002  $calculatedAttributes = CalculatedDerivedAttributeMetadata::getAllByModelClassName(get_class($this->model));
1003  foreach ($calculatedAttributes as $attribute)
1004  {
1005  $attributes[$attribute->name] = array('label' => $attribute->getLabelByLanguage(Yii::app()->language),
1006  'derivedAttributeType' => 'CalculatedNumber');
1007  }
1008  self::$derivedAttributesData[get_class($this->model)] =
1009  array_merge($attributes, $this->getDerivedAttributesDataByReportRules());
1010  }
1011  return self::$derivedAttributesData[get_class($this->model)];
1012  }
1013 
1018  {
1019  if (isset(self::$dynamicallyDerivedAttributesData[get_class($this->model)]))
1020  {
1021  return self::$dynamicallyDerivedAttributesData[get_class($this->model)];
1022  }
1023  $attributes = array();
1024  foreach ($this->model->getAttributes() as $attribute => $notUsed)
1025  {
1026  if (!$this->model instanceof User &&
1027  $this->model->isRelation($attribute) &&
1028  $this->model->getRelationModelClassName($attribute) == 'User')
1029  {
1030  $attributes[$attribute . FormModelUtil::DELIMITER . self::DYNAMIC_ATTRIBUTE_USER] =
1031  array('label' => $this->model->getAttributeLabel($attribute));
1032  }
1033  }
1034  self::$dynamicallyDerivedAttributesData[get_class($this->model)] = $attributes;
1035  return self::$dynamicallyDerivedAttributesData[get_class($this->model)];
1036  }
1037 
1043  {
1044  assert('is_string($relation)');
1045  return $this->model->getInferredRelationModelClassNamesForRelation($relation);
1046  }
1047 
1052  protected function resolveRelationToSelectableRelationData(& $attributes, $attribute)
1053  {
1054  assert('is_array($attributes)');
1055  assert('is_string($attribute)');
1056  $attributes[$attribute] = array('label' => $this->model->getAttributeLabel($attribute));
1057  }
1058 
1064  {
1065  return $this->rules->getDerivedAttributeTypesData($this->model);
1066  }
1067  }
1068 ?>
Definition: User.php:37
getInferredRelationsData(RedBeanModel $precedingModel=null, $precedingRelation=null)
__construct(RedBeanModel $model, ReportRules $rules, $reportType, $moduleClassName=null)
inferredRelationLinksToPrecedingRelation($inferredModelClassName, $relation, RedBeanModel $precedingModel=null, $precedingRelation=null)
const HAS_ONE
Definition: BeanModel.php:64
derivedRelationLinksToPrecedingRelation($relationModelClassName, $opposingRelation, RedBeanModel $precedingModel=null, $precedingRelation=null)
const HAS_ONE_BELONGS_TO
Definition: BeanModel.php:48
relationLinksToPrecedingRelation($relation, RedBeanModel $precedingModel=null, $precedingRelation=null)
static getApplicableRulesByModelClassNameAndAttributeName($modelClassName, $attributeName, $ruleAttributeName, $requiredRuleIsApplicable=false, $treatDateTimeAsDate=false, $readOnlyRuleIsApplicable=true)
const TYPE_SUMMATION
Definition: Report.php:57
static getAvailableOperatorsType($model, $attributeName)
const TYPE_MATRIX
Definition: Report.php:63
static subValueSort($array, $subKey, $sortFunctionName)
Definition: ArrayUtil.php:153
static canUserAccessModule($moduleClassName, $user)
Definition: RightsUtil.php:103
getSelectableRelationsData(RedBeanModel $precedingModel=null, $precedingRelation=null)
getDerivedRelationsViaCastedUpModelData(RedBeanModel $precedingModel=null, $precedingRelation=null)
static makeByModuleClassName($moduleClassName)
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
const HAS_MANY_BELONGS_TO
Definition: BeanModel.php:58
static relationLinksToPrecedingRelation($modelClassName, $relation, $precedingModelClassName=null, $precedingRelation=null)
static isRelation($attributeName)
Definition: BeanModel.php:220
static getType($model, $attributeName)
static getAllByModelClassName($modelClassName)
static make($moduleClassName, $modelClassName, $reportType)
Generated on Wed Jul 8 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.