Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ReportResultsGridView.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 ReportResultsGridView extends View implements ListViewInterface
41  {
45  protected $controllerId;
46 
50  protected $moduleId;
51 
55  protected $dataProvider;
56 
60  protected $rowsAreExpandable = false;
61 
67  protected $gridId;
68 
73  protected $gridIdSuffix;
74 
78  protected $gridViewPagerParams = array();
79 
83  protected $emptyText = null;
84 
92  public function __construct(
93  $controllerId,
94  $moduleId,
95  ReportDataProvider $dataProvider,
96  $gridIdSuffix = null,
97  $gridViewPagerParams = array()
98  )
99  {
100  assert('is_array($gridViewPagerParams)');
101  $this->controllerId = $controllerId;
102  $this->moduleId = $moduleId;
103  $this->dataProvider = $dataProvider;
104  $this->gridIdSuffix = $gridIdSuffix;
105  $this->gridViewPagerParams = $gridViewPagerParams;
106  $this->gridId = 'report-results-grid-view';
107  }
108 
112  public function getGridViewId()
113  {
114  return $this->gridId . $this->gridIdSuffix;
115  }
116 
122  public function getLinkString($attributeString, $attribute)
123  {
124  $shouldRenderMultipleLinks = $this->getShouldRenderMultipleLinksByReportDataProvider($this->dataProvider);
125  $string = 'ReportResultsGridUtil::makeStringForLinkOrLinks("' .
126  $attribute . '", $data, "' . $shouldRenderMultipleLinks . '", ' . $attributeString . ')';
127  return $string;
128  }
129 
130  protected function getShouldRenderMultipleLinksByReportDataProvider(ReportDataProvider $dataProvider)
131  {
132  if ($dataProvider instanceof RowsAndColumnsReportDataProvider)
133  {
134  return false;
135  }
136  return true;
137  }
138 
142  protected static function getGridTemplate()
143  {
144  $preloader = '<div class="list-preloader"><span class="z-spinner"></span></div>';
145  return "{summary}\n{items}\n{pager}" . $preloader;
146  }
147 
151  protected static function getPagerCssClass()
152  {
153  return 'pager horizontal';
154  }
155 
159  protected static function getSummaryText()
160  {
161  return Zurmo::t('Core', '{count} result(s)');
162  }
163 
167  protected static function getSummaryCssClass()
168  {
169  return 'summary';
170  }
171 
176  protected function renderContent()
177  {
178  if (!$this->isDataProviderValid())
179  {
180  throw new NotSupportedException();
181  }
182  return $this->renderResultsGridContent();
183  }
184 
188  protected function renderResultsGridContent()
189  {
190  $cClipWidget = new CClipWidget();
191  $cClipWidget->beginClip("ReportResultsGridView");
192  $cClipWidget->widget($this->getGridViewWidgetPath(), $this->getCGridViewParams());
193  $cClipWidget->endClip();
194  $content = $cClipWidget->getController()->clips['ReportResultsGridView'] . "\n";
195  $content .= $this->renderScripts();
196  return $content;
197  }
198 
202  protected function getGridViewWidgetPath()
203  {
204  return 'application.modules.reports.widgets.ReportResultsExtendedGridView';
205  }
206 
210  protected function getCGridViewParams()
211  {
212  $columns = $this->getCGridViewColumns();
213  assert('is_array($columns)');
214  return array(
215  'id' => $this->getGridViewId(),
216  'htmlOptions' => array(
217  'class' => 'cgrid-view'
218  ),
219  'loadingCssClass' => 'loading',
220  'dataProvider' => $this->dataProvider,
221  'pager' => $this->getCGridViewPagerParams(),
222  'beforeAjaxUpdate' => $this->getCGridViewBeforeAjaxUpdate(),
223  'afterAjaxUpdate' => $this->getCGridViewAfterAjaxUpdate(),
224  'columns' => $columns,
225  'nullDisplay' => '&#160;',
226  'pagerCssClass' => static::getPagerCssClass(),
227  'showTableOnEmpty' => $this->getShowTableOnEmpty(),
228  'emptyText' => $this->getEmptyText(),
229  'template' => static::getGridTemplate(),
230  'summaryText' => static::getSummaryText(),
231  'summaryCssClass' => static::getSummaryCssClass(),
232  'summaryCloneId' => $this->getSummaryCloneId(),
233  'enableSorting' => false,
234  'expandableRows' => $this->rowsAreExpandable(),
235  'leadingHeaders' => $this->getLeadingHeaders(),
236  );
237  }
238 
242  protected function getCGridViewPagerParams()
243  {
244  $defaultGridViewPagerParams = array(
245  'firstPageLabel' => '<span>first</span>',
246  'prevPageLabel' => '<span>previous</span>',
247  'nextPageLabel' => '<span>next</span>',
248  'lastPageLabel' => '<span>last</span>',
249  'class' => 'SimpleListLinkPager',
250  'paginationParams' => GetUtil::getData(),
251  'route' => 'defaultPortlet/details',
252  );
253  return $this->resolveDefaultGridViewPagerParams($defaultGridViewPagerParams);
254  }
255 
260  protected function resolveDefaultGridViewPagerParams($defaultGridViewPagerParams)
261  {
262  if (empty($this->gridViewPagerParams))
263  {
264  return $defaultGridViewPagerParams;
265  }
266  else
267  {
268  return array_merge($defaultGridViewPagerParams, $this->gridViewPagerParams);
269  }
270  }
271 
275  protected function getShowTableOnEmpty()
276  {
277  return true;
278  }
279 
283  protected function getEmptyText()
284  {
285  return $this->emptyText;
286  }
287 
293  protected function getCGridViewColumns()
294  {
295  $columns = array();
296 
297  if ($this->rowsAreExpandable())
298  {
299  $firstColumn = array(
300  'class' => 'DrillDownColumn',
301  'id' => $this->gridId . $this->gridIdSuffix . '-rowDrillDown',
302  'htmlOptions' => array('class' => 'hasDrillDownLink')
303  );
304  array_push($columns, $firstColumn);
305  }
306  $grandTotals = $this->dataProvider->runQueryAndGrandTotalsData();
307  $grandTotalsRow = $grandTotals[0];
308  $isFirstRow = true;
309  foreach ($this->dataProvider->resolveDisplayAttributes() as $key => $displayAttribute)
310  {
311  if (!$displayAttribute->queryOnly)
312  {
313  $columnClassName = $this->resolveColumnClassNameForListViewColumnAdapter($displayAttribute);
314  $attributeName = $displayAttribute->resolveAttributeNameForGridViewColumn($key);
315  $params = $this->resolveParamsForColumnElement($displayAttribute);
316  $columnAdapter = new $columnClassName($attributeName, $this, $params);
317  $column = $columnAdapter->renderGridViewData();
318  $column['header'] = $displayAttribute->label;
319  if (!isset($column['class']))
320  {
321  $column['class'] = 'DataColumn';
322  }
323  if (isset($grandTotalsRow) && $isFirstRow)
324  {
325  $column['footer'] = Zurmo::t('Core', 'Total');
326  }
327  if (isset($grandTotalsRow[$displayAttribute->columnAliasName]))
328  {
329  $column['footer'] = $columnAdapter->renderValue($grandTotalsRow[$displayAttribute->columnAliasName]);
330  }
331  array_push($columns, $column);
332  $isFirstRow = false;
333  }
334  }
335  return $columns;
336  }
337 
343  {
344  $displayElementType = $displayAttribute->getDisplayElementType();
345  if (@class_exists($displayElementType . 'ForReportListViewColumnAdapter'))
346  {
347  return $displayElementType . 'ForReportListViewColumnAdapter';
348  }
349  else
350  {
351  return $displayElementType . 'ListViewColumnAdapter';
352  }
353  }
354 
359  protected function resolveParamsForColumnElement(DisplayAttributeForReportForm $displayAttribute)
360  {
361  $params = array();
362  if ($displayAttribute->isALinkableAttribute())
363  {
364  $params['isLink'] = true;
365  }
366  elseif ($displayAttribute->isATypeOfCurrencyValue())
367  {
368  $params['currencyValueConversionType'] = $this->dataProvider->getReport()->getCurrencyConversionType();
369  $params['spotConversionCurrencyCode'] = $this->dataProvider->getReport()->getSpotConversionCurrencyCode();
370  $params['fromBaseToSpotRate'] = $this->dataProvider->getReport()->getFromBaseToSpotRate();
371  }
372  return $params;
373  }
374 
378  protected function getCGridViewBeforeAjaxUpdate()
379  {
380  return 'js:function(id, options) {$(this).makeSmallLoadingSpinner(true, "#"+id + " > .list-preloader"); }'; // Not Coding Standard
381  }
382 
388  protected function getCGridViewAfterAjaxUpdate()
389  {
390  // Begin Not Coding Standard
391  return 'js:function(id, data) {
392  processAjaxSuccessError(id, data);
393  }';
394  // End Not Coding Standard
395  }
396 
397  protected function renderScripts()
398  {
399  Yii::app()->clientScript->registerScriptFile(
400  Yii::app()->getAssetManager()->publish(
401  Yii::getPathOfAlias('application.core.views.assets')) . '/ListViewUtils.js');
402  }
403 
407  protected function rowsAreExpandable()
408  {
409  if (count($this->dataProvider->getReport()->getDrillDownDisplayAttributes()) > 0)
410  {
411  return true;
412  }
413  return false;
414  }
415 
419  protected function getLeadingHeaders()
420  {
421  }
422 
423  public function getSummaryCloneId()
424  {
425  return $this->getGridViewId() . "-summary-clone";
426  }
427  }
428 ?>
getLinkString($attributeString, $attribute)
Definition: View.php:43
resolveColumnClassNameForListViewColumnAdapter(DisplayAttributeForReportForm $displayAttribute)
resolveParamsForColumnElement(DisplayAttributeForReportForm $displayAttribute)
resolveDefaultGridViewPagerParams($defaultGridViewPagerParams)
__construct($controllerId, $moduleId, ReportDataProvider $dataProvider, $gridIdSuffix=null, $gridViewPagerParams=array())
Generated on Wed Jul 8 2020 07:10:37
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.