Completed
Push — master ( 1d23a1...916f6f )
by Jean-Christophe
03:30
created

HtmlRating   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 2
cbo 3
dl 0
loc 47
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setValue() 0 3 1
A setMax() 0 3 1
A run() 0 4 1
A asStar() 0 3 1
A asHeart() 0 3 1
A setIcon() 0 3 1
1
<?php
2
3
namespace Ajax\semantic\html\modules;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\JsUtils;
7
8
class HtmlRating extends HtmlSemDoubleElement {
9
	protected $_params=array();
10
	/**
11
	 * @param string $identifier
12
	 * @param int $value
13
	 * @param int $max
14
	 * @param string $icon star or heart
15
	 */
16
	public function __construct($identifier, $value,$max=5,$icon="") {
17
		parent::__construct($identifier, "div", "ui {$icon} rating");
18
		$this->setValue($value);
19
		$this->setMax($max);
20
	}
21
22
	/**
23
	 * {@inheritDoc}
24
	 * @see \Ajax\common\html\HtmlDoubleElement::setValue()
25
	 */
26
	public function setValue($value){
27
		$this->setProperty("data-rating", $value);
28
	}
29
30
	public function setMax($max){
31
		$this->setProperty("data-max-rating", $max);
32
	}
33
34
	/**
35
	 * {@inheritDoc}
36
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::run()
37
	 */
38
	public function run(JsUtils $js){
39
		parent::run($js);
40
		return $js->semantic()->rating("#".$this->identifier,$this->_params);
41
	}
42
43
	public function asStar(){
44
		return $this->setIcon();
45
	}
46
47
	public function asHeart(){
48
		return $this->setIcon("heart");
49
	}
50
51
	public function setIcon($icon="star"){
52
		return $this->addToPropertyCtrl("class", $icon, ["star","heart",""]);
53
	}
54
}