Completed
Push — master ( e87f8c...8310f7 )
by Jean-Christophe
02:41
created

HtmlSemDoubleElement::addList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Ajax\semantic\html\base;
4
5
use Ajax\common\html\HtmlDoubleElement;
6
use Ajax\semantic\html\content\InternalPopup;
7
8
use Ajax\semantic\html\base\traits\BaseTrait;
9
use Ajax\semantic\html\modules\HtmlDimmer;
10
use Ajax\semantic\html\elements\HtmlLabel;
11
use Ajax\semantic\html\base\constants\Direction;
12
use Ajax\JsUtils;
13
use Ajax\semantic\html\base\constants\Side;
14
use Ajax\common\html\html5\HtmlList;
15
16
/**
17
 * Base class for Semantic double elements
18
 * @author jc
19
 * @version 1.001
20
 */
21
class HtmlSemDoubleElement extends HtmlDoubleElement {
22
	use BaseTrait;
23
	protected $_popup=NULL;
24
	protected $_dimmer=NULL;
25
	protected $_params=array ();
26
27
28 View Code Duplication
	public function __construct($identifier, $tagName="p", $baseClass="ui", $content=NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
29
		parent::__construct($identifier, $tagName);
30
		$this->_baseClass=$baseClass;
31
		$this->setClass($baseClass);
32
		if (isset($content)) {
33
			$this->content=$content;
34
		}
35
	}
36
37
	/**
38
	 * Defines the popup attributes
39
	 * @param string $variation
40
	 * @param string $popupEvent
41
	 */
42
	public function setPopupAttributes($variation=NULL, $popupEvent=NULL) {
43
		if (isset($this->_popup))
44
			$this->_popup->setAttributes($variation, $popupEvent);
45
	}
46
47
	/**
48
	 * Adds a popup to the element
49
	 * @param string $title
50
	 * @param string $content
51
	 * @param string $variation
52
	 * @param array $params
53
	 * @return HtmlSemDoubleElement
54
	 */
55
	public function addPopup($title="", $content="", $variation=NULL, $params=array()) {
56
		$this->_popup=new InternalPopup($this, $title, $content, $variation, $params);
57
		return $this;
58
	}
59
60
	/**
61
	 * Adds an html popup to the element
62
	 * @param string $html
63
	 * @param string $variation
64
	 * @param array $params
65
	 * @return HtmlSemDoubleElement
66
	 */
67
	public function addPopupHtml($html="", $variation=NULL, $params=array()) {
68
		$this->_popup=new InternalPopup($this);
69
		$this->_popup->setHtml($html);
70
		$this->_popup->setAttributes($variation, $params);
71
		return $this;
72
	}
73
74
	/**
75
	 * Adds a Dimmer to the element
76
	 * @param array $params
77
	 * @param mixed $content
78
	 * @return HtmlDimmer
79
	 */
80
	public function addDimmer($params=array(), $content=NULL) {
81
		$dimmer=new HtmlDimmer("dimmer-" . $this->identifier, $content);
82
		$dimmer->setParams($params);
83
		$dimmer->setContainer($this);
84
		$this->addContent($dimmer);
85
		return $dimmer;
86
	}
87
88
	/**
89
	 * Adds a label to the element
90
	 * @param mixed $label
91
	 * @param boolean $before
92
	 * @param string $icon
93
	 * @return mixed|HtmlLabel
94
	 */
95
	public function addLabel($label, $before=false, $icon=NULL) {
96
		$labelO=$label;
97
		if (\is_object($label) === false) {
98
			$labelO=new HtmlLabel("label-" . $this->identifier, $label);
99
			if (isset($icon))
100
				$labelO->addIcon($icon);
101
		} else {
102
			$labelO->addToPropertyCtrl("class", "label", array ("label" ));
103
		}
104
		$this->addContent($labelO, $before);
105
		return $labelO;
106
	}
107
108
	/**
109
	 * Adds an attached label to the element
110
	 * @param mixed $label
111
	 * @param string $side
112
	 * @param string $direction
113
	 * @param string $icon
114
	 * @return HtmlSemDoubleElement
115
	 */
116
	public function attachLabel($label,$side=Side::TOP,$direction=Direction::NONE,$icon=NULL){
117
		$label=$this->addLabel($label,true,$icon);
118
		$label->setAttached($side,$direction);
119
		return $this;
120
	}
121
122
	/**
123
	 * Transforms the element into a link
124
	 * @return HtmlSemDoubleElement
125
	 */
126
	public function asLink($href=NULL,$target=NULL) {
127
		if (isset($href))
128
			$this->setProperty("href", $href);
129
		if(isset($target))
130
			$this->setProperty("target", $target);
131
		return $this->setTagName("a");
132
	}
133
134
	/**
135
	 * Returns the script displaying the dimmer
136
	 * @param boolean $show
137
	 * @return string
138
	 */
139
	public function jsShowDimmer($show=true) {
140
		$status="hide";
141
		if ($show === true)
142
			$status="show";
143
		return '$("#.' . $this->identifier . ').dimmer("' . $status . '");';
144
	}
145
146
	/**
147
	 * {@inheritDoc}
148
	 * @see BaseHtml::compile()
149
	 */
150
	public function compile(JsUtils $js=NULL, &$view=NULL) {
151
	if (isset($this->_popup))
152
			$this->_popup->compile($js);
153
		return parent::compile($js, $view);
154
	}
155
156
	/**
157
	 * {@inheritDoc}
158
	 * @see HtmlDoubleElement::run()
159
	 */
160
	public function run(JsUtils $js) {
161
		$this->_bsComponent=$js->semantic()->generic("#" . $this->identifier);
162
		parent::run($js);
163
		$this->addEventsOnRun($js);
164
		if (isset($this->_popup)) {
165
			$this->_popup->run($js);
166
		}
167
		return $this->_bsComponent;
168
	}
169
170
	public function addList($elements,$ordered=false){
171
		$list=new HtmlList("list-".$this->identifier,$elements);
172
		$list->setOrdered($ordered);
173
		$list->setClass("ui list");
174
		$this->addContent($list);
175
	}
176
177
	/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
178
	 * public function __call($name, $arguments){
179
	 * $type=\substr($name, 0,3);
180
	 * $name=\strtolower(\substr($name, 3));
181
	 * $names=\array_merge($this->_variations,$this->_states);
182
	 * $argument=@$arguments[0];
183
	 * if(\array_search($name, $names)!==FALSE){
184
	 * switch ($type){
185
	 * case "set":
186
	 * if($argument===false){
187
	 * $this->removePropertyValue("class", $name);
188
	 * }else {
189
	 * $this->setProperty("class", $this->_baseClass." ".$name);
190
	 * }
191
	 * break;
192
	 * case "add":
193
	 * $this->addToPropertyCtrl("class", $name,array($name));
194
	 * break;
195
	 * default:
196
	 * throw new \Exception("Méthode ".$type.$name." inexistante.");
197
	 * }
198
	 * }else{
199
	 * throw new \Exception("Propriété ".$name." inexistante.");
200
	 * }
201
	 * return $this;
202
	 * }
203
	 */
204
}
205