1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\content\view; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
7
|
|
|
use Ajax\semantic\html\elements\HtmlIcon; |
8
|
|
|
use Ajax\semantic\html\elements\html5\HtmlImg; |
9
|
|
|
|
10
|
|
View Code Duplication |
class HtmlViewContent extends HtmlSemDoubleElement { |
|
|
|
|
11
|
|
|
|
12
|
|
|
public function __construct($identifier, $content=array()) { |
13
|
|
|
parent::__construct($identifier, "div", "content", $content); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
private function addElement($content, $baseClass) { |
17
|
|
|
$count=\sizeof($this->content); |
18
|
|
|
$result=new HtmlSemDoubleElement("element-" . $count . "-" . $this->identifier, "div", $baseClass, $content); |
19
|
|
|
$this->addContent($result); |
20
|
|
|
return $result; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function addMeta($value, $direction=Direction::LEFT) { |
24
|
|
|
if (\array_key_exists("meta", $this->content) === false) { |
25
|
|
|
$this->content["meta"]=new HtmlSemDoubleElement("meta-" . $this->identifier, "div", "meta", array ()); |
26
|
|
|
} |
27
|
|
|
if ($direction === Direction::RIGHT) { |
28
|
|
|
$value=new HtmlSemDoubleElement("", "span", "", $value); |
29
|
|
|
$value->setFloated($direction); |
30
|
|
|
} |
31
|
|
|
$this->content["meta"]->addContent($value); |
32
|
|
|
return $this->content["meta"]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function addImage($src="", $alt="", $size=NULL) { |
36
|
|
|
$image=new HtmlImg("img-", $src, $alt); |
37
|
|
|
if (isset($size)) |
38
|
|
|
$image->setSize($size); |
39
|
|
|
$this->content["image"]=$image; |
40
|
|
|
return $image; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function addMetas($metas) { |
44
|
|
|
if (\is_array($metas)) { |
45
|
|
|
foreach ( $metas as $meta ) { |
46
|
|
|
$this->addMeta($meta); |
47
|
|
|
} |
48
|
|
|
} else |
49
|
|
|
$this->addMeta($metas); |
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function addContentIcon($icon, $caption=NULL, $direction=Direction::LEFT) { |
54
|
|
|
if ($direction === Direction::RIGHT) { |
55
|
|
|
if (isset($caption)) { |
56
|
|
|
$result=new HtmlSemDoubleElement("", "span", "", $caption); |
57
|
|
|
$result->addIcon($icon); |
58
|
|
|
$this->addContent($result); |
59
|
|
|
} else { |
60
|
|
|
$result=new HtmlIcon("", $icon); |
61
|
|
|
$this->addContent($result); |
62
|
|
|
} |
63
|
|
|
$result->setFloated($direction); |
64
|
|
|
} else { |
65
|
|
|
$this->addIcon($icon); |
66
|
|
|
$result=$this->addContent($caption); |
67
|
|
|
} |
68
|
|
|
return $result; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function addContentText($caption, $direction=Direction::LEFT) { |
72
|
|
|
if ($direction === Direction::RIGHT) { |
73
|
|
|
$result=new HtmlSemDoubleElement("", "span", "", $caption); |
74
|
|
|
$this->addContent($result); |
75
|
|
|
$result->setFloated($direction); |
76
|
|
|
} else |
77
|
|
|
$result=$this->addContent($caption); |
78
|
|
|
return $result; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function addContentIcons($icons, $direction=Direction::LEFT) { |
82
|
|
|
foreach ( $icons as $icon ) { |
83
|
|
|
$this->addContentIcon($icon, NULL, $direction); |
84
|
|
|
} |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function addHeaderContent($header, $metas=array(), $description=NULL) { |
89
|
|
|
$this->addElement($header, "header"); |
90
|
|
|
$this->addMetas($metas); |
91
|
|
|
if (isset($description)) { |
92
|
|
|
$this->addElement($description, "description"); |
93
|
|
|
} |
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
} |
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.