Completed
Push — master ( b535d8...118a49 )
by Jean-Christophe
03:00
created

HtmlDoubleElement   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 13
Bugs 0 Features 1
Metric Value
wmc 18
c 13
b 0
f 1
lcom 2
cbo 4
dl 0
loc 92
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setContent() 0 4 1
A getContent() 0 3 1
A addContent() 0 12 3
B run() 0 12 5
A addBadge() 0 6 1
A addLabel() 0 6 1
A addGlyph() 0 6 1
A setValue() 0 2 1
A wrapContent() 0 5 1
A wrapContentWithGlyph() 0 8 2
1
<?php
2
3
namespace Ajax\bootstrap\html\base;
4
5
use Ajax\JsUtils;
6
use Ajax\bootstrap\html\HtmlBadge;
7
use Ajax\bootstrap\html\HtmlLabel;
8
use Ajax\bootstrap\html\HtmlGlyphicon;
9
10
class HtmlDoubleElement extends HtmlSingleElement {
11
	/**
12
	 *
13
	 * @var mixed
14
	 */
15
	protected $content;
16
	protected $wrapContentBefore="";
17
	protected $wrapContentAfter="";
18
19
	public function __construct($identifier, $tagName="p") {
20
		parent::__construct($identifier, $tagName);
21
		$this->_template="<%tagName% id='%identifier%' %properties%>%wrapContentBefore%%content%%wrapContentAfter%</%tagName%>";
22
	}
23
24
	public function setContent($content) {
25
		$this->content=$content;
26
		return $this;
27
	}
28
29
	public function getContent() {
30
		return $this->content;
31
	}
32
33
	public function addContent($content) {
34
		if (is_array($this->content)===false) {
35
			$newContent=array ();
36
			if (isset($this->content))
37
				$newContent []=$this->content;
38
			$newContent []=$content;
39
			$this->content=$newContent;
40
		} else {
41
			$this->content []=$content;
42
		}
43
		return $this;
44
	}
45
46
	/*
47
	 * (non-PHPdoc)
48
	 * @see \Ajax\bootstrap\html\HtmlSingleElement::run()
49
	 */
50
	public function run(JsUtils $js) {
51
		parent::run($js);
52
		if ($this->content instanceof HtmlDoubleElement) {
53
			$this->content->run($js);
54
		} else if (is_array($this->content)) {
55
			foreach ( $this->content as $itemContent ) {
56
				if ($itemContent instanceof HtmlDoubleElement) {
57
					$itemContent->run($js);
58
				}
59
			}
60
		}
61
	}
62
63
	public function addBadge($caption, $leftSeparator="&nbsp;") {
64
		$badge=new HtmlBadge("badge-".$this->identifier, $caption);
65
		$badge->wrap($leftSeparator);
66
		$this->addContent($badge);
67
		return $this;
68
	}
69
70
	public function addLabel($caption, $style="label-default", $leftSeparator="&nbsp;") {
71
		$label=new HtmlLabel("label-".$this->identifier, $caption, $style);
72
		$label->wrap($leftSeparator);
73
		$this->addContent($label);
74
		return $this;
75
	}
76
77
	public function addGlyph($glyphicon,$index=0){
78
		$glyph=new HtmlGlyphicon("");
79
		$glyph->setGlyphicon($glyphicon);
80
		$this->addContent($glyph);
81
		return $this;
82
	}
83
84
	public function setValue($value) {
85
	}
86
87
	public function wrapContent($before, $after="") {
88
		$this->wrapContentBefore.=$before;
89
		$this->wrapContentAfter=$after.$this->wrapContentAfter;
90
		return $this;
91
	}
92
93
	public function wrapContentWithGlyph($glyphBefore,$glyphAfter=""){
94
		$before=HtmlGlyphicon::getGlyphicon($glyphBefore)."&nbsp;";
95
		$after="";
96
		if($glyphAfter!==""){
97
			$after="&nbsp;".HtmlGlyphicon::getGlyphicon($glyphAfter);
98
		}
99
		return $this->wrapContent($before,$after);
100
	}
101
}