ResultList   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
eloc 20
c 5
b 1
f 0
dl 0
loc 61
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeParentInit() 0 4 1
A getLabelColumn() 0 10 1
A getYearColumn() 0 8 1
A getGenreColumn() 0 8 1
1
<?php
2
3
/**
4
 * Base class for a widget that displays media results as a simple list.
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2014-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
Yii::import('bootstrap.widgets.TbGridView');
11
12
abstract class ResultList extends TbGridView
13
{
14
	use ResultTrait;
0 ignored issues
show
Bug introduced by
The trait ResultTrait requires the property $totalItemCount which is not provided by ResultList.
Loading history...
15
	
16
	/**
17
	 * Returns the column definitions
18
	 */
19
	abstract public function getColumnDefinitions();
20
	
21
	public function beforeParentInit()
22
	{
23
		// Configure columns
24
		$this->columns = $this->getColumnDefinitions();
25
	}
26
	
27
	/**
28
	 * Returns the column definition for the label column
29
	 * @return array
30
	 */
31
	protected function getLabelColumn()
32
	{
33
		return array(
34
			'name'=>'label',
35
			'header'=>Yii::t('GenericList', 'Title'),
36
			'type'=>'html',
37
			'value'=>function($data) {
38
				/* @var $data Media */
39
				echo CHtml::link($data->label, Yii::app()->controller->createUrl('details', array('id'=>$data->getId())));
40
				echo $data->getWatchedIcon();
41
			},
42
		);
43
	}
44
45
	/**
46
	 * Returns the column definition for the year column
47
	 * @return array
48
	 */
49
	protected function getYearColumn()
50
	{
51
		return array(
52
			'name'=>'premiered',
53
			'header'=>Yii::t('GenericList', 'Year'),
54
			'value'=>function($data) {
55
				/** @var Movie|TVShow $data */
56
				echo $data->getRenderedYear();
57
			},
58
		);
59
	}
60
61
	/**
62
	 * Returns the column definition for the genre column
63
	 * @return array
64
	 */
65
	protected function getGenreColumn()
66
	{
67
		return array(
68
			'name'=>'genre',
69
			'header'=>Yii::t('GenericList', 'Genre'),
70
			'value'=>function($data) {
71
				/* @var $data Media */
72
				return $data->getGenreString();
73
			}
74
		);
75
	}
76
77
}
78