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

HtmlCardGroups::setWide()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\views;
4
5
use Ajax\semantic\html\base\HtmlSemCollection;
6
use Ajax\service\JArray;
7
use Ajax\semantic\html\base\constants\Wide;
8
9
class HtmlCardGroups extends HtmlSemCollection {
10
11
	public function __construct($identifier, $cards=array()) {
12
		parent::__construct($identifier, "div", "ui cards");
13
		$this->addItems($cards);
14
	}
15
16
	protected function createItem($value) {
17
		$result=new HtmlCard("card-" . $this->count());
18
		if (\is_array($value)) {
19
			$header=JArray::getValue($value, "header", 0);
20
			$metas=JArray::getValue($value, "metas", 1);
21
			$description=JArray::getValue($value, "description", 2);
22
			$image=JArray::getValue($value, "image", 3);
23
			$extra=JArray::getValue($value, "extra", 4);
24
			if (isset($image)) {
25
				$result->addImage($image);
26
			}
27
			$result->addCardHeaderContent($header, $metas, $description);
28
			if (isset($extra)) {
29
				$result->addExtraContent($extra);
30
			}
31
		} else
32
			$result->addCardContent($value);
33
		return $result;
34
	}
35
36
	/**
37
	 * Defines the cards width (alias for setWidth)
38
	 * @param int $wide
39
	 */
40
	public function setWide($wide) {
41
		$wide=Wide::getConstants()["W" . $wide];
42
		return $this->addToPropertyCtrl("class", $wide, Wide::getConstants());
43
	}
44
45
	public function newCard($identifier) {
46
		return new HtmlCard($identifier);
47
	}
48
49
	public function getCard($index) {
50
		return $this->getItem($index);
51
	}
52
53
	public function getCardContent($cardIndex, $contentIndex) {
54
		$card=$this->getItem($cardIndex);
55
		if (isset($card)) {
56
			return $card->getCardContent($contentIndex);
57
		}
58
	}
59
60
	public function fromDatabaseObject($object, $function) {
61
		return $this->addItem($function($object));
62
	}
63
}