Completed
Push — master ( 172c54...50fc65 )
by Jean-Christophe
04:31 queued 01:31
created

HtmlCard::addExtraContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\views;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\elements\HtmlHeader;
7
use Ajax\JsUtils;
8
use Ajax\service\JArray;
9
10
use Ajax\semantic\html\elements\HtmlImage;
11
use Ajax\semantic\html\content\card\HtmlCardContent;
12
use Ajax\semantic\html\content\card\HtmlCardHeaderContent;
13
use Ajax\semantic\html\elements\HtmlReveal;
14
use Ajax\semantic\html\base\constants\RevealType;
15
use Ajax\semantic\html\elements\HtmlButtonGroups;
16
17
class HtmlCard extends HtmlSemDoubleElement {
18
19
	public function __construct($identifier) {
20
		parent::__construct($identifier, "div", "ui card", array ());
21
	}
22
23 View Code Duplication
	private function createContent($content, $baseClass="content") {
0 ignored issues
show
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...
24
		$count=\sizeof($this->content);
25
		$result=new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content);
26
		$result->setClass($baseClass);
27
		return $result;
28
	}
29
30
	private function addElementInContent($key, $element) {
31
		if (\array_key_exists($key, $this->content) === false) {
32
			$this->content[$key]=array ();
33
		}
34
		$this->content[$key][]=$element;
35
		return $element;
36
	}
37
38
	private function getPart($part, $index=NULL) {
39
		if (\array_key_exists($part, $this->content)) {
40
			if (isset($index))
41
				return $this->content[$part][$index];
42
			return $this->content[$part];
43
		}
44
		return NULL;
45
	}
46
47
	public function addHeader($header, $niveau=4, $type="page") {
48
		if (!$header instanceof HtmlHeader) {
49
			$header=new HtmlHeader("header-" . $this->identifier, $niveau, $header, $type);
50
		}
51
		$this->content["header"]=$this->createContent($header);
52
	}
53
54
	public function addImage($image, $title="") {
55
		if (!$image instanceof HtmlImage) {
56
			$image=new HtmlImage("image-" . $this->identifier, $image, $title);
57
		}
58
		$image->setClass("image");
59
		return $this->addElementInContent("content", $image);
60
	}
61
62 View Code Duplication
	public function addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) {
0 ignored issues
show
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...
63
		$reveal=$visibleContent;
64
		if (!$visibleContent instanceof HtmlReveal) {
65
			$reveal=new HtmlReveal("reveral-" . $this->identifier, $visibleContent, $hiddenContent, $type, $attributeType);
66
		}
67
		return $this->addElementInContent("content", $reveal);
68
	}
69
70 View Code Duplication
	public function addRevealImage($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) {
0 ignored issues
show
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...
71
		$reveal=$visibleContent;
72
		if (!$visibleContent instanceof HtmlReveal) {
73
			return $this->addReveal(new HtmlImage("", $visibleContent), new HtmlImage("", $hiddenContent), $type, $attributeType);
74
		}
75
		return $this->addElementInContent("content", $reveal);
76
	}
77
78
	public function addExtraContent($content=array()) {
79
		return $this->addElementInContent("extra-content", $this->createContent($content, "extra content"));
80
	}
81
82
	public function addContent($content=array(), $before=false) {
83
		if (!$content instanceof HtmlCardContent) {
84
			$content=$this->createContent($content);
85
		}
86
		return $this->addElementInContent("content", $content);
87
	}
88
89
	/**
90
	 * @param array $elements
91
	 * @param string $asIcons
92
	 * @return \Ajax\semantic\html\elements\HtmlButtonGroups
93
	 */
94
	public function addButtons($elements=array(), $asIcons=false){
95
		$buttons=new HtmlButtonGroups("buttons-".$this->identifier,$elements,$asIcons);
0 ignored issues
show
Bug introduced by
It seems like $asIcons defined by parameter $asIcons on line 94 can also be of type string; however, Ajax\semantic\html\eleme...onGroups::__construct() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
96
		$this->addElementInContent("content", $buttons);
97
		return $buttons;
98
	}
99
100
101
102
	public function addCardHeaderContent($header, $metas=array(), $description=NULL) {
103
		$count=\sizeof($this->content);
104
		return $this->addElementInContent("content", new HtmlCardHeaderContent("content-" . $count . "-" . $this->identifier, $header, $metas, $description));
105
	}
106
107
	public function addCardContent($content=array()) {
108
		$count=\sizeof($this->content);
109
		return $this->addElementInContent("content", new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content));
110
	}
111
112
	public function getCardContent($index=NULL) {
113
		return $this->getPart("content", $index);
114
	}
115
116
	public function getCardExtraContent() {
117
		return $this->getPart("extra-content");
118
	}
119
120
	public function getCardImage() {
121
		return $this->getPart("image");
122
	}
123
124
	public function getCardHeader() {
125
		return $this->getPart("header");
126
	}
127
128
	/**
129
	 *
130
	 * {@inheritDoc}
131
	 *
132
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
133
	 */
134
	public function compile(JsUtils $js=NULL, &$view=NULL) {
135
		$this->content=JArray::sortAssociative($this->content, [ "header","image","content","extra-content" ]);
136
		return parent::compile($js, $view);
137
	}
138
139
	public function asLink($href="") {
140
		$this->addToProperty("class", "link");
141
		if ($href !== "") {
142
			$this->setProperty("href", $href);
143
		}
144
		return $this;
145
	}
146
}