| Total Complexity | 7 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 1 |
| 1 | <?php |
||
| 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() |
||
| 69 | } |
||
| 70 | |||
| 71 | } |
||
| 72 |