All Data Structures Functions Variables Pages
ReportRelationsAndAttributesToTreeAdapter.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  {
45  protected $report;
46 
51  public function __construct(Report $report, $treeType)
52  {
53  assert('is_string($treeType)');
54  $this->report = $report;
55  $this->treeType = $treeType;
56  }
57 
62  public function getData($nodeId)
63  {
64  assert('is_string($nodeId)');
65  $nodeId = $this->resolveNodeIdByRemovingTreeType($nodeId);
66  $moduleClassName = $this->report->getModuleClassName();
67  $modelToReportAdapter = $this->makeModelRelationsAndAttributesToReportAdapter(
68  $moduleClassName, $moduleClassName::getPrimaryModelName());
69  $nodeIdPrefix = self::resolveNodeIdPrefixByNodeId($nodeId);
70  $precedingModel = null;
71  $precedingRelation = null;
72  if ($nodeId != 'source')
73  {
74  self::resolvePrecedingModelRelationAndAdapterByNodeId($nodeId, $modelToReportAdapter, $precedingModel,
75  $precedingRelation);
76  }
77  else
78  {
79  $nodeIdPrefix = null;
80  }
81  if ($nodeIdPrefix == null)
82  {
83  $data = array();
84  $data[0] = array('expanded' => true,
85  'text' => $moduleClassName::getModuleLabelByTypeAndLanguage('Singular'));
86  }
87  $childrenNodeData = $this->getChildrenNodeData($modelToReportAdapter, $precedingModel,
88  $precedingRelation, $nodeIdPrefix);
89  if (!empty($childrenNodeData) && $nodeIdPrefix == null)
90  {
91  $data[0]['children'] = $childrenNodeData;
92  }
93  else
94  {
95  $data = $childrenNodeData;
96  }
97  return $data;
98  }
99 
109  protected function getChildrenNodeData(ModelRelationsAndAttributesToReportAdapter $modelToReportAdapter,
110  RedBeanModel $precedingModel = null,
111  $precedingRelation = null, $nodeIdPrefix = null)
112  {
113  $childrenNodeData = array();
114  $attributesData = $this->getAttributesData($modelToReportAdapter, $precedingModel, $precedingRelation);
115  foreach ($attributesData as $attribute => $attributeData)
116  {
117  $attributeNode = array('id' => self::makeNodeId($attribute, $nodeIdPrefix),
118  'text' => $attributeData['label'],
119  'wrapperClass' => 'item-to-place',
120  );
121  $this->resolveChildNodeDataValueForAttributeNode($attributeNode, $attribute, $nodeIdPrefix);
122  $childrenNodeData[] = $attributeNode;
123  }
124  $selectableRelationsData = $modelToReportAdapter->
125  getSelectableRelationsData($precedingModel, $precedingRelation);
126  $resolvedSelectableRelationsData = $modelToReportAdapter->
127  getSelectableRelationsDataResolvedForUserAccess(
128  Yii::app()->user->userModel,
129  $selectableRelationsData);
130  foreach ($resolvedSelectableRelationsData as $relation => $relationData)
131  {
132  $relationModelClassName = $modelToReportAdapter->getRelationModelClassName($relation);
133  $relationModuleClassName = $relationModelClassName::getModuleClassName();
134  if ($relationModuleClassName == null)
135  {
136  throw new NotSupportedException($relationModelClassName);
137  }
138  $relationNode = array('id' => self::makeNodeId($relation, $nodeIdPrefix),
139  'text' => $relationData['label'],
140  'expanded' => false,
141  'hasChildren' => true);
142  $childrenNodeData[] = $relationNode;
143  }
144  return $childrenNodeData;
145  }
146 
153  protected function resolveChildNodeDataValueForAttributeNode(& $attributeNode, $attribute, $nodeIdPrefix)
154  {
155  }
156 
163  protected function getAttributesData(ModelRelationsAndAttributesToReportAdapter $modelToReportAdapter,
164  RedBeanModel $precedingModel = null, $precedingRelation = null)
165  {
166  if ($this->treeType == ComponentForReportForm::TYPE_FILTERS)
167  {
168  return $modelToReportAdapter->getAttributesForFilters();
169  }
170  elseif ($this->treeType == ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES)
171  {
172  return $modelToReportAdapter->getAttributesForDisplayAttributes($this->report->getGroupBys(),
173  $precedingModel, $precedingRelation);
174  }
175  elseif ($this->treeType == ComponentForReportForm::TYPE_ORDER_BYS)
176  {
177  return $modelToReportAdapter->getAttributesForOrderBys($this->report->getGroupBys(),
178  $this->report->getDisplayAttributes(),
179  $precedingModel, $precedingRelation);
180  }
181  elseif ($this->treeType == ComponentForReportForm::TYPE_GROUP_BYS)
182  {
183  return $modelToReportAdapter->getAttributesForGroupBys($precedingModel, $precedingRelation);
184  }
186  {
187  return $modelToReportAdapter->getForDrillDownAttributes($precedingModel, $precedingRelation);
188  }
189  else
190  {
191  throw new NotSupportedException();
192  }
193  }
194 
200  protected function makeModelRelationsAndAttributesToReportAdapter($moduleClassName, $modelClassName)
201  {
202  assert('is_string($moduleClassName)');
203  assert('is_string($modelClassName)');
204  return ModelRelationsAndAttributesToReportAdapter::make($moduleClassName, $modelClassName,
205  $this->report->getType());
206  }
207 
215  $nodeId, & $modelToReportAdapter, & $precedingModel, & $precedingRelation)
216  {
217  assert('$modelToReportAdapter instanceof ModelRelationsAndAttributesToReportAdapter');
218  if ($nodeId == 'source')
219  {
220  return;
221  }
222  $relations = explode(FormModelUtil::RELATION_DELIMITER, $nodeId);
223  $lastRelation = end($relations);
224  foreach ($relations as $relation)
225  {
226  $relationModelClassName = $modelToReportAdapter->getRelationModelClassName($relation);
227  $precedingRelation = $relation;
228  if ($relation != $lastRelation)
229  {
230  $precedingModel = new $relationModelClassName(false);
231  }
232  elseif (count($relations) == 1)
233  {
234  $precedingModel = $modelToReportAdapter->getModel();
235  }
236  $modelToReportAdapter = $this->makeModelRelationsAndAttributesToReportAdapter(
237  $relationModelClassName::getModuleClassName(), $relationModelClassName);
238  }
239  }
240  }
241 ?>
resolvePrecedingModelRelationAndAdapterByNodeId($nodeId, &$modelToReportAdapter, &$precedingModel, &$precedingRelation)
const RELATION_DELIMITER
getChildrenNodeData(ModelRelationsAndAttributesToReportAdapter $modelToReportAdapter, RedBeanModel $precedingModel=null, $precedingRelation=null, $nodeIdPrefix=null)
getAttributesData(ModelRelationsAndAttributesToReportAdapter $modelToReportAdapter, RedBeanModel $precedingModel=null, $precedingRelation=null)
makeModelRelationsAndAttributesToReportAdapter($moduleClassName, $modelClassName)
resolveChildNodeDataValueForAttributeNode(&$attributeNode, $attribute, $nodeIdPrefix)
static make($moduleClassName, $modelClassName, $reportType)
Generated on Tue May 26 2020 07:10:34