Completed
Push — master ( 8b7375...189ad5 )
by Jean-Christophe
03:49
created

HtmlIcon::setCircular()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\elements;
4
5
use Ajax\semantic\html\base\HtmlSemSingleElement;
6
7
/**
8
 * Semantic Icon component
9
 * @see http://semantic-ui.com/elements/icon.html
10
 * @author jc
11
 * @version 1.001
12
 */
13
class HtmlIcon extends HtmlSemSingleElement {
14
	protected $_icon;
15
16
	public function __construct($identifier, $icon) {
17
		parent::__construct($identifier, "i", "icon");
18
		$this->setIcon($icon);
19
	}
20
21
	public function getIcon() {
22
		return $this->_icon;
23
	}
24
25
	/**
26
	 * sets the icon
27
	 * @param string $icon
28
	 * @return \Ajax\semantic\html\HtmlIcon
29
	 */
30
	public function setIcon($icon) {
31
		if (isset($this->_icon)) {
32
			$this->removePropertyValue("class", $this->_icon);
33
		}
34
		$this->_icon=$icon;
35
		$this->addToProperty("class", $icon);
36
		return $this;
37
	}
38
39
	/**
40
	 * adds an icon in icon element
41
	 * @param string $icon
42
	 * @return \Ajax\semantic\html\HtmlIcon
43
	 */
44
	public function addToIcon($icon) {
45
		$this->addToProperty("class", $icon);
46
		return $this->addToMember($this->_icon, $icon);
47
	}
48
49
	/**
50
	 * Icon used as a simple loader
51
	 * @return \Ajax\semantic\html\HtmlIcon
52
	 */
53
	public function asLoader() {
54
		return $this->addToProperty("class", "loading");
55
	}
56
57
	/**
58
	 * An icon can be fitted, without any space to the left or right of it.
59
	 * @return \Ajax\semantic\html\HtmlIcon
60
	 */
61
	public function setFitted() {
62
		return $this->addToProperty("class", "fitted");
63
	}
64
65
	/**
66
	 *
67
	 * @param string $sens horizontally or vertically
68
	 * @return \Ajax\semantic\html\HtmlIcon
69
	 */
70
	public function setFlipped($sens="horizontally") {
71
		return $this->addToProperty("class", "flipped " . $sens);
72
	}
73
74
	/**
75
	 *
76
	 * @param string $sens clockwise or counterclockwise
77
	 * @return \Ajax\semantic\html\HtmlIcon
78
	 */
79
	public function setRotated($sens="clockwise") {
80
		return $this->addToProperty("class", "rotated " . $sens);
81
	}
82
83
	/**
84
	 * icon formatted as a link
85
	 * @return \Ajax\semantic\html\HtmlIcon
86
	 */
87
	public function asLink($href=NULL) {
88
		if (isset($href)) {
89
			$this->wrap("<a href='" . $href . "'>", "</a>");
90
		}
91
		return $this->addToProperty("class", "link");
92
	}
93
94
	public function setOutline() {
95
		return $this->addToProperty("class", "outline");
96
	}
97
98
	/**
99
	 *
100
	 * @param string $inverted
101
	 * @return \Ajax\semantic\html\HtmlIcon
102
	 */
103
	public function setBordered($inverted=false) {
104
		$invertedStr="";
105
		if ($inverted !== false)
106
			$invertedStr=" inverted";
107
		return $this->addToProperty("class", "bordered" . $invertedStr);
108
	}
109
110
	/**
111
	 *
112
	 * @return \Ajax\semantic\html\HtmlIcon
113
	 */
114
	public function toCorner() {
115
		return $this->addToProperty("class", "corner");
116
	}
117
118
	public function addLabel($label) {
119
		$this->wrap("", $label);
120
		return $this;
121
	}
122
123
	public static function label($identifier, $icon, $label) {
124
		$result=new HtmlIcon($identifier, $icon);
125
		return $result->addLabel($label);
126
	}
127
}