HtmlListItem::initContent()   B
last analyzed

Complexity

Conditions 8
Paths 49

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 8
eloc 24
c 2
b 0
f 0
nc 49
nop 1
dl 0
loc 30
rs 8.4444
1
<?php
2
namespace Ajax\semantic\html\content;
3
4
use Ajax\service\JArray;
5
use Ajax\semantic\html\elements\HtmlList;
6
7
class HtmlListItem extends HtmlAbsractItem {
8
9
	protected $image;
10
11
	public function __construct($identifier, $content = NULL) {
12
		parent::__construct($identifier, "item", $content);
13
	}
14
15
	protected function initContent($content) {
16
		if (\is_array($content)) {
17
			if (JArray::isAssociative($content) === false) {
18
				$icon = $content[0] ?? null;
19
				$title = $content[1] ?? null;
20
				$desc = $content[2] ?? null;
21
			} else {
22
				$icon = $content["icon"] ?? null;
23
				$image = $content["image"] ?? null;
24
				$title = $content["title"] ?? null;
25
				$header = $content["header"] ?? null;
26
				$desc = $content["description"] ?? null;
27
				$items = $content["items"] ?? null;
28
			}
29
			if (isset($icon)) {
30
				$this->setIcon($icon);
31
			}
32
			if (isset($image)) {
33
				$this->setImage($image);
34
			}
35
			if (isset($title)) {
36
				$this->setTitle($title, $desc);
37
			} elseif (isset($header)) {
38
				$this->setTitle($header, $desc, "header");
39
			}
40
			if (isset($items)) {
41
				$this->addList($items);
42
			}
43
		} else {
44
			$this->setContent($content);
45
		}
46
	}
47
48
	public function addList($items = array(), $ordered = false) {
49
		$list = new HtmlList("", $items);
50
		if ($ordered)
51
			$list->setOrdered();
52
		$list->setClass("list");
53
		$this->content["list"] = $list;
54
		return $list;
55
	}
56
57
	public function getList() {
58
		return $this->content["list"];
59
	}
60
61
	public function getItem($index) {
62
		return $this->getList()->getItem($index);
63
	}
64
}
65