Passed
Push — master ( 39f3dd...5f0b05 )
by Jean-Christophe
07:53
created

HtmlEmoji::asLoader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
namespace Ajax\semantic\html\elements;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
7
8
/**
9
 * Semantic Emoji component
10
 * Ajax\semantic\html\elements$HtmlIcon
11
 * This class is part of phpMv-ui
12
 * @author jcheron <[email protected]>
13
 * @version 1.0.0
14
 *
15
 */
16
class HtmlEmoji extends HtmlSemDoubleElement {
17
	protected $_emoji;
18
19
	public function __construct($identifier, $emoji) {
20
		parent::__construct($identifier, "em", "", NULL);
21
		$this->setEmoji($emoji);
22
	}
23
24
	public function getEmoji() {
25
		return $this->_emoji;
26
	}
27
28
	/**
29
	 * sets the emoji
30
	 * @param string $emoji
31
	 * @return HtmlEmoji
32
	 */
33
	public function setEmoji($emoji) {
34
		if (isset($this->_emoji)) {
35
			$this->removePropertyValue("data-emoji", $this->_emoji);
36
		}
37
		$this->_emoji=$emoji;
38
		$this->addToProperty("data-emoji", $emoji);
39
		return $this;
40
	}
41
42
	/**
43
	 * Emoji used as a simple loader
44
	 * @return HtmlEmoji
45
	 */
46
	public function asLoader() {
47
		return $this->addToProperty("class", "loading");
48
	}
49
50
	/**
51
	 * icon formatted as a link
52
	 * @param string $href
53
	 * @param string $target
54
	 * @return HtmlEmoji
55
	 */
56
	public function asLink($href=NULL,$target=NULL) {
57
		if (isset($href)) {
58
			$_target="";
59
			if(isset($target))
60
				$_target="target='{$target}'";
61
			$this->wrap("<a href='" . $href . "' {$_target}>", "</a>");
62
		}
63
		return $this->addToProperty("class", "link");
64
	}
65
66
	public function addLabel($label, $before=false, $emoji='slight_smile') {
67
		if($before)
68
			$this->wrap($label);
69
		else
70
			$this->wrap("", $label);
71
		if(isset($emoji))
72
			$this->setEmoji($emoji);
73
		return $this;
74
	}
75
76
}
77