Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DetailsView.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 
40  abstract class DetailsView extends ModelView
41  {
42  protected $controllerId;
43 
44  protected $moduleId;
45 
46  protected $model;
47 
48  protected $title;
49 
54  public function __construct($controllerId, $moduleId, $model, $title = null)
55  {
56  assert('$title == null || is_string($title)');
57  $this->assertModelIsValid($model);
58  $this->controllerId = $controllerId;
59  $this->moduleId = $moduleId;
60  $this->model = $model;
61  $this->modelClassName = get_class($model);
62  $this->modelId = $model->id;
63  $this->title = $title;
64  }
65 
66  public static function assertModelIsValid($model)
67  {
68  assert('$model instanceof RedBeanModel || $model instanceof CFormModel || $model instanceof ModelForm');
69  }
70 
76  protected function renderContent()
77  {
78  $content = '<div class="details-table">';
79  $content .= $this->renderTitleContent();
80  $content .= $this->resolveAndRenderActionElementMenu();
81  $leftContent = $this->renderBeforeFormLayoutForDetailsContent();
82  $leftContent .= $this->renderFormLayout();
83  $leftContent .= $this->renderAfterFormLayoutForDetailsContent();
84  $leftContent = $this->resolveLeftContentForSlidingPanels($leftContent);
85  $content .= ZurmoHtml::tag('div', array('class' => 'left-column full-width'), $leftContent);
86  $content .= $this->renderRightSideContent();
87  $content .= $this->renderAfterRightSideContent();
88  $content .= '</div>';
89  $content .= $this->renderAfterDetailsTable();
90  return $content;
91  }
92 
98  protected function resolveLeftContentForSlidingPanels($content)
99  {
100  return $content;
101  }
102 
103  protected function resolveAndRenderActionElementMenu()
104  {
105  return $this->renderWrapperAndActionElementMenu();
106  }
107 
108  protected function renderRightSideContent($form = null)
109  {
110  }
111 
112  protected function renderBeforeFormLayoutForDetailsContent()
113  {
114  }
115 
116  protected function renderAfterFormLayoutForDetailsContent()
117  {
118  }
119 
120  protected function renderAfterRightSideContent()
121  {
122  }
123 
124  protected function renderAfterDetailsTable()
125  {
126  }
127 
134  protected function renderFormLayout($form = null)
135  {
136  assert('$form == null || $form instanceof ZurmoActiveForm');
137  $maxCellsPerRow = $this->getMaxCellsPerRow();
138  $metadata = $this->getFormLayoutMetadata();
139  $metadataWithRenderedElements = $this->resolveMetadataWithRenderedElements($metadata, $maxCellsPerRow, $form);
140  $this->afterResolveMetadataWithRenderedElements($metadataWithRenderedElements, $form);
141  if ($form != null)
142  {
143  $errorSummaryContent = $form->errorSummary($this->getModel());
144  }
145  else
146  {
147  $errorSummaryContent = null;
148  }
149  $formLayoutClassName = static::getDetailsViewFormLayoutClass();
150  $formLayout = new $formLayoutClassName($metadataWithRenderedElements, $maxCellsPerRow,
151  $errorSummaryContent, $this->getFormLayoutUniqueId());
152  $formLayout->alwaysShowErrorSummary = $this->alwaysShowErrorSummary();
153  $formLayout->labelsHaveOwnCells($this->doesLabelHaveOwnCell());
154  $formLayout->setMorePanelsLinkLabel($this->getMorePanelsLinkLabel());
155  $formLayout->setLessPanelsLinkLabel($this->getLessPanelsLinkLabel());
156  return $formLayout->render();
157  }
158 
166  protected function resolveMetadataWithRenderedElements($metadata, $maxCellsPerRow, $form)
167  {
168  assert('is_array($metadata)');
169  assert('is_int($maxCellsPerRow)');
170  assert('$form == null || $form instanceof ZurmoActiveForm');
171  $maximumColumnCount = DetailsViewFormLayout::getMaximumColumnCountForAllPanels($metadata);
172  foreach ($metadata['global']['panels'] as $panelNumber => $panel)
173  {
174  if ($this->shouldDisplayPanel(ArrayUtil::getArrayValue($panel, 'detailViewOnly')))
175  {
176  foreach ($panel['rows'] as $rowIndex => $row)
177  {
178  foreach ($row['cells'] as $cellIndex => $cell)
179  {
180  if (is_array($cell['elements']) && $this->shouldDisplayCell(ArrayUtil::getArrayValue($cell, 'detailViewOnly')))
181  {
182  foreach ($cell['elements'] as $elementIndex => $elementInformation)
183  {
184  if (count($row['cells']) == 1 && count($row['cells']) < $maxCellsPerRow &&
185  count($row['cells']) < $maximumColumnCount)
186  {
187  $elementInformation['wide'] = true;
188  }
189  $this->resolveElementInformationDuringFormLayoutRender($elementInformation);
190  Yii::app()->custom->resolveElementInformationDuringFormLayoutRender($this, $elementInformation);
191  $elementclassname = $elementInformation['type'] . 'Element';
192  $element = new $elementclassname($this->getModel(), $elementInformation['attributeName'],
193  $form, array_slice($elementInformation, 2));
194  $this->resolveElementDuringFormLayoutRender($element);
195  $metadata['global']['panels'][$panelNumber]['rows']
196  [$rowIndex]['cells'][$cellIndex]['elements'][$elementIndex] = $element->render();
197  }
198  }
199  else
200  {
201  foreach ($cell['elements'] as $elementIndex => $elementInformation)
202  {
203  $metadata['global']['panels'][$panelNumber]['rows']
204  [$rowIndex]['cells'][$cellIndex]['elements'][$elementIndex] = null;
205  }
206  }
207  }
208  }
209  }
210  else
211  {
212  unset($metadata['global']['panels'][$panelNumber]);
213  }
214  }
215  return $metadata;
216  }
217 
222  protected function resolveMaxCellsPresentInAnyRow($metadata)
223  {
224  assert('is_array($metadata)');
225  $maxCellsPresent = 1;
226  if (!isset($metadata['global']['panels']))
227  {
228  return $maxCellsPresent;
229  }
230  foreach ($metadata['global']['panels'] as $panelNumber => $panel)
231  {
232  foreach ($panel['rows'] as $rowIndex => $row)
233  {
234  $maxCellsPresentInThisRow = 0;
235  foreach ($row['cells'] as $cellIndex => $cell)
236  {
237  $maxCellsPresentInThisRow++;
238  }
239  if ($maxCellsPresentInThisRow > $maxCellsPresent)
240  {
241  $maxCellsPresent = $maxCellsPresentInThisRow;
242  }
243  }
244  }
245  return $maxCellsPresent;
246  }
247 
252  protected function doesLabelHaveOwnCell()
253  {
254  return true;
255  }
256 
261  protected function afterResolveMetadataWithRenderedElements(& $metadataWithRenderedElements, $form)
262  {
263  }
264 
265  protected function getMaxCellsPerRow()
266  {
267  $designerRulesType = static::getDesignerRulesType();
268  if ($designerRulesType == null)
269  {
270  $designerRulesType = self::getDesignerRulesType();
271  }
272  $designerRulesClassName = $designerRulesType . 'DesignerRules';
273  $designerRules = new $designerRulesClassName();
274  return $designerRules->maxCellsPerRow();
275  }
276 
333  public static function getDefaultMetadata()
334  {
335  return array();
336  }
337 
341  protected function getModel()
342  {
343  return $this->model;
344  }
345 
346  protected function shouldDisplayCell($detailViewOnly)
347  {
348  return true;
349  }
350 
351  protected function shouldDisplayPanel($detailViewOnly)
352  {
353  return true;
354  }
355 
356  public static function getDesignerRulesType()
357  {
358  return 'DetailsView';
359  }
360 
365  protected function resolveElementInformationDuringFormLayoutRender(& $elementInformation)
366  {
367  }
368 
372  protected function resolveElementDuringFormLayoutRender(& $element)
373  {
374  }
375 
383  protected function getFormLayoutMetadata()
384  {
385  return self::getMetadata();
386  }
387 
388  protected static function assertMetadataIsValid(array $metadata)
389  {
390  parent::assertMetadataIsValid($metadata);
391  $attributeNames = array();
392  $derivedTypes = array();
393  assert('!isset($metadata["global"]["panelsDisplayType"]) || is_int($metadata["global"]["panelsDisplayType"])');
394  }
395 
400  protected function getMorePanelsLinkLabel()
401  {
402  return Zurmo::t('Core', 'More Details');
403  }
404 
409  protected function getLessPanelsLinkLabel()
410  {
411  return Zurmo::t('Core', 'Fewer Details');
412  }
413 
414  public function getTitle()
415  {
416  return $this->title;
417  }
418 
419  protected function alwaysShowErrorSummary()
420  {
421  return false;
422  }
423 
428  protected function getFormLayoutUniqueId()
429  {
430  return null;
431  }
432 
437  protected function getDetailsViewFormLayoutClass()
438  {
439  return 'DetailsViewFormLayout';
440  }
441  }
442 ?>
getLessPanelsLinkLabel()
__construct($controllerId, $moduleId, $model, $title=null)
Definition: DetailsView.php:54
getDetailsViewFormLayoutClass()
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
getFormLayoutUniqueId()
static getDefaultMetadata()
renderFormLayout($form=null)
getMorePanelsLinkLabel()
resolveLeftContentForSlidingPanels($content)
Definition: DetailsView.php:98
resolveElementDuringFormLayoutRender(&$element)
static getMaximumColumnCountForAllPanels($metadata)
Definition: FormLayout.php:126
resolveElementInformationDuringFormLayoutRender(&$elementInformation)
afterResolveMetadataWithRenderedElements(&$metadataWithRenderedElements, $form)
doesLabelHaveOwnCell()
getFormLayoutMetadata()
resolveMetadataWithRenderedElements($metadata, $maxCellsPerRow, $form)
resolveMaxCellsPresentInAnyRow($metadata)
Generated on Sat Jul 4 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.