Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ListView.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 ListView extends ModelView implements ListViewInterface
41  {
42  protected $controllerId;
43 
44  protected $moduleId;
45 
46  protected $dataProvider;
47 
52  protected $renderViewToolBarDuringRenderContent = true;
53 
58  protected $rowsAreSelectable = false;
59 
65  protected $gridId;
66 
71  protected $gridIdSuffix;
72 
76  protected $selectedIds;
77 
81  protected $gridViewPagerParams = array();
82 
83  private $resolvedMetadata;
84 
85  protected $emptyText = null;
86 
87  private $listAttributesSelector;
88 
89  private $kanbanBoard;
90 
95  public function __construct(
96  $controllerId,
97  $moduleId,
98  $modelClassName,
99  $dataProvider,
100  $selectedIds,
101  $gridIdSuffix = null,
102  $gridViewPagerParams = array(),
103  $listAttributesSelector = null,
104  $kanbanBoard = null
105  )
106  {
107  assert('is_array($selectedIds)');
108  assert('is_string($modelClassName)');
109  assert('is_array($this->gridViewPagerParams)');
110  assert('$listAttributesSelector == null || $listAttributesSelector instanceof ListAttributesSelector');
111  assert('$kanbanBoard === null || $kanbanBoard instanceof $kanbanBoard');
112  $this->controllerId = $controllerId;
113  $this->moduleId = $moduleId;
114  $this->modelClassName = $modelClassName;
115  $this->dataProvider = $dataProvider;
116  $this->rowsAreSelectable = true;
117  $this->selectedIds = $selectedIds;
118  $this->gridIdSuffix = $gridIdSuffix;
119  $this->gridViewPagerParams = $gridViewPagerParams;
120  $this->gridId = 'list-view';
121  $this->listAttributesSelector = $listAttributesSelector;
122  $this->kanbanBoard = $kanbanBoard;
123  }
124 
125  protected function getKanbanBoard()
126  {
127  return $this->kanbanBoard;
128  }
129 
130  protected function setKanbanBoard($kanbanBoard)
131  {
132  assert('$kanbanBoard === null || $kanbanBoard instanceof $kanbanBoard');
133  $this->kanbanBoard = $kanbanBoard;
134  }
135 
142  protected function renderContent()
143  {
144  $cClipWidget = new CClipWidget();
145  $cClipWidget->beginClip("ListView");
146  $cClipWidget->widget($this->getGridViewWidgetPath(), $this->getCGridViewParams());
147  $cClipWidget->endClip();
148  $content = null;
149  if ($this->renderViewToolBarDuringRenderContent)
150  {
151  $content .= $this->renderViewToolBar();
152  }
153  $content .= $cClipWidget->getController()->clips['ListView'] . "\n";
154  if ($this->getRowsAreSelectable())
155  {
156  $content .= ZurmoHtml::hiddenField($this->gridId . $this->gridIdSuffix . '-selectedIds', implode(",", $this->selectedIds)) . "\n"; // Not Coding Standard
157  }
158  $this->renderScripts();
159  return $content;
160  }
161 
162  protected function getGridViewWidgetPath()
163  {
164  if (Yii::app()->userInterface->isMobile())
165  {
166  $widget = 'application.core.widgets.StackedExtendedGridView';
167  }
168  elseif ($this->kanbanBoard === null || !$this->kanbanBoard->getIsActive())
169  {
170  $widget = 'application.core.widgets.ExtendedGridView';
171  }
172  elseif ($this->kanbanBoard->getIsActive())
173  {
174  $widget = $this->kanbanBoard->getGridViewWidgetPath();
175  }
176  else
177  {
178  throw new NotSupportedException();
179  }
180  return $widget;
181  }
182 
187  public function getRowsAreSelectable()
188  {
189  if ($this->kanbanBoard != null && $this->kanbanBoard->getIsActive())
190  {
191  return false;
192  }
194  }
195 
196  public function setRowsAreSelectable($value)
197  {
198  $this->rowsAreSelectable = (boolean)$value;
199  }
200 
201  protected function getCGridViewParams()
202  {
203  $columns = $this->getCGridViewColumns();
204  assert('is_array($columns)');
205  $params = array(
206  'id' => $this->getGridViewId(),
207  'htmlOptions' => array(
208  'class' => 'cgrid-view ' . $this->getTypeCssClassForCGridView() . $this->getKanbanCssClassForCGridView()
209  ),
210  'loadingCssClass' => 'loading',
211  'dataProvider' => $this->getDataProvider(),
212  'selectableRows' => $this->getCGridViewSelectableRowsCount(),
213  'pager' => $this->getCGridViewPagerParams(),
214  'beforeAjaxUpdate' => $this->getCGridViewBeforeAjaxUpdate(),
215  'afterAjaxUpdate' => $this->getCGridViewAfterAjaxUpdate(),
216  'ajaxUrl' => $this->getCGridViewAjaxUrl(),
217  'columns' => $columns,
218  'nullDisplay' => '&#160;',
219  'pagerCssClass' => static::getPagerCssClass(),
220  'showTableOnEmpty' => $this->getShowTableOnEmpty(),
221  'emptyText' => $this->getEmptyText(),
222  'template' => static::getGridTemplate(),
223  'summaryText' => static::getSummaryText(),
224  'summaryCssClass' => static::getSummaryCssClass(),
225  'summaryCloneId' => $this->getSummaryCloneId(),
226  'tableColumnGroup' => $this->getTableColumnGroup(),
227  'hideHeader' => $this->isHeaderHidden()
228  );
229  return $this->resolveCGridViewParamsForKanbanBoard($params);
230  }
231 
232  protected function getTypeCssClassForCGridView()
233  {
234  return 'type-' . $this->moduleId;
235  }
236 
237  protected function getKanbanCssClassForCGridView()
238  {
239  if ($this->kanbanBoard != null && $this->kanbanBoard->getIsActive())
240  {
241  return ' type-kanban-' . $this->moduleId;
242  }
243  else
244  {
245  return '';
246  }
247  }
248 
249  protected static function getGridTemplate()
250  {
251  $preloader = '<div class="list-preloader"><span class="z-spinner"></span></div>';
252  $items = '<div class="items-wrapper">{items}{pager}</div>';
253  return "{summary}" . $items . $preloader;
254  }
255 
256  protected static function getPagerCssClass()
257  {
258  return 'pager vertical';
259  }
260 
261  protected static function getSummaryText()
262  {
263  return Zurmo::t('Core', '{count} result(s)');
264  }
265 
266  protected static function getSummaryCssClass()
267  {
268  return 'summary';
269  }
270 
271  public function getSummaryCloneId()
272  {
273  return $this->getGridViewId() . "-summary-clone";
274  }
275 
276  public function getTableColumnGroup()
277  {
278  return array();
279  }
280 
281  protected function getCGridViewPagerParams()
282  {
283  $defaultGridViewPagerParams = array(
284  'prevPageLabel' => '<span>previous</span>',
285  'nextPageLabel' => '<span>next</span>',
286  'class' => 'EndlessListLinkPager',
287  'paginationParams' => GetUtil::getData(),
288  'route' => $this->getGridViewActionRoute($this->getListActionId(), $this->moduleId),
289  );
290  if (empty($this->gridViewPagerParams))
291  {
292  return $defaultGridViewPagerParams;
293  }
294  else
295  {
296  return array_merge($defaultGridViewPagerParams, $this->gridViewPagerParams);
297  }
298  }
299 
300  protected function getShowTableOnEmpty()
301  {
302  return true;
303  }
304 
305  protected function getEmptyText()
306  {
307  return $this->emptyText;
308  }
309 
310  public function setEmptyText($text)
311  {
312  $this->emptyText = $text;
313  }
314 
315  public function getGridViewId()
316  {
317  return $this->gridId . $this->gridIdSuffix;
318  }
319 
320  protected function getCGridViewFirstColumn()
321  {
322  $checked = 'in_array($data->id, array(' . implode(',', $this->selectedIds) . '))'; // Not Coding Standard
323  $checkBoxHtmlOptions = array();
324  $firstColumn = array(
325  'class' => 'CheckBoxColumn',
326  'checked' => $checked,
327  'id' => $this->gridId . $this->gridIdSuffix . '-rowSelector', // Always specify this as -rowSelector.
328  'checkBoxHtmlOptions' => $checkBoxHtmlOptions,
329  );
330  return $firstColumn;
331  }
332 
337  protected function getCGridViewColumns()
338  {
339  $columns = array();
340  if ($this->getRowsAreSelectable())
341  {
342  $firstColumn = $this->getCGridViewFirstColumn();
343  array_push($columns, $firstColumn);
344  }
345 
346  $metadata = $this->getResolvedMetadata();
347  foreach ($metadata['global']['panels'] as $panel)
348  {
349  foreach ($panel['rows'] as $row)
350  {
351  foreach ($row['cells'] as $cell)
352  {
353  foreach ($cell['elements'] as $columnInformation)
354  {
355  $column = $this->processColumnInfoToFetchColumnData($columnInformation);
356  array_push($columns, $column);
357  }
358  }
359  }
360  }
361  $menuColumn = $this->getGridViewMenuColumn();
362  if ($menuColumn == null)
363  {
364  $lastColumn = $this->getCGridViewLastColumn();
365  if (!empty($lastColumn))
366  {
367  array_push($columns, $lastColumn);
368  }
369  }
370  else
371  {
372  array_push($columns, $menuColumn);
373  }
374  return $columns;
375  }
376 
377  protected function resolveMetadata()
378  {
379  if ($this->listAttributesSelector != null)
380  {
381  return $this->listAttributesSelector->getResolvedMetadata();
382  }
383  return self::getMetadata();
384  }
385 
386  protected function getResolvedMetadata()
387  {
388  if ($this->resolvedMetadata != null)
389  {
390  return $this->resolvedMetadata;
391  }
392  $this->resolvedMetadata = $this->resolveMetadata();
393  return $this->resolvedMetadata;
394  }
395 
396  protected function getCGridViewBeforeAjaxUpdate()
397  {
398  if ($this->getRowsAreSelectable())
399  {
400  return 'js:function(id, options) { $(this).makeSmallLoadingSpinner(true, "#" + id); addListViewSelectedIdsToUrl(id, options); }';
401  }
402  else
403  {
404  return 'js:function(id, options) { $(this).makeSmallLoadingSpinner(true, "#" + id); }';
405  }
406  }
407 
408  protected function getCGridViewAfterAjaxUpdate()
409  {
410  // Begin Not Coding Standard
411  return 'js:function(id, data) {
412  processAjaxSuccessError(id, data);
413  var $data = $(data);
414  jQuery.globalEval($data.filter("script").last().text());
415  }';
416  // End Not Coding Standard
417  }
418 
419  protected function getCGridViewAjaxUrl()
420  {
421  return null;
422  }
423 
450  public static function getDefaultMetadata()
451  {
452  return array();
453  }
454 
462  public static function canRenderRowMenuColumnByElementAndData($element, $data)
463  {
464  return true;
465  }
466 
467  protected function getCGridViewSelectableRowsCount()
468  {
469  if ($this->getRowsAreSelectable())
470  {
471  return 2;
472  }
473  else
474  {
475  return 0;
476  }
477  }
478 
479  protected function getCGridViewLastColumn()
480  {
481  $url = 'Yii::app()->createUrl("' . $this->getGridViewActionRoute('edit');
482  $url .= '", array("id" => $data->id))';
483  return array(
484  'class' => 'ButtonColumn',
485  'template' => '{update}',
486  'buttons' => array(
487  'update' => array(
488  'url' => $url,
489  'imageUrl' => false,
490  'options' => array('class' => 'pencil', 'title' => 'Update'),
491  'label' => '!'
492  ),
493  ),
494  );
495  }
496 
497  protected function getGridViewMenuColumn()
498  {
499  $metadata = $this::getMetadata();
500  $content = null;
501  if (isset($metadata['global']['rowMenu']) && is_array($metadata['global']['rowMenu']['elements']))
502  {
503  return array(
504  'class' => $this->resolveRowMenuColumnClass(),
505  'rowMenu' => $metadata['global']['rowMenu'],
506  'listView' => $this,
507  'redirectUrl' => ArrayUtil::getArrayValue($this->params, 'redirectUrl'),
508  'modelClassName' => $this->modelClassName
509  );
510  }
511  return $content;
512  }
513 
514  protected function getGridViewActionRoute($action, $moduleId = null)
515  {
516  if ($moduleId == null)
517  {
518  $moduleId = $this->moduleId;
519  }
520  return '/' . $moduleId . '/' . $this->controllerId . '/' . $action;
521  }
522 
523  protected function getListActionId()
524  {
525  return 'list';
526  }
527 
528  public function getLinkString($attributeString, $attribute)
529  {
530  $string = 'ZurmoHtml::link(';
531  $string .= $attributeString . ', ';
532  $string .= 'Yii::app()->createUrl("' .
533  $this->getGridViewActionRoute('details') . '", array("id" => $data->id))';
534  $string .= ')';
535  return $string;
536  }
537 
538  public function getRelatedLinkString($attributeString, $attributeName, $moduleId)
539  {
540  $string = 'ListView::resolveRelatedListStringContent($data->' . $attributeName . '->id, ZurmoHtml::link(';
541  $string .= $attributeString . ', ';
542  $string .= 'Yii::app()->createUrl("' .
543  $this->getGridViewActionRoute('details', $moduleId) . '",
544  array("id" => $data->' . $attributeName . '->id))';
545  $string .= '))';
546  return $string;
547  }
548 
549  public static function resolveRelatedListStringContent($modelId, $linkStringContent)
550  {
551  if ($modelId > 0)
552  {
553  return $linkStringContent;
554  }
555  }
556 
557  public static function getDesignerRulesType()
558  {
559  return 'ListView';
560  }
561 
565  protected function getActionModuleClassName()
566  {
567  return get_class(Yii::app()->getModule($this->moduleId));
568  }
569 
570  protected function getDataProvider()
571  {
572  return $this->dataProvider;
573  }
574 
575  protected function renderScripts()
576  {
577  Yii::app()->clientScript->registerScriptFile(
578  Yii::app()->getAssetManager()->publish(
579  Yii::getPathOfAlias('application.core.views.assets')) . '/ListViewUtils.js');
580  }
581 
582  public function getModuleId()
583  {
584  return $this->moduleId;
585  }
586 
587  public function getControllerId()
588  {
589  return $this->controllerId;
590  }
591 
592  private function resolveCGridViewParamsForKanbanBoard(array $params)
593  {
594  if (Yii::app()->userInterface->isMobile() || $this->kanbanBoard === null || !$this->kanbanBoard->getIsActive())
595  {
596  return $params;
597  }
598  $params = array_merge($params, $this->kanbanBoard->getGridViewParams());
599  return array_merge($params, $this->resolveExtraParamsForKanbanBoard());
600  }
601 
605  protected function processColumnInfoToFetchColumnData($columnInformation)
606  {
607  $columnClassName = ucfirst($columnInformation['type']) . 'ListViewColumnAdapter';
608  $columnAdapter = new $columnClassName($columnInformation['attributeName'], $this, array_slice($columnInformation, 1));
609  $column = $columnAdapter->renderGridViewData();
610  if (!isset($column['class']))
611  {
612  $column['class'] = 'DataColumn';
613  }
614  return $column;
615  }
616 
621  protected function isHeaderHidden()
622  {
623  return false;
624  }
625 
630  protected function resolveRowMenuColumnClass()
631  {
632  return 'RowMenuColumn';
633  }
634  }
635 ?>
resolveRowMenuColumnClass()
Definition: ListView.php:630
renderContent()
Definition: ListView.php:142
$gridViewPagerParams
Definition: ListView.php:81
static getDefaultMetadata()
Definition: ListView.php:450
$selectedIds
Definition: ListView.php:76
$rowsAreSelectable
Definition: ListView.php:58
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
getCGridViewColumns()
Definition: ListView.php:337
$gridIdSuffix
Definition: ListView.php:71
__construct($controllerId, $moduleId, $modelClassName, $dataProvider, $selectedIds, $gridIdSuffix=null, $gridViewPagerParams=array(), $listAttributesSelector=null, $kanbanBoard=null)
Definition: ListView.php:95
processColumnInfoToFetchColumnData($columnInformation)
Definition: ListView.php:605
renderViewToolBar($renderInForm=true)
getActionModuleClassName()
Definition: ListView.php:565
getRowsAreSelectable()
Definition: ListView.php:187
static canRenderRowMenuColumnByElementAndData($element, $data)
Definition: ListView.php:462
isHeaderHidden()
Definition: ListView.php:621
Generated on Wed Dec 2 2020 07:10:24
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.