1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Renders a collapsed list of seasons with episodes inside (accordion style) |
5
|
|
|
* |
6
|
|
|
* @author Sam Stenvall <[email protected]> |
7
|
|
|
* @copyright Copyright © Sam Stenvall 2013- |
8
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0 |
9
|
|
|
*/ |
10
|
|
|
class SeasonAccordion extends CWidget |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var array the items for the list |
15
|
|
|
*/ |
16
|
|
|
public $items = array(); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var array options for the container |
20
|
|
|
*/ |
21
|
|
|
public $htmlOptions = array(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Initializes the widget |
25
|
|
|
*/ |
26
|
|
|
public function init() |
27
|
|
|
{ |
28
|
|
|
TbHtml::addCssClass('accordion', $this->htmlOptions); |
29
|
|
|
|
30
|
|
|
parent::init(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Renders the widget. If there are no items, nothing will be rendered. |
35
|
|
|
* TODO: Reuse TbCollapse somehow |
36
|
|
|
*/ |
37
|
|
|
public function run() |
38
|
|
|
{ |
39
|
|
|
$itemCount = count($this->items); |
40
|
|
|
|
41
|
|
|
if ($itemCount === 0) |
42
|
|
|
return; |
43
|
|
|
|
44
|
|
|
echo CHtml::openTag('div', $this->htmlOptions); |
45
|
|
|
|
46
|
|
|
foreach ($this->items as $k=> $item) |
47
|
|
|
{ |
48
|
|
|
$id = __CLASS__.'_'.$this->id.'_'.$k; |
49
|
|
|
$contentId = $id.'_content'; |
50
|
|
|
|
51
|
|
|
$linkOptions = array( |
52
|
|
|
'class'=>'accordion-toggle episode-toggle', |
53
|
|
|
'data-content-id'=>$contentId, |
54
|
|
|
'data-toggle'=>'collapse', |
55
|
|
|
'data-parent'=>$this->id); |
56
|
|
|
|
57
|
|
|
// Add content-url data attributes to the link when available |
58
|
|
|
if (isset($item['contentUrl'])) |
59
|
|
|
$linkOptions['data-content-url'] = $item['contentUrl']; |
60
|
|
|
|
61
|
|
|
// Render the contents of the heading |
62
|
|
|
$heading = $this->render('_seasonAccordionHeading', array( |
63
|
|
|
'linkUrl'=>'#'.$id, |
64
|
|
|
'linkOptions'=>$linkOptions, |
65
|
|
|
'season'=>$item['season'], |
66
|
|
|
), true); |
67
|
|
|
|
68
|
|
|
$bodyOptions = array('class'=>'accordion-body collapse', 'id'=>$id); |
69
|
|
|
if ($itemCount === 1) |
70
|
|
|
TbHtml::addCssClass('in', $bodyOptions); |
71
|
|
|
|
72
|
|
|
echo CHtml::openTag('div', array('class'=>'accordion-group')); |
73
|
|
|
echo CHtml::tag('div', array('class'=>'accordion-heading'), $heading); |
74
|
|
|
echo CHtml::openTag('div', $bodyOptions); |
75
|
|
|
echo CHtml::tag('div', array('id'=>$contentId, |
76
|
|
|
'class'=>'accordion-inner'), $item['content']); |
77
|
|
|
echo CHtml::closeTag('div'); |
78
|
|
|
echo CHtml::closeTag('div'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
echo CHtml::closeTag('div'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |