Passed
Push — master ( d021a5...a13070 )
by Sam
03:47 queued 12s
created

Seasons   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
eloc 15
c 4
b 1
f 1
dl 0
loc 59
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasSeasons() 0 3 1
A run() 0 6 2
A init() 0 17 4
1
<?php
2
3
/**
4
 * Renders the seasons for a TV show
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
class Seasons extends CWidget
11
{
12
13
	/**
14
	 * @var TVShow the TV show 
15
	 */
16
	public $tvshow;
17
18
	/**
19
	 * @var Season[] the seasons
20
	 */
21
	public $seasons;
22
	
23
	/**
24
	 * @var string the current display mode
25
	 */
26
	public $displayMode;
27
28
	/**
29
	 * Initializes the widget
30
	 */
31
	public function init()
32
	{
33
		// Determine the display mode
34
		
35
		/* @var $ctrl MediaController */
36
		$ctrl = Yii::app()->controller;
37
		$this->displayMode = $ctrl->getDisplayMode(DisplayMode::CONTEXT_SEASONS);
38
39
		// Register some required scripts
40
		if ($this->hasSeasons() && $this->displayMode === DisplayMode::MODE_LIST)
41
		{
42
			// If we only have one season we want the "drawer" to open 
43
			// automatically on page load
44
			if (count($this->seasons) === 1)
45
			{
46
				Yii::app()->clientScript->registerScript('PopulateSingleSeason', 
47
						'populateAll();', CClientScript::POS_END);
48
			}
49
		}
50
	}
51
52
	/**
53
	 * Renders the widget
54
	 */
55
	public function run()
56
	{
57
		if ($this->hasSeasons())
58
			$this->render('_seasons');
59
		else
60
			echo CHtml::tag('div', array('class'=>'alert alert-block alert-error'), Yii::t('TVShows', 'There are no episodes for this show'));
61
	}
62
63
	/**
64
	 * @return boolean whether we have any seasons to render
65
	 */
66
	private function hasSeasons()
67
	{
68
		return count($this->seasons) > 0;
69
	}
70
71
}
72