Completed
Push — master ( 98392d...8b7375 )
by Jean-Christophe
04:05
created

HtmlCard::getCardExtraContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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
use Phalcon\Mvc\View;
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
16
class HtmlCard extends HtmlSemDoubleElement {
17
18
	public function __construct($identifier) {
19
		parent::__construct($identifier, "div", "ui card", array ());
20
	}
21
22 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...
23
		$count=\sizeof($this->content);
24
		$result=new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content);
25
		$result->setClass($baseClass);
26
		return $result;
27
	}
28
29
	private function addElementInContent($key, $element) {
30
		if (\array_key_exists($key, $this->content) === false) {
31
			$this->content[$key]=array ();
32
		}
33
		$this->content[$key][]=$element;
34
		return $element;
35
	}
36
37
	private function getPart($part, $index=NULL) {
38
		if (\array_key_exists($part, $this->content)) {
39
			if (isset($index))
40
				return $this->content[$part][$index];
41
			return $this->content[$part];
42
		}
43
		return NULL;
44
	}
45
46
	public function addHeader($header, $niveau=4, $type="page") {
47
		if (!$header instanceof HtmlHeader) {
48
			$header=new HtmlHeader("header-" . $this->identifier, $niveau, $header, $type);
49
		}
50
		$this->content["header"]=$this->createContent($header);
51
	}
52
53
	public function addImage($image, $title="") {
54
		if (!$image instanceof HtmlImage) {
55
			$image=new HtmlImage("image-" . $this->identifier, $image, $title);
56
		}
57
		$image->setClass("image");
58
		return $this->addElementInContent("content", $image);
59
	}
60
61 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...
62
		$reveal=$visibleContent;
63
		if (!$visibleContent instanceof HtmlReveal) {
64
			$reveal=new HtmlReveal("reveral-" . $this->identifier, $visibleContent, $hiddenContent, $type, $attributeType);
65
		}
66
		return $this->addElementInContent("content", $reveal);
67
	}
68
69 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...
70
		$reveal=$visibleContent;
71
		if (!$visibleContent instanceof HtmlReveal) {
72
			return $this->addReveal(new HtmlImage("", $visibleContent), new HtmlImage("", $hiddenContent), $type, $attributeType);
73
		}
74
		return $this->addElementInContent("content", $reveal);
75
	}
76
77
	public function addExtraContent($content=array()) {
78
		return $this->addElementInContent("extra-content", $this->createContent($content, "extra content"));
79
	}
80
81
	public function addContent($content=array(), $before=false) {
82
		if (!$content instanceof HtmlCardContent) {
83
			$content=$this->createContent($content);
84
		}
85
		return $this->addElementInContent("content", $content);
86
	}
87
88
	public function addCardHeaderContent($header, $metas=array(), $description=NULL) {
89
		$count=\sizeof($this->content);
90
		return $this->addElementInContent("content", new HtmlCardHeaderContent("content-" . $count . "-" . $this->identifier, $header, $metas, $description));
91
	}
92
93
	public function addCardContent($content=array()) {
94
		$count=\sizeof($this->content);
95
		return $this->addElementInContent("content", new HtmlCardContent("content-" . $count . "-" . $this->identifier, $content));
96
	}
97
98
	public function getCardContent($index=NULL) {
99
		return $this->getPart("content", $index);
100
	}
101
102
	public function getCardExtraContent() {
103
		return $this->getPart("extra-content");
104
	}
105
106
	public function getCardImage() {
107
		return $this->getPart("image");
108
	}
109
110
	public function getCardHeader() {
111
		return $this->getPart("header");
112
	}
113
114
	/**
115
	 *
116
	 * {@inheritDoc}
117
	 *
118
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
119
	 */
120
	public function compile(JsUtils $js=NULL, View $view=NULL) {
121
		$this->content=JArray::sortAssociative($this->content, [ "header","image","content","extra-content" ]);
122
		return parent::compile($js, $view);
123
	}
124
125
	public function asLink($href="") {
126
		$this->addToProperty("class", "link");
127
		if ($href !== "") {
128
			$this->setProperty("href", $href);
129
		}
130
		return $this;
131
	}
132
}