Completed
Push — master ( 73e21a...085edf )
by Jean-Christophe
04:37
created

HtmlAbsractItem   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
initContent() 0 1 ?
A setIcon() 0 3 1
A setImage() 0 5 1
A createContent() 0 4 1
A setTitle() 0 12 3
A getPart() 0 4 1
A setActive() 0 5 1
A asLink() 0 6 2
A compile() 0 5 2
1
<?php
2
3
namespace Ajax\semantic\html\content;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\elements\HtmlIcon;
7
use Ajax\JsUtils;
8
9
use Ajax\service\JArray;
10
use Ajax\semantic\html\elements\html5\HtmlImg;
11
12
abstract class HtmlAbsractItem extends HtmlSemDoubleElement {
13
14
	public function __construct($identifier, $baseClass,$content=NULL) {
15
		parent::__construct($identifier, "div", $baseClass);
16
		$this->content=array();
17
		$this->initContent($content);
18
	}
19
20
	protected abstract function initContent($content);
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
21
22
	public function setIcon($icon){
23
		$this->content["icon"]=new HtmlIcon("icon-".$this->identifier, $icon);
24
	}
25
26
	public function setImage($image){
27
		$image=new HtmlImg("icon-".$this->identifier, $image);
28
		$image->asAvatar();
29
		$this->content["image"]=$image;
30
	}
31
32
	private function createContent(){
33
		$this->content["content"]=new HtmlSemDoubleElement("content-".$this->identifier,"div","content");
34
		return $this->content["content"];
35
	}
36
37
	public function setTitle($title,$description=NULL,$baseClass="title"){
38
		$title=new HtmlSemDoubleElement("","div",$baseClass,$title);
39
		if(\array_key_exists("content", $this->content)===false){
40
			$this->createContent();
41
		}
42
		$this->content["content"]->addContent($title);
43
		if(isset($description)){
44
			$description=new HtmlSemDoubleElement("","div","description",$description);
45
			$this->content["content"]->addContent($description);
46
		}
47
		return $this;
48
	}
49
50
	public function getPart($partName="header"){
51
		$content=\array_merge($this->content["content"]->getContent(),array(@$this->content["icon"],@$this->content["image"]));
52
		return $this->getElementByPropertyValue("class", $partName, $content);
53
	}
54
55
	public function setActive(){
56
		$this->setTagName("div");
57
		$this->removeProperty("href");
58
		return $this->addToPropertyCtrl("class", "active", array("active"));
59
	}
60
61
	public function asLink($href=NULL,$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...
62
		$this->setTagName("a");
63
		if(isset($href))
64
			$this->setProperty("href", $href);
65
		return $this;
66
	}
67
68
	/**
69
	 *
70
	 * {@inheritDoc}
71
	 *
72
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
73
	 */
74
	public function compile(JsUtils $js=NULL, $view=NULL) {
75
		if(\is_array($this->content))
76
			$this->content=JArray::sortAssociative($this->content, [ "icon","image","content" ]);
77
		return parent::compile($js, $view);
78
	}
79
}