Completed
Push — master ( b1fd35...62c434 )
by Jean-Christophe
03:27
created

HtmlViewContent::addMetas()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 7
nc 2
nop 1
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
use Ajax\JsUtils;
10
use Ajax\service\JArray;
11
use Ajax\semantic\html\elements\HtmlButtonGroups;
12
13
class HtmlViewContent extends HtmlSemDoubleElement {
14
	use ContentPartTrait;
15
	public function __construct($identifier, $content=array()) {
16
		parent::__construct($identifier, "div", "content",[]);
17
		$this->setContent($content);
18
	}
19
20
	public function setContent($value){
21
		if (\is_array($value)) {
22
			$header=JArray::getValue($value, "header", 0);
23
			$metas=JArray::getValue($value, "metas", 1);
24
			$description=JArray::getValue($value, "description", 2);
25
			$image=JArray::getValue($value, "image", 3);
26
			$extra=JArray::getValue($value, "extra", 4);
27
			if (isset($image)) {
28
				$this->addImage($image);
29
			}
30
			$this->addHeaderContent($header, $metas, $description,$extra);
31
		} else
32
			$this->addContent($value);
33
	}
34
35 View Code Duplication
	public function addElement($content, $baseClass="",$part=NULL) {
0 ignored issues
show
Unused Code introduced by
The parameter $part is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
36
		$count=\sizeof($this->content);
37
		$result=new HtmlViewContent("element-" . $count . "-" . $this->identifier, $content);
38
		$result->setClass($baseClass);
39
		$this->addContent($result);
40
		return $result;
41
	}
42
43
	public function addMeta($value, $direction=Direction::LEFT) {
44
		if (\array_key_exists("meta", $this->content) === false) {
45
			$this->content["meta"]=new HtmlSemDoubleElement("meta-" . $this->identifier, "div", "meta", array ());
46
		}
47
		if ($direction === Direction::RIGHT) {
48
			$value=new HtmlSemDoubleElement("", "span", "", $value);
49
			$value->setFloated($direction);
50
		}
51
		$this->content["meta"]->addContent($value);
52
		return $this->content["meta"];
53
	}
54
55
	public function addExtra($value) {
56
		if (\array_key_exists("extra", $this->content) === false) {
57
			$this->content["extra"]=new HtmlSemDoubleElement("extra-" . $this->identifier, "div", "extra", array ());
58
		}
59
		$this->content["extra"]->addContent($value);
60
		return $this->content["extra"];
61
	}
62
63
	public function addImage($src="", $alt="", $size=NULL) {
64
		$image=new HtmlImg("img-", $src, $alt);
65
		if (isset($size))
66
			$image->setSize($size);
67
		$this->content['image']=$image;
68
		return $image;
69
	}
70
71
	/**
72
	 * @param array $elements
73
	 * @param boolean $asIcons
74
	 * @param string $part
75
	 * @param boolean $before
76
	 * @return HtmlButtonGroups
77
	 */
78
	public function addContentButtons($elements=array(), $asIcons=false,$part="extra",$before=false){
79
		$buttons=new HtmlButtonGroups("buttons-".$this->identifier,$elements,$asIcons);
80
		$this->addElementInPart($buttons,$part, $before,true);
81
		return $buttons;
82
	}
83
84
	public function addMetas($metas) {
85
		if (\is_array($metas)) {
86
			foreach ( $metas as $meta ) {
87
				$this->addMeta($meta);
88
			}
89
		} else
90
			$this->addMeta($metas);
91
		return $this;
92
	}
93
94
	public function addContentIcon($icon, $caption=NULL, $direction=Direction::LEFT) {
95
		if ($direction === Direction::RIGHT) {
96
			if (isset($caption)) {
97
				$result=new HtmlSemDoubleElement("", "span", "", $caption);
98
				$result->addIcon($icon);
99
				$this->addContent($result);
100
			} else {
101
				$result=new HtmlIcon("", $icon);
102
				$this->addContent($result);
103
			}
104
			$result->setFloated($direction);
105
		} else {
106
			$this->addIcon($icon);
107
			$result=$this->addContent($caption);
108
		}
109
		return $result;
110
	}
111
112
	public function addContentText($caption, $direction=Direction::LEFT) {
113
		if ($direction === Direction::RIGHT) {
114
			$result=new HtmlSemDoubleElement("", "span", "", $caption);
115
			$this->addContent($result);
116
			$result->setFloated($direction);
117
		} else
118
			$result=$this->addContent($caption);
119
		return $result;
120
	}
121
122
	public function addContentIcons($icons, $direction=Direction::LEFT) {
123
		foreach ( $icons as $icon ) {
124
			$this->addContentIcon($icon, NULL, $direction);
125
		}
126
		return $this;
127
	}
128
129
	public function addHeaderContent($header, $metas=array(), $description=NULL,$extra=NULL) {
130
		if(isset($header))
131
			$this->addElement($header, "header");
132
		$this->addMetas($metas);
133
		if (isset($description)) {
134
			$this->addElement($description, "description");
135
		}
136
		if(isset($extra)){
137
			$this->addExtra($extra);
138
		}
139
		return $this;
140
	}
141
142
	public function compile(JsUtils $js=NULL, &$view=NULL) {
143
		//$this->content=JArray::sortAssociative($this->content, [ "header","meta","description","extra" ]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
144
		return parent::compile($js, $view);
145
	}
146
}