Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ReportResultsRowData.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 
44  class ReportResultsRowData extends CComponent
45  {
46  const ATTRIBUTE_NAME_PREFIX = 'attribute';
47 
48  const DRILL_DOWN_GROUP_BY_VALUE_PREFIX = 'groupByRowValue';
49 
53  protected $id;
54 
58  protected $displayAttributes;
59 
64  protected $modelsByAliases = array();
65 
69  protected $selectedColumnNamesAndValues = array();
70 
74  protected $selectedColumnNamesAndRowSpans = array();
75 
79  protected $selectedColumnNamesAndLabels = array();
80 
85  public static function resolveAttributeNameByKey($key)
86  {
87  assert('is_numeric($key) || is_string($key)');
88  return self::ATTRIBUTE_NAME_PREFIX . $key;
89  }
90 
91  public static function resolveKeyByAttributeName($attribute)
92  {
93  assert('is_string($attribute)');
94  $parts = explode(self::ATTRIBUTE_NAME_PREFIX, $attribute);
95  if (count($parts) == 2 && $parts[1] != null)
96  {
97  return $parts[1];
98  }
99  return null;
100  }
101 
102  public function getDisplayAttributes()
103  {
104  return $this->displayAttributes;
105  }
106 
111  public function __construct(array $displayAttributes, $id)
112  {
113  assert('is_int($id)');
114  $this->displayAttributes = $displayAttributes;
115  $this->id = $id;
116  }
117 
122  public function __isset($name)
123  {
124  if ($this->$name !== null)
125  {
126  return true;
127  }
128  return parent::__isset($name);
129  }
130 
135  public function __get($name)
136  {
137  $parts = explode(self::ATTRIBUTE_NAME_PREFIX, $name);
138  if (count($parts) == 2 && $parts[1] != null)
139  {
140  return $this->resolveValueFromModel($parts[1]);
141  }
142  //Not using isset, because a null value would not resolve correctly
143  if (array_key_exists($name, $this->selectedColumnNamesAndValues))
144  {
145  return $this->selectedColumnNamesAndValues[$name];
146  }
147  return parent::__get($name);
148  }
149 
155  public function addModelAndAlias(RedBeanModel $model, $alias)
156  {
157  assert('is_string($alias)');
158  if (isset($this->modelsByAliases[$alias]))
159  {
160  throw new NotSupportedException();
161  }
162  $this->modelsByAliases[$alias] = $model;
163  }
164 
169  public function addSelectedColumnNameAndValue($columnName, $value)
170  {
171  $this->selectedColumnNamesAndValues[$columnName] = $value;
172  }
173 
178  public function addSelectedColumnNameAndLabel($columnName, $label)
179  {
180  assert('is_string($label)');
181  $this->selectedColumnNamesAndLabels[$columnName] = $label;
182  }
183 
188  public function getLabel($columnName)
189  {
190  assert('is_string($columnName)');
191  return $this->selectedColumnNamesAndLabels[$columnName];
192  }
193 
198  public function addSelectedColumnNameAndRowSpan($columnName, $value)
199  {
200  assert('is_int($value)');
201  $this->selectedColumnNamesAndRowSpans[$columnName] = $value;
202  }
203 
208  public function getSelectedColumnRowSpan($columnName)
209  {
210  assert('is_string($columnName)');
211  return $this->selectedColumnNamesAndRowSpans[$columnName];
212  }
213 
220  public function getModel($attribute)
221  {
222  assert('is_string($attribute)');
223  list($notUsed, $displayAttributeKey) = explode(self::ATTRIBUTE_NAME_PREFIX, $attribute);
224  if ($displayAttributeKey != null)
225  {
226  return $this->resolveModel($displayAttributeKey);
227  }
228  throw new NotSupportedException();
229  }
230 
237  public function getAttributeLabel($attribute)
238  {
239  assert('is_string($attribute)');
240  $parts = explode(self::ATTRIBUTE_NAME_PREFIX, $attribute);
241  if (count($parts) == 2 && $parts[1] != null)
242  {
243  list($notUsed, $displayAttributeKey) = explode(self::ATTRIBUTE_NAME_PREFIX, $attribute);
244  if ($displayAttributeKey != null && isset($this->displayAttributes[$displayAttributeKey]))
245  {
246  return $this->displayAttributes[$displayAttributeKey]->getDisplayLabel();
247  }
248  else
249  {
250  throw new NotSupportedException();
251  }
252  }
253  $parts = explode(DisplayAttributeForReportForm::COLUMN_ALIAS_PREFIX, $attribute);
254  if (count($parts) == 2 && $parts[1] != null)
255  {
256  list($notUsed, $displayAttributeKey) = explode(DisplayAttributeForReportForm::COLUMN_ALIAS_PREFIX, $attribute);
257  if ($displayAttributeKey != null && isset($this->displayAttributes[$displayAttributeKey]))
258  {
259  return $this->displayAttributes[$displayAttributeKey]->getDisplayLabel();
260  }
261  else
262  {
263  throw new NotSupportedException();
264  }
265  }
266  }
267 
271  public function getId()
272  {
273  return $this->id;
274  }
275 
280  {
281  $dataParams = array();
282  foreach ($this->displayAttributes as $key => $displayAttribute)
283  {
284  if ($displayAttribute->valueUsedAsDrillDownFilter)
285  {
286  $attributeAlias = $displayAttribute->resolveAttributeNameForGridViewColumn($key);
287  if ($this->shouldResolveValueFromModel($attributeAlias))
288  {
289  list($notUsed, $displayAttributeKey) = explode(self::ATTRIBUTE_NAME_PREFIX, $attributeAlias);
290  $model = $this->resolveModel($displayAttributeKey);
291  if ($model == null)
292  {
293  $value = null;
294  }
295  else
296  {
297  $value = $this->resolveRawValueByModel($displayAttribute, $model);
298  }
299  }
300  else
301  {
302  $value = $this->selectedColumnNamesAndValues[$attributeAlias];
303  }
304  if ($value !== null)
305  {
306  $dataParams[self::resolveDataParamKeyForDrillDown($displayAttribute->attributeIndexOrDerivedType)] = $value;
307  }
308  }
309  }
310  return $dataParams;
311  }
312 
317  public static function resolveDataParamKeyForDrillDown($attributeIndexOrDerivedType)
318  {
319  return self::DRILL_DOWN_GROUP_BY_VALUE_PREFIX . $attributeIndexOrDerivedType;
320  }
321 
326  public function resolveRawValueByDisplayAttributeKey($displayAttributeKey)
327  {
328  assert('is_int($displayAttributeKey)');
329  if (null != $model = $this->resolveModel($displayAttributeKey))
330  {
331  return $this->resolveRawValueByModel($this->displayAttributes[$displayAttributeKey], $model);
332  }
333  //Not using isset, because a null value would not resolve correctly
334  $columnAliasName = $this->displayAttributes[$displayAttributeKey]->columnAliasName;
335  if (array_key_exists($columnAliasName, $this->selectedColumnNamesAndValues))
336  {
337  return $this->selectedColumnNamesAndValues[$columnAliasName];
338  }
339  throw new NotSupportedException();
340  }
341 
346  protected function shouldResolveValueFromModel($attributeAlias)
347  {
348  $parts = explode(self::ATTRIBUTE_NAME_PREFIX, $attributeAlias);
349  if (count($parts) == 2 && $parts[1] != null)
350  {
351  return true;
352  }
353  return false;
354  }
355 
361  protected function resolveModel($displayAttributeKey)
362  {
363  if (!isset($this->displayAttributes[$displayAttributeKey]))
364  {
365  throw new NotSupportedException();
366  }
367  $displayAttribute = $this->displayAttributes[$displayAttributeKey];
368  $modelAlias = $displayAttribute->getModelAliasUsingTableAliasName();
369  if (!isset($this->modelsByAliases[$modelAlias]))
370  {
371  return null;
372  }
373  return $this->getModelByAlias($modelAlias);
374  }
375 
381  protected function resolveValueFromModel($displayAttributeKey)
382  {
383  if (!isset($this->displayAttributes[$displayAttributeKey]))
384  {
385  throw new NotSupportedException();
386  }
387  $displayAttribute = $this->displayAttributes[$displayAttributeKey];
388  $modelAlias = $displayAttribute->getModelAliasUsingTableAliasName();
389  $attribute = $displayAttribute->getResolvedAttributeRealAttributeName();
390  if (!isset($this->modelsByAliases[$modelAlias]))
391  {
392  $defaultModelClassName = $displayAttribute->getResolvedAttributeModelClassName();
393  $model = new $defaultModelClassName(false);
394  }
395  else
396  {
397  $model = $this->getModelByAlias($modelAlias);
398  }
399  return $this->resolveModelAttributeValueForPenultimateRelation($model, $attribute, $displayAttribute);
400  }
401 
412  protected function resolveModelAttributeValueForPenultimateRelation(RedBeanModel $model, $attribute,
413  DisplayAttributeForReportForm $displayAttribute)
414  {
415  if (($attribute == 'UniqueIdentifier' &&
416  !is_subclass_of($displayAttribute->getResolvedAttributeModelClassName(), 'OwnedModel')))
417  {
418  return $model->id;
419  }
420  if ($model->isAttribute($attribute) &&
421  !is_subclass_of($displayAttribute->getResolvedAttributeModelClassName(), 'OwnedModel'))
422  {
423  return $model->$attribute;
424  }
425  $penultimateRelation = $displayAttribute->getPenultimateRelation();
426  if (!$model->isAttribute($penultimateRelation))
427  {
428  //Fallback. For some reason this could in fact reference the original $model attribute, but because it is
429  //not owned, it gets confused. todo: need to investigate this further because this is not proper.
430  if ($model->isAttribute($attribute))
431  {
432  return $model->$attribute;
433  }
434  throw new NotSupportedException();
435  }
436  return $model->$penultimateRelation->$attribute;
437  }
438 
444  protected function resolveRawValueByModel(DisplayAttributeForReportForm $displayAttribute, RedBeanModel $model)
445  {
446  $type = $displayAttribute->getDisplayElementType();
447  $attribute = $displayAttribute->getResolvedAttribute();
448  if ($type == 'CurrencyValue')
449  {
450  return $model->{$attribute}->value;
451  }
452  elseif ($type == 'User')
453  {
454  $realAttributeName = $displayAttribute->getResolvedAttributeRealAttributeName();
455  return $model->{$realAttributeName}->id;
456  }
457  elseif ($type == 'DropDown')
458  {
459  return $model->{$attribute}->value;
460  }
461  elseif (null != $rawValueRelatedAttribute = $displayAttribute->getRawValueRelatedAttribute())
462  {
463  return $model->{$attribute}->{$rawValueRelatedAttribute};
464  }
465  else
466  {
467  return $this->resolveModelAttributeValueForPenultimateRelation($model, $attribute, $displayAttribute);
468  }
469  }
470 
476  protected function getModelByAlias($alias)
477  {
478  if (!isset($this->modelsByAliases[$alias]))
479  {
480  throw new NotSupportedException();
481  }
482  return $this->modelsByAliases[$alias];
483  }
484  }
485 ?>
static resolveDataParamKeyForDrillDown($attributeIndexOrDerivedType)
resolveModel($displayAttributeKey)
static resolveAttributeNameByKey($key)
addSelectedColumnNameAndLabel($columnName, $label)
resolveRawValueByModel(DisplayAttributeForReportForm $displayAttribute, RedBeanModel $model)
isAttribute($attributeName)
shouldResolveValueFromModel($attributeAlias)
addSelectedColumnNameAndValue($columnName, $value)
resolveModelAttributeValueForPenultimateRelation(RedBeanModel $model, $attribute, DisplayAttributeForReportForm $displayAttribute)
getSelectedColumnRowSpan($columnName)
addModelAndAlias(RedBeanModel $model, $alias)
resolveRawValueByDisplayAttributeKey($displayAttributeKey)
__construct(array $displayAttributes, $id)
resolveValueFromModel($displayAttributeKey)
addSelectedColumnNameAndRowSpan($columnName, $value)
Generated on Thu Jul 2 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.