Completed
Push — master ( a95fe7...9db12b )
by Jean-Christophe
03:11
created

HtmlViewGroups::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\content\view;
4
5
use Ajax\semantic\html\base\HtmlSemCollection;
6
use Ajax\service\JArray;
7
use Ajax\semantic\html\base\constants\Wide;
8
use Ajax\JsUtils;
9
10
abstract class HtmlViewGroups extends HtmlSemCollection {
11
12
	public function __construct($identifier, $uiClass,$items=array()) {
13
		parent::__construct($identifier, "div", $uiClass);
14
		$this->addItems($items);
15
	}
16
17
	abstract protected function createElement();
18
19
	protected function createItem($value) {
20
		$result=$this->createElement();
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
				$result->addImage($image);
29
			}
30
			$result->addItemHeaderContent($header, $metas, $description);
31
			if (isset($extra)) {
32
				$result->addExtraContent($extra);
33
			}
34
		} else
35
			$result->addItemContent($value);
36
		return $result;
37
	}
38
39
	/**
40
	 * Defines the ites width (alias for setWidth)
41
	 * @param int $wide
42
	 */
43
	public function setWide($wide) {
44
		$wide=Wide::getConstants()["W" . $wide];
45
		return $this->addToPropertyCtrl("class", $wide, Wide::getConstants());
46
	}
47
48
	abstract public function newItem($identifier);
49
50
51
	public function getItemContent($itemIndex, $contentIndex) {
52
		$item=$this->getItem($itemIndex);
53
		if (isset($item)) {
54
			return $item->getItemContent($contentIndex);
55
		}
56
	}
57
58
	public function fromDatabaseObject($object, $function) {
59
		return $this->addItem($function($object));
60
	}
61
62
	public function run(JsUtils $js){
63
		$result=parent::run($js);
64
		return $result->setItemSelector(".item");
65
	}
66
}
67