1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\common\html; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use Ajax\JsUtils; |
7
|
|
|
class HtmlDoubleElement extends HtmlSingleElement { |
8
|
|
|
/** |
9
|
|
|
* |
10
|
|
|
* @var mixed |
11
|
|
|
*/ |
12
|
|
|
protected $content; |
13
|
|
|
protected $wrapContentBefore=""; |
14
|
|
|
protected $wrapContentAfter=""; |
15
|
|
|
|
16
|
|
|
public function __construct($identifier, $tagName="p") { |
17
|
|
|
parent::__construct($identifier, $tagName); |
18
|
|
|
$this->_template='<%tagName% id="%identifier%" %properties%>%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function setContent($content) { |
22
|
|
|
$this->content=$content; |
23
|
|
|
return $this; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getContent() { |
27
|
|
|
return $this->content; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function addContent($content,$before=false) { |
31
|
|
|
if (!\is_array($this->content)) { |
32
|
|
|
if(isset($this->content)) |
33
|
|
|
$this->content=array ($this->content); |
34
|
|
|
else |
35
|
|
|
$this->content=array(); |
36
|
|
|
} |
37
|
|
|
if($before) |
38
|
|
|
array_unshift($this->content,$content); |
39
|
|
|
else |
40
|
|
|
$this->content []=$content; |
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/* |
45
|
|
|
* (non-PHPdoc) |
46
|
|
|
* @see \Ajax\bootstrap\html\HtmlSingleElement::run() |
47
|
|
|
*/ |
48
|
|
|
public function run(JsUtils $js) { |
49
|
|
|
parent::run($js); |
50
|
|
|
if ($this->content instanceof HtmlDoubleElement) { |
51
|
|
|
$this->content->run($js); |
52
|
|
|
} else if (\is_array($this->content)) { |
53
|
|
|
foreach ( $this->content as $itemContent ) { |
54
|
|
|
if ($itemContent instanceof HtmlDoubleElement) { |
55
|
|
|
$itemContent->run($js); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setValue($value) { |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function wrapContent($before, $after="") { |
65
|
|
|
$this->wrapContentBefore.=$before; |
66
|
|
|
$this->wrapContentAfter=$after.$this->wrapContentAfter; |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getContentInstances($class){ |
71
|
|
|
return $this->_getContentInstances($class,$this->content); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function _getContentInstances($class,$content){ |
75
|
|
|
$instances=[]; |
76
|
|
|
if($content instanceof $class){ |
77
|
|
|
$instances[]=$content; |
78
|
|
|
}elseif($content instanceof HtmlDoubleElement){ |
79
|
|
|
$instances=\array_merge($instances,$content->getContentInstances($class)); |
|
|
|
|
80
|
|
|
}elseif (\is_array($content)){ |
81
|
|
|
foreach ($content as $element){ |
82
|
|
|
$instances=\array_merge($instances,$this->_getContentInstances($class, $element)); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
return $instances; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Transforms the element into a link |
90
|
|
|
* @return HtmlDoubleElement |
91
|
|
|
*/ |
92
|
|
|
public function asLink($href=NULL,$target=NULL) { |
93
|
|
|
if (isset($href)) |
94
|
|
|
$this->setProperty("href", $href); |
95
|
|
|
if(isset($target)) |
96
|
|
|
$this->setProperty("target", $target); |
97
|
|
|
return $this->setTagName("a"); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.