1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\elements; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\common\html\html5\HtmlImg; |
7
|
|
|
use Ajax\common\html\HtmlDoubleElement; |
8
|
|
|
|
9
|
|
|
class HtmlLabel extends HtmlSemDoubleElement { |
10
|
|
|
|
11
|
|
|
public function __construct($identifier,$caption="",$tagName="div") { |
12
|
|
|
parent::__construct($identifier,$tagName); |
13
|
|
|
$this->setProperty("class", "ui label"); |
14
|
|
|
$this->content=$caption; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param string $side |
19
|
|
|
* @return \Ajax\semantic\html\elements\HtmlLabel |
20
|
|
|
*/ |
21
|
|
|
public function setPointing($side=""){ |
22
|
|
|
return $this->addToPropertyCtrl("class", $side." pointing",array("right pointing","left pointing"," pointing")); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $side |
27
|
|
|
* @return \Ajax\semantic\html\elements\HtmlLabel |
28
|
|
|
*/ |
29
|
|
|
public function toCorner($side="left"){ |
30
|
|
|
return $this->addToPropertyCtrl("class", $side." corner",array("right corner","left corner")); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return \Ajax\semantic\html\elements\HtmlLabel |
35
|
|
|
*/ |
36
|
|
|
public function asTag(){ |
37
|
|
|
return $this->addToProperty("class", "tag"); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function setBasic(){ |
41
|
|
|
return $this->addToProperty("class", "basic"); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Adds an icon before or after |
46
|
|
|
* @param string|HtmlIcon $icon |
47
|
|
|
* @param boolean $before |
48
|
|
|
* @return \Ajax\semantic\html\elements\HtmlIcon |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function addIcon($icon,$before=true){ |
|
|
|
|
51
|
|
|
$iconO=$icon; |
52
|
|
|
if(\is_string($icon)){ |
53
|
|
|
$iconO=new HtmlIcon("icon-".$this->identifier, $icon); |
54
|
|
|
} |
55
|
|
|
$this->addContent($iconO,$before); |
56
|
|
|
return $iconO; |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Adds an image to emphasize |
61
|
|
|
* @param string $src |
62
|
|
|
* @param string $alt |
63
|
|
|
* @param string $before |
64
|
|
|
* @return \Ajax\semantic\html\elements\HtmlLabel |
65
|
|
|
*/ |
66
|
|
|
public function addImage($src,$alt="",$before=true){ |
67
|
|
|
$this->addToProperty("class", "image"); |
68
|
|
|
return $this->addContent(new HtmlImg("image-".$this->identifier,$src,$alt),$before); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $detail |
73
|
|
|
* @return \Ajax\common\html\HtmlDoubleElement |
74
|
|
|
*/ |
75
|
|
|
public function addDetail($detail){ |
76
|
|
|
$div=new HtmlDoubleElement("detail-".$this->identifier,$this->tagName); |
77
|
|
|
$div->setClass("detail"); |
78
|
|
|
$div->setContent($detail); |
79
|
|
|
$this->addContent($div); |
80
|
|
|
return $div; |
81
|
|
|
} |
82
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.