Completed
Push — master ( b9a8b8...3e8704 )
by Jean-Christophe
03:43
created

HtmlDoubleElement::wrapContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace Ajax\common\html;
4
5
use Ajax\JsUtils;
6
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)===false) {
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
}