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

MediaFlag::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Base class for media flag widgets
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2013-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
abstract class MediaFlag extends CWidget
11
{
12
13
	/**
14
	 * @var string the media file name
15
	 */
16
	public $file;
17
18
	/**
19
	 * @var string the base URL to the flag icons
20
	 */
21
	private $_iconBaseDir;
22
23
	/**
24
	 * Initializes the widget
25
	 */
26
	public function init()
27
	{
28
		$this->_iconBaseDir = Yii::app()->baseUrl.'/images/xbmc-media-flags';
29
	}
30
31
	/**
32
	 * Runs the widget. If an icon can be determined it will be rendered.
33
	 */
34
	public function run()
35
	{
36
		$icon = $this->getIcon();
37
38
		if ($icon !== false)
39
			echo CHtml::image($this->_iconBaseDir.'/'.$icon.'.png');
40
	}
41
42
	/**
43
	 * Returns the name of the icon file that should be displayed, without the 
44
	 * file extension, e.g. "50px-720". If no icon can be determined, false is returned
45
	 * @return string|false the icon name
46
	 */
47
	abstract protected function getIcon();
48
}
49