WatchMediaModal   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderModalBody() 0 9 1
A renderTriggerButton() 0 9 1
A init() 0 11 1
1
<?php
2
3
Yii::import('bootstrap.widgets.TbModal');
4
5
/**
6
 * Base class for the modals that show watch/download buttons and links
7
 *
8
 * @author Sam Stenvall <[email protected]>
9
 * @copyright Copyright &copy; Sam Stenvall 2014-
10
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
11
 */
12
abstract class WatchMediaModal extends TbModal
13
{
14
15
	/**
16
	 * @var Media the media operated on
17
	 */
18
	public $media;
19
20
	/**
21
	 * @return string the name of the class that should be rendered inside the 
22
	 * modal body
23
	 */
24
	abstract protected function getInnerWidgetClass();
25
26
	/**
27
	 * @return array the options for the Watch button
28
	 */
29
	abstract protected function getWatchButtonOptions();
30
31
	/**
32
	 * Initializes the widget
33
	 */
34
	public function init()
35
	{
36
		// Generate a unique ID. We can't rely on the built-in counter in 
37
		// CWidget::getId() because these modals may be rendered from AJAX 
38
		// request and the counter will be zero then
39
		$this->id = uniqid($this->getId());
40
41
		parent::init();
42
43
		TbHtml::addCssClass('watch-modal', $this->htmlOptions);
44
		$this->header = Yii::t('Movies', 'Watch / Download');
45
	}
46
47
	/**
48
	 * Renders the modal body
49
	 */
50
	public function renderModalBody()
51
	{
52
		echo CHtml::openTag('div', array('class'=>'modal-body'));
53
54
		$this->widget($this->getInnerWidgetClass(), array(
55
			'details'=>$this->media,
56
		));
57
58
		echo CHtml::closeTag('div');
59
	}
60
61
	/**
62
	 * Renders the button that triggers the modal
63
	 * @param array $htmlOptions (optional) options for the button
64
	 */
65
	public function renderTriggerButton($htmlOptions = array())
66
	{
67
		$commonOptions = array(
68
			'class'=>'fa fa-play watch-modal-button',
69
			'data-toggle'=>'modal',
70
			'data-target'=>'#'.$this->id);
71
72
		echo TbHtml::button(Yii::t('RetrieveMediaWidget', 'Watch'), array_merge(
73
						$commonOptions, $this->getWatchButtonOptions(), $htmlOptions));
74
	}
75
76
}
77