Complex classes like TbExtendedGridView often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TbExtendedGridView, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class TbExtendedGridView extends TbGridView { |
||
28 | |||
29 | /** |
||
30 | * @var bool $fixedHeader if set to true will keep the header fixed position |
||
31 | */ |
||
32 | public $fixedHeader = false; |
||
33 | |||
34 | /** |
||
35 | * @var integer $headerOffset, when $fixedHeader is set to true, headerOffset will position table header top position |
||
36 | * at $headerOffset. If you are using bootstrap and has navigation top fixed, its height is 40px, so it is recommended |
||
37 | * to use $headerOffset=40; |
||
38 | */ |
||
39 | public $headerOffset = 0; |
||
40 | |||
41 | /** |
||
42 | * @var string the template to be used to control the layout of various sections in the view. |
||
43 | * These tokens are recognized: {extendedSummary}, {summary}, {items} and {pager}. They will be replaced with the |
||
44 | * extended summary, summary text, the items, and the pager. |
||
45 | */ |
||
46 | public $template = "{summary}\n{items}\n{pager}\n{extendedSummary}"; |
||
47 | |||
48 | /** |
||
49 | * @var array $extendedSummary displays an extended summary version. |
||
50 | * There are different types of summary types, |
||
51 | * please, see {@link TbSumOperation}, {@link TbSumOfTypeOperation},{@link TbPercentOfTypeGooglePieOperation} |
||
52 | * {@link TbPercentOfTypeOperation} and {@link TbPercentOfTypeEasyPieOperation}. |
||
53 | * |
||
54 | * The following is an example, please review the different types of TbOperation classes to find out more about |
||
55 | * its configuration parameters. |
||
56 | * |
||
57 | * <pre> |
||
58 | * 'extendedSummary' => array( |
||
59 | * 'title' => '', // the extended summary title |
||
60 | * 'columns' => array( // the 'columns' that will be displayed at the extended summary |
||
61 | * 'id' => array( // column name "id" |
||
62 | * 'class' => 'TbSumOperation', // what is the type of TbOperation we are going to display |
||
63 | * 'label' => 'Sum of Ids' // label is name of label of the resulted value (ie Sum of Ids:) |
||
64 | * ), |
||
65 | * 'results' => array( // column name "results" |
||
66 | * 'class' => 'TbPercentOfTypeGooglePieOperation', // the type of TbOperation |
||
67 | * 'label' => 'How Many Of Each? ', // the label of the operation |
||
68 | * 'types' => array( // TbPercentOfTypeGooglePieOperation "types" attributes |
||
69 | * '0' => array('label' => 'zeros'), // a value of "0" will be labelled "zeros" |
||
70 | * '1' => array('label' => 'ones'), // a value of "1" will be labelled "ones" |
||
71 | * '2' => array('label' => 'twos')) // a value of "2" will be labelled "twos" |
||
72 | * ) |
||
73 | * ) |
||
74 | * ), |
||
75 | * </pre> |
||
76 | */ |
||
77 | public $extendedSummary = array(); |
||
78 | |||
79 | /** |
||
80 | * @var string $extendedSummaryCssClass is the class name of the layer containing the extended summary |
||
81 | */ |
||
82 | public $extendedSummaryCssClass = 'extended-summary'; |
||
83 | |||
84 | /** |
||
85 | * @var array $extendedSummaryOptions the HTML attributes of the layer containing the extended summary |
||
86 | */ |
||
87 | public $extendedSummaryOptions = array(); |
||
88 | |||
89 | /** |
||
90 | * @var array $componentsAfterAjaxUpdate has scripts that will be executed after components have updated. |
||
91 | * It is used internally to render scripts required for components to work correctly. You may use it for your own |
||
92 | * scripts, just make sure it is of type array. |
||
93 | */ |
||
94 | public $componentsAfterAjaxUpdate = array(); |
||
95 | |||
96 | /** |
||
97 | * @var array $componentsReadyScripts hold scripts that will be executed on document ready. |
||
98 | * It is used internally to render scripts required for components to work correctly. You may use it for your own |
||
99 | * scripts, just make sure it is of type array. |
||
100 | */ |
||
101 | public $componentsReadyScripts = array(); |
||
102 | |||
103 | /** |
||
104 | * @var array $chartOptions if configured, the extended view will display a highcharts chart. |
||
105 | */ |
||
106 | public $chartOptions = array(); |
||
107 | |||
108 | /** |
||
109 | * @var bool $sortableRows. If true the rows at the table will be sortable. |
||
110 | */ |
||
111 | public $sortableRows = false; |
||
112 | |||
113 | /** |
||
114 | * @var string Database field name for row sorting |
||
115 | */ |
||
116 | public $sortableAttribute = 'sort_order'; |
||
117 | |||
118 | /** |
||
119 | * @var boolean Save sort order by ajax defaults to false |
||
120 | * @see bootstrap.action.TbSortableAction for an easy way to use with your controller |
||
121 | */ |
||
122 | public $sortableAjaxSave = false; |
||
123 | |||
124 | /** |
||
125 | * @var string Name of the action to call and sort values |
||
126 | * @see bootstrap.action.TbSortableAction for an easy way to use with your controller |
||
127 | * |
||
128 | * <pre> |
||
129 | * 'sortableAction' => 'module/controller/sortable' | 'controller/sortable' |
||
130 | * </pre> |
||
131 | * |
||
132 | * The widget will make use of the string to create the URL and then append $sortableAttribute |
||
133 | * @see $sortableAttribute |
||
134 | */ |
||
135 | public $sortableAction; |
||
136 | |||
137 | /** |
||
138 | * @var string a javascript function that will be invoked after a successful sorting is done. |
||
139 | * The function signature is <code>function(id, position)</code> where 'id' refers to the ID of the model id key, |
||
140 | * 'position' the new position in the list. |
||
141 | */ |
||
142 | public $afterSortableUpdate; |
||
143 | |||
144 | /** |
||
145 | * @var bool whether to allow selecting of cells |
||
146 | */ |
||
147 | public $selectableCells = false; |
||
148 | |||
149 | /** |
||
150 | * @var string the filter to use to allow selection. For example, if you set the "htmlOptions" property of a column to have a |
||
151 | * "class" of "tobeselected", you could set this property as: "td.tobeselected" in order to allow selection to |
||
152 | * those columns with that class only. |
||
153 | */ |
||
154 | public $selectableCellsFilter = 'td'; |
||
155 | |||
156 | /** |
||
157 | * @var string a javascript function that will be invoked after a selection is done. |
||
158 | * The function signature is <code>function(selected)</code> where 'selected' refers to the selected columns. |
||
159 | */ |
||
160 | public $afterSelectableCells; |
||
161 | /** |
||
162 | * @var array the configuration options to display a TbBulkActions widget |
||
163 | * @see TbBulkActions widget for its configuration |
||
164 | */ |
||
165 | public $bulkActions = array(); |
||
166 | |||
167 | /** |
||
168 | * @var string the aligment of the bulk actions. It can be 'left' or 'right'. |
||
169 | */ |
||
170 | public $bulkActionAlign = 'right'; |
||
171 | |||
172 | /** |
||
173 | * @var TbBulkActions component that will display the bulk actions to the grid |
||
174 | */ |
||
175 | protected $bulk; |
||
176 | |||
177 | /** |
||
178 | * @var boolean $displayExtendedSummary a helper property that is set to true if we have to render the |
||
179 | * extended summary |
||
180 | */ |
||
181 | protected $displayExtendedSummary; |
||
182 | /** |
||
183 | * @var boolean $displayChart a helper property that is set to true if we have to render a chart. |
||
184 | */ |
||
185 | protected $displayChart; |
||
186 | |||
187 | /** |
||
188 | * @var TbOperation[] $extendedSummaryTypes hold the current configured TbOperation that will process column values. |
||
189 | */ |
||
190 | protected $extendedSummaryTypes = array(); |
||
191 | |||
192 | /** |
||
193 | * @var array $extendedSummaryOperations hold the supported operation types |
||
194 | */ |
||
195 | protected $extendedSummaryOperations = array( |
||
196 | 'TbSumOperation', |
||
197 | 'TbCountOfTypeOperation', |
||
198 | 'TbPercentOfTypeOperation', |
||
199 | 'TbPercentOfTypeEasyPieOperation', |
||
200 | 'TbPercentOfTypeGooglePieOperation' |
||
201 | ); |
||
202 | |||
203 | /** |
||
204 | *### .init() |
||
205 | * |
||
206 | * Widget initialization |
||
207 | */ |
||
208 | public function init(){ |
||
209 | |||
210 | if ($this->shouldEnableExtendedSummary()) |
||
211 | $this->prepareDisplayingExtendedSummary(); |
||
212 | |||
213 | if ($this->shouldEnableChart() && $this->hasData()) |
||
214 | $this->enableChart(); |
||
215 | |||
216 | if ($this->shouldEnableBulkActions()) |
||
217 | $this->enableBulkActions(); |
||
218 | |||
219 | $this->fillSelectionChangedProperty(); |
||
220 | |||
221 | parent::init(); |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | *### .renderContent() |
||
226 | * |
||
227 | * Renders grid content |
||
228 | */ |
||
229 | public function renderContent() |
||
230 | { |
||
231 | parent::renderContent(); |
||
232 | $this->registerCustomClientScript(); |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | *### .renderKeys() |
||
237 | * |
||
238 | * Renders the key values of the data in a hidden tag. |
||
239 | */ |
||
240 | public function renderKeys() |
||
266 | |||
267 | /** |
||
268 | *### .getAttribute() |
||
269 | * |
||
270 | * Helper function to get an attribute from the data |
||
271 | * |
||
272 | * @param CActiveRecord $data |
||
273 | * @param string $attribute the attribute to get |
||
274 | * |
||
275 | * @return mixed the attribute value null if none found |
||
276 | */ |
||
277 | protected function getAttribute($data, $attribute) |
||
293 | |||
294 | /** |
||
295 | *### .getPrimaryKey() |
||
296 | * |
||
297 | * Helper function to return the primary key of the $data |
||
298 | * IMPORTANT: composite keys on CActiveDataProviders will return the keys joined by comma |
||
299 | * |
||
300 | * @param CActiveRecord $data |
||
301 | * |
||
302 | * @return null|string |
||
303 | */ |
||
304 | protected function getPrimaryKey($data) |
||
317 | |||
318 | /** |
||
319 | *### .renderTableHeader() |
||
320 | * |
||
321 | * Renders grid header |
||
322 | */ |
||
323 | public function renderTableHeader() { |
||
324 | |||
325 | $this->renderChart(); |
||
326 | parent::renderTableHeader(); |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | *### .renderTableFooter() |
||
331 | * |
||
332 | * Renders the table footer. |
||
333 | */ |
||
334 | public function renderTableFooter() |
||
359 | |||
360 | /** |
||
361 | *### .renderBulkActions() |
||
362 | */ |
||
363 | public function renderBulkActions() { |
||
364 | |||
365 | Booster::getBooster()->registerAssetJs('jquery.saveselection.gridview.js'); |
||
366 | $this->componentsAfterAjaxUpdate[] = "$.fn.yiiGridView.afterUpdateGrid('".$this->id."');"; |
||
367 | echo '<tr><td colspan="' . count($this->columns) . '">'; |
||
368 | $this->bulk->renderButtons(); |
||
369 | echo '</td></tr>'; |
||
370 | } |
||
371 | |||
372 | |||
373 | /** |
||
374 | *### .renderChart() |
||
375 | * |
||
376 | * Renders chart |
||
377 | * @throws CException |
||
378 | */ |
||
379 | public function renderChart() { |
||
380 | |||
381 | if (!$this->displayChart || $this->dataProvider->getItemCount() <= 0) { |
||
382 | return; |
||
383 | } |
||
384 | |||
385 | if (!isset($this->chartOptions['data']['series'])) { |
||
386 | throw new CException(Yii::t( |
||
387 | 'zii', |
||
388 | 'You need to set the "series" attribute in order to render a chart' |
||
389 | )); |
||
390 | } |
||
391 | |||
392 | $configSeries = $this->chartOptions['data']['series']; |
||
393 | if (!is_array($configSeries)) { |
||
394 | throw new CException(Yii::t('zii', '"chartOptions.series" is expected to be an array.')); |
||
395 | } |
||
396 | |||
397 | |||
398 | if (!isset($this->chartOptions['config'])) { |
||
399 | $this->chartOptions['config'] = array(); |
||
400 | } |
||
401 | |||
402 | // **************************************** |
||
403 | // render switch buttons |
||
404 | $buttons = Yii::createComponent( |
||
405 | array( |
||
406 | 'class' => 'booster.widgets.TbButtonGroup', |
||
407 | 'toggle' => 'radio', |
||
408 | 'buttons' => array( |
||
409 | array( |
||
410 | 'label' => Yii::t('zii', 'Grid'), |
||
411 | 'url' => '#', |
||
412 | 'htmlOptions' => array('class' => 'active ' . $this->getId() . '-grid-control grid') |
||
413 | ), |
||
414 | array( |
||
415 | 'label' => Yii::t('zii', 'Chart'), |
||
416 | 'url' => '#', |
||
417 | 'htmlOptions' => array('class' => $this->getId() . '-grid-control chart') |
||
418 | ), |
||
419 | ), |
||
420 | 'htmlOptions' => array('style' => 'margin-bottom:5px') |
||
421 | ) |
||
422 | ); |
||
423 | echo '<div>'; |
||
424 | $buttons->init(); |
||
425 | $buttons->run(); |
||
426 | echo '</div>'; |
||
427 | |||
428 | $chartId = preg_replace('[-\\ ?]', '_', 'exgvwChart' . $this->getId()); // cleaning out most possible characters invalid as javascript variable identifiers. |
||
429 | |||
430 | $this->componentsReadyScripts[] = '$(document).on("click",".' . $this->getId() . '-grid-control", function() { |
||
431 | $(this).parent().find("input[type=\"radio\"]").parent().toggleClass("active"); |
||
432 | if ($(this).hasClass("grid") && $("#' . $this->getId() . ' #' . $chartId . '").is(":visible")) |
||
433 | { |
||
434 | $("#' . $this->getId() . ' #' . $chartId . '").hide(); |
||
435 | $("#' . $this->getId() . ' table.items").show(); |
||
436 | } |
||
437 | if ($(this).hasClass("chart") && $("#' . $this->getId() . ' table.items").is(":visible")) |
||
438 | { |
||
439 | $("#' . $this->getId() . ' table.items").hide(); |
||
440 | $("#' . $this->getId() . ' #' . $chartId . '").show(); |
||
441 | } |
||
442 | return false; |
||
443 | });'; |
||
444 | |||
445 | $this->componentsAfterAjaxUpdate[] = ' |
||
446 | if($("label.grid.'.$this->getId().'-grid-control").hasClass("active")) { |
||
447 | $("#' . $this->getId() . ' #' . $chartId . '").hide(); |
||
448 | $("#' . $this->getId() . ' table.items").show(); |
||
449 | } else { |
||
450 | $("#' . $this->getId() . ' table.items").hide(); |
||
451 | $("#' . $this->getId() . ' #' . $chartId . '").show(); |
||
452 | } |
||
453 | '; |
||
454 | // end switch buttons |
||
455 | // **************************************** |
||
456 | |||
457 | // render Chart |
||
458 | // chart options |
||
459 | $data = $this->dataProvider->getData(); |
||
460 | $count = count($data); |
||
461 | $seriesData = array(); |
||
462 | $cnt = 0; |
||
463 | foreach ($configSeries as $set) { |
||
464 | $seriesData[$cnt] = array('name' => isset($set['name']) ? $set['name'] : null, 'data' => array()); |
||
465 | |||
466 | for ($row = 0; $row < $count; ++$row) { |
||
467 | $column = $this->getColumnByName($set['attribute']); |
||
468 | if (!is_null($column) && $column->value !== null) { |
||
469 | $seriesData[$cnt]['data'][] = $this->evaluateExpression( |
||
470 | $column->value, |
||
471 | array('data' => $data[$row], 'row' => $row) |
||
472 | ); |
||
473 | } else { |
||
474 | $value = CHtml::value($data[$row], $set['attribute']); |
||
475 | $seriesData[$cnt]['data'][] = is_numeric($value) ? (float)$value : $value; |
||
476 | } |
||
477 | |||
478 | } |
||
479 | ++$cnt; |
||
480 | } |
||
481 | |||
482 | $xAxisData = array(); |
||
483 | |||
484 | $xAxisData[] = array('categories'=>array()); |
||
485 | if(!empty($this->chartOptions['data']['xAxis'])){ |
||
486 | $xAxis = $this->chartOptions['data']['xAxis']; |
||
487 | $categories = $xAxis['categories']; |
||
488 | if(is_array($categories)) { |
||
489 | $xAxisData['categories'] = $categories; |
||
490 | } else { // field name |
||
491 | for ($row = 0; $row < $count; ++$row) { |
||
492 | $column = $this->getColumnByName($categories); |
||
493 | if (!is_null($column) && $column->value !== null) { |
||
494 | $xAxisData['categories'][] = $this->evaluateExpression( |
||
495 | $column->value, |
||
496 | array('data' => $data[$row], 'row' => $row) |
||
497 | ); |
||
498 | } else { |
||
499 | $value = CHtml::value($data[$row], $categories); |
||
500 | $xAxisData['categories'][] = $value; |
||
501 | } |
||
502 | } |
||
503 | } |
||
504 | } |
||
505 | |||
506 | // **************************************** |
||
507 | // render chart |
||
508 | $options = CMap::mergeArray( |
||
509 | $this->chartOptions['config'], |
||
510 | array('series' => $seriesData, 'xAxis' => $xAxisData) |
||
511 | ); |
||
512 | $this->chartOptions['htmlOptions'] = isset($this->chartOptions['htmlOptions']) |
||
513 | ? $this->chartOptions['htmlOptions'] : array(); |
||
514 | |||
515 | // sorry but use a class to provide styles, we need this |
||
516 | if(empty($this->chartOptions['htmlOptions']['style'])) |
||
517 | $this->chartOptions['htmlOptions']['style'] = 'width: 100%; height: 100%;'; |
||
518 | else |
||
519 | $this->chartOptions['htmlOptions']['style'] = $this->chartOptions['htmlOptions']['style'].'; width: 100%; height: 100%;'; |
||
520 | |||
521 | // build unique ID |
||
522 | // important! |
||
523 | echo '<div>'; |
||
524 | if ($this->ajaxUpdate !== false) { |
||
525 | if (isset($options['chart']) && is_array($options['chart'])) { |
||
526 | $options['chart']['renderTo'] = $chartId; |
||
527 | } else { |
||
528 | $options['chart'] = array('renderTo' => $chartId); |
||
529 | } |
||
530 | $jsOptions = CJSON::encode($options); |
||
531 | |||
532 | if (isset($this->chartOptions['htmlOptions']['data-config'])) { |
||
533 | unset($this->chartOptions['htmlOptions']['data-config']); |
||
534 | } |
||
535 | |||
536 | echo "<div id='{$chartId}' " . CHtml::renderAttributes( |
||
537 | $this->chartOptions['htmlOptions'] |
||
538 | ) . " data-config='{$jsOptions}'></div>"; |
||
539 | |||
540 | /* fix for chart dimensions changing after ajax */ |
||
541 | $this->componentsAfterAjaxUpdate[] = " |
||
542 | $('#".$chartId."').width($('#".$this->id." table').width()); |
||
543 | $('#".$chartId."').height($('#".$this->id." table').height() + 150); |
||
544 | highchart{$chartId} = new Highcharts.Chart($('#{$chartId}').data('config')); |
||
545 | "; |
||
546 | } |
||
547 | $configChart = array( |
||
548 | 'class' => 'booster.widgets.TbHighCharts', |
||
549 | 'id' => $chartId, |
||
550 | 'options' => $options, |
||
551 | 'htmlOptions' => $this->chartOptions['htmlOptions'] |
||
552 | ); |
||
553 | $chart = Yii::createComponent($configChart); |
||
554 | $chart->init(); |
||
555 | $chart->run(); |
||
556 | echo '</div>'; |
||
557 | // end chart display |
||
558 | // **************************************** |
||
559 | |||
560 | // check if the chart should appear by default |
||
561 | if(isset($this->chartOptions['defaultView']) && $this->chartOptions['defaultView'] === true) { |
||
562 | $this->componentsReadyScripts[] = ' |
||
563 | $(".' . $this->getId() . '-grid-control.grid").removeClass("active"); |
||
564 | $(".' . $this->getId() . '-grid-control.chart").addClass("active"); |
||
565 | $("#' . $this->getId() . ' table.items").hide(); |
||
566 | $("#' . $this->getId() . ' #' . $chartId . '").show(); |
||
567 | '; |
||
568 | } else { |
||
569 | $this->componentsReadyScripts[] = ' |
||
570 | $(".' . $this->getId() . '-grid-control.grid").addClass("active"); |
||
571 | $(".' . $this->getId() . '-grid-control.chart").removeClass("active"); |
||
572 | $("#' . $this->getId() . ' table.items").show(); |
||
573 | $("#' . $this->getId() . ' #' . $chartId . '").hide(); |
||
574 | '; |
||
575 | } |
||
576 | } |
||
577 | |||
578 | /** |
||
579 | *### .renderTableRow() |
||
580 | * |
||
581 | * Renders a table body row. |
||
582 | * |
||
583 | * This method is a copy-paste from CGridView.renderTableRow(), |
||
584 | * because we cannot override *just* the `renderDataCell` routine (it's polymorphic) |
||
585 | * and Yii doesn't have a seam in place for us to do this. |
||
586 | * @see https://github.com/yiisoft/yii/pull/3571 |
||
587 | * |
||
588 | * Only meaningful change in here is the replacement of the `$column->renderDataCell($row)` |
||
589 | * with our own method. |
||
590 | * |
||
591 | * @param integer $row the row number (zero-based). |
||
592 | * |
||
593 | * @deprecated This method will be removed after Yii 1.1.17 release. |
||
594 | */ |
||
595 | public function renderTableRow($row) |
||
596 | { |
||
597 | $htmlOptions = array(); |
||
598 | if ($this->rowHtmlOptionsExpression !== null) { |
||
599 | $data = $this->dataProvider->data[$row]; |
||
600 | $options = $this->evaluateExpression( |
||
601 | $this->rowHtmlOptionsExpression, |
||
602 | array('row' => $row, 'data' => $data) |
||
603 | ); |
||
604 | if (is_array($options)) { |
||
605 | $htmlOptions = $options; |
||
606 | } |
||
607 | } |
||
608 | |||
609 | if ($this->rowCssClassExpression !== null) { |
||
610 | $data = $this->dataProvider->data[$row]; |
||
611 | $class = $this->evaluateExpression($this->rowCssClassExpression, array('row' => $row, 'data' => $data)); |
||
612 | } elseif (is_array($this->rowCssClass) && ($n = count($this->rowCssClass)) > 0) { |
||
613 | $class = $this->rowCssClass[$row % $n]; |
||
614 | } |
||
615 | |||
616 | if (!empty($class)) { |
||
617 | if (isset($htmlOptions['class'])) { |
||
618 | $htmlOptions['class'] .= ' ' . $class; |
||
619 | } else { |
||
620 | $htmlOptions['class'] = $class; |
||
621 | } |
||
622 | } |
||
623 | |||
624 | echo CHtml::openTag('tr', $htmlOptions); |
||
625 | foreach ($this->columns as $column) |
||
626 | $this->renderDataCellProcessingSummariesIfNeeded($column, $row); |
||
627 | echo CHtml::closeTag('tr'); |
||
628 | } |
||
629 | |||
630 | /** |
||
631 | *### .renderExtendedSummary() |
||
632 | * |
||
633 | * Renders summary |
||
634 | */ |
||
635 | public function renderExtendedSummary() |
||
645 | |||
646 | /** |
||
647 | *### .renderExtendedSummaryContent() |
||
648 | * |
||
649 | * Renders summary content. Will be appended to |
||
650 | */ |
||
651 | public function renderExtendedSummaryContent() |
||
652 | { |
||
653 | if ($this->dataProvider->getItemCount() <= 0) |
||
654 | return; |
||
655 | |||
656 | if (empty($this->extendedSummaryTypes)) |
||
657 | return; |
||
658 | |||
659 | echo '<div id="' . $this->id . '-extended-summary" style="display:none">'; |
||
660 | if (isset($this->extendedSummary['title'])) { |
||
661 | echo '<h3>' . $this->extendedSummary['title'] . '</h3>'; |
||
662 | } |
||
663 | foreach ($this->extendedSummaryTypes as $summaryType) { |
||
664 | /** @var $summaryType TbOperation */ |
||
665 | $summaryType->run(); |
||
666 | echo '<br/>'; |
||
667 | } |
||
668 | echo '</div>'; |
||
669 | } |
||
670 | |||
671 | /** |
||
672 | *### .registerCustomClientScript() |
||
673 | * |
||
674 | * This script must be run at the end of content rendering not at the beginning as it is common with normal CGridViews |
||
675 | */ |
||
676 | public function registerCustomClientScript() |
||
677 | { |
||
678 | /** @var $cs CClientScript */ |
||
679 | $cs = Yii::app()->getClientScript(); |
||
680 | |||
681 | $fixedHeaderJs = ''; |
||
682 | if ($this->fixedHeader) { |
||
683 | Booster::getBooster()->registerAssetJs('jquery.stickytableheaders' . (!YII_DEBUG ? '.min' : '') . '.js'); |
||
684 | $fixedHeaderJs = "$('#{$this->id} table.items').stickyTableHeaders({fixedOffset:{$this->headerOffset}});"; |
||
685 | $this->componentsAfterAjaxUpdate[] = $fixedHeaderJs; |
||
686 | } |
||
687 | |||
688 | if ($this->sortableRows) { |
||
689 | $afterSortableUpdate = ''; |
||
690 | if ($this->afterSortableUpdate !== null) { |
||
691 | if (!($this->afterSortableUpdate instanceof CJavaScriptExpression) && strpos( |
||
692 | $this->afterSortableUpdate, |
||
693 | 'js:' |
||
694 | ) !== 0 |
||
695 | ) { |
||
696 | $afterSortableUpdate = new CJavaScriptExpression($this->afterSortableUpdate); |
||
697 | } else { |
||
698 | $afterSortableUpdate = $this->afterSortableUpdate; |
||
699 | } |
||
700 | } |
||
701 | |||
702 | $this->selectableRows = 1; |
||
703 | $cs->registerCoreScript('jquery.ui'); |
||
704 | Booster::getBooster()->registerAssetJs('jquery.sortable.gridview.js'); |
||
705 | |||
706 | if ($this->sortableAjaxSave && $this->sortableAction !== null) { |
||
707 | $sortableAction = Yii::app()->createUrl( |
||
708 | $this->sortableAction, |
||
709 | array('sortableAttribute' => $this->sortableAttribute) |
||
710 | ); |
||
711 | } else { |
||
712 | $sortableAction = ''; |
||
713 | } |
||
714 | |||
715 | $afterSortableUpdate = CJavaScript::encode($afterSortableUpdate); |
||
716 | if (Yii::app()->request->enableCsrfValidation) |
||
717 | { |
||
718 | $csrfTokenName = Yii::app()->request->csrfTokenName; |
||
719 | $csrfToken = Yii::app()->request->csrfToken; |
||
720 | $csrf = "{'$csrfTokenName':'$csrfToken' }"; |
||
721 | } else |
||
722 | $csrf = '{}'; |
||
723 | |||
724 | $this->componentsReadyScripts[] = "$.fn.yiiGridView.sortable('{$this->id}', '{$sortableAction}', {$afterSortableUpdate}, $csrf);"; |
||
725 | $this->componentsAfterAjaxUpdate[] = "$.fn.yiiGridView.sortable('{$this->id}', '{$sortableAction}', {$afterSortableUpdate}, $csrf);"; |
||
726 | } |
||
727 | |||
728 | if ($this->selectableCells) { |
||
729 | $afterSelectableCells = ''; |
||
730 | if ($this->afterSelectableCells !== null) { |
||
731 | if (!($this->afterSelectableCells instanceof CJavaScriptExpression) && strpos($this->afterSelectableCells,'js:') !== 0) { |
||
732 | $afterSelectableCells = new CJavaScriptExpression($this->afterSelectableCells); |
||
733 | } else { |
||
734 | $afterSelectableCells = $this->afterSelectableCells; |
||
735 | } |
||
736 | } |
||
737 | $cs->registerCoreScript('jquery.ui'); |
||
738 | Booster::getBooster()->registerAssetJs('jquery.selectable.gridview.js'); |
||
739 | $afterSelectableCells = CJavaScript::encode($afterSelectableCells); |
||
740 | $this->componentsReadyScripts[] = "$.fn.yiiGridView.selectable('{$this->id}','{$this->selectableCellsFilter}',{$afterSelectableCells});"; |
||
741 | $this->componentsAfterAjaxUpdate[] = "$.fn.yiiGridView.selectable('{$this->id}','{$this->selectableCellsFilter}', {$afterSelectableCells});"; |
||
742 | } |
||
743 | |||
744 | $cs->registerScript( |
||
745 | __CLASS__ . '#' . $this->id . 'Ex', |
||
746 | ' |
||
747 | var $grid = $("#' . $this->id . '"); |
||
748 | ' . $fixedHeaderJs . ' |
||
749 | if ($(".' . $this->extendedSummaryCssClass . '", $grid).length) |
||
750 | { |
||
751 | $(".' . $this->extendedSummaryCssClass . '", $grid).html($("#' . $this->id . '-extended-summary", $grid).html()); |
||
752 | } |
||
753 | ' . (count($this->componentsReadyScripts) ? implode(PHP_EOL, $this->componentsReadyScripts) : '') . ' |
||
754 | $.ajaxPrefilter(function (options, originalOptions, jqXHR) { |
||
755 | var qs = $.deparam.querystring(options.url); |
||
756 | if (qs.hasOwnProperty("ajax") && qs.ajax == "' . $this->id . '") |
||
757 | { |
||
758 | if (typeof (options.realsuccess) == "undefined" || options.realsuccess !== options.success) |
||
759 | { |
||
760 | options.realsuccess = options.success; |
||
761 | options.success = function(data) |
||
762 | { |
||
763 | if (options.realsuccess) { |
||
764 | options.realsuccess(data); |
||
765 | var $data = $("<div>" + data + "</div>"); |
||
766 | // we need to get the grid again... as it has been updated |
||
767 | if ($(".' . $this->extendedSummaryCssClass . '", $("#' . $this->id . '"))) |
||
768 | { |
||
769 | $(".' . $this->extendedSummaryCssClass . '", $("#' . $this->id . '")).html($("#' . $this->id . '-extended-summary", $data).html()); |
||
770 | } |
||
771 | ' . (count($this->componentsAfterAjaxUpdate) ? implode( |
||
772 | PHP_EOL, |
||
773 | $this->componentsAfterAjaxUpdate |
||
774 | ) : '') . ' |
||
775 | } |
||
776 | } |
||
777 | } |
||
778 | } |
||
779 | });' |
||
780 | ); |
||
781 | } |
||
782 | |||
783 | /** |
||
784 | *### .parseColumnValue() |
||
785 | * |
||
786 | * @param CGridColumn $column |
||
787 | * @param string $value Value of the $column rendered by $column->renderDataCell($row). |
||
788 | */ |
||
789 | protected function processColumnValue($column, $value) |
||
790 | { |
||
791 | if (!($column instanceof CDataColumn)) |
||
792 | return; |
||
793 | |||
794 | if (!array_key_exists($column->name, $this->extendedSummary['columns'])) |
||
795 | return; |
||
796 | |||
797 | $config = $this->extendedSummary['columns'][$column->name]; |
||
798 | $config['column'] = $column; |
||
799 | |||
800 | $this->getSummaryOperationInstance($column->name, $config) |
||
801 | ->processValue($value); |
||
802 | } |
||
803 | |||
804 | /** |
||
805 | *### .getSummaryOperationInstance() |
||
806 | * |
||
807 | * Each type of 'extended' summary |
||
808 | * |
||
809 | * @param string $name the name of the column |
||
810 | * @param array $config the configuration of the column at the extendedSummary |
||
811 | * |
||
812 | * @return mixed |
||
813 | * @throws CException |
||
814 | */ |
||
815 | protected function getSummaryOperationInstance($name, $config) |
||
839 | |||
840 | /** |
||
841 | *### .getColumnByName() |
||
842 | * |
||
843 | * Helper function to get a column by its name |
||
844 | * |
||
845 | * @param string $name |
||
846 | * |
||
847 | * @return TbDataColumn|null |
||
848 | */ |
||
849 | protected function getColumnByName($name) |
||
858 | |||
859 | /** |
||
860 | * @return bool |
||
861 | */ |
||
862 | private function shouldEnableExtendedSummary() |
||
863 | { |
||
864 | return preg_match( |
||
865 | '/extendedsummary/i', |
||
866 | $this->template |
||
867 | ) && !empty($this->extendedSummary) && isset($this->extendedSummary['columns']); |
||
869 | |||
870 | private function prepareDisplayingExtendedSummary() |
||
875 | |||
876 | private function shouldEnableChart() |
||
880 | |||
881 | /** |
||
882 | * @return int |
||
883 | */ |
||
884 | private function hasData() |
||
888 | |||
889 | private function enableChart() |
||
893 | |||
894 | /** |
||
895 | * @return bool |
||
896 | */ |
||
897 | private function shouldEnableBulkActions() |
||
901 | |||
902 | private function enableBulkActions() |
||
911 | |||
912 | private function fillSelectionChangedProperty() |
||
916 | |||
917 | /** |
||
918 | * @return string |
||
919 | */ |
||
920 | private function makeDefaultSelectionChangedJavascript() |
||
926 | |||
927 | /** |
||
928 | * This method will become `renderDataCell` after Yii 1.1.17 will be released |
||
929 | * @see https://github.com/yiisoft/yii/pull/3571 |
||
930 | * |
||
931 | * @param CGridColumn $column |
||
932 | * @param integer $row |
||
933 | */ |
||
934 | private function renderDataCellProcessingSummariesIfNeeded($column, $row) |
||
943 | |||
944 | /** |
||
945 | * @param CGridColumn $column |
||
946 | * @param integer $row |
||
947 | * |
||
948 | * @return string |
||
949 | */ |
||
950 | private function getRenderedDataCellValue($column, $row) |
||
956 | |||
957 | /** |
||
958 | * @return bool |
||
959 | */ |
||
960 | private function isExtendedSummaryEnabled() |
||
964 | |||
965 | } |
||
966 | |||
1446 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.