Skip to content

Commit b7a7dde

Browse files
committed
view Items added
1 parent fcfed56 commit b7a7dde

File tree

9 files changed

+409
-181
lines changed

9 files changed

+409
-181
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Ajax\semantic\html\content\view;
4+
5+
6+
class HtmlItem extends HtmlViewItem {
7+
8+
public function __construct($identifier) {
9+
parent::__construct($identifier, "item", array ());
10+
}
11+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace Ajax\semantic\html\content\view;
4+
5+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6+
use Ajax\semantic\html\base\constants\Direction;
7+
use Ajax\semantic\html\elements\HtmlIcon;
8+
use Ajax\semantic\html\elements\html5\HtmlImg;
9+
10+
class HtmlViewContent extends HtmlSemDoubleElement {
11+
12+
public function __construct($identifier, $content=array()) {
13+
parent::__construct($identifier, "div", "content", $content);
14+
}
15+
16+
private function addElement($content, $baseClass) {
17+
$count=\sizeof($this->content);
18+
$result=new HtmlSemDoubleElement("element-" . $count . "-" . $this->identifier, "div", $baseClass, $content);
19+
$this->addContent($result);
20+
return $result;
21+
}
22+
23+
public function addMeta($value, $direction=Direction::LEFT) {
24+
if (\array_key_exists("meta", $this->content) === false) {
25+
$this->content["meta"]=new HtmlSemDoubleElement("meta-" . $this->identifier, "div", "meta", array ());
26+
}
27+
if ($direction === Direction::RIGHT) {
28+
$value=new HtmlSemDoubleElement("", "span", "", $value);
29+
$value->setFloated($direction);
30+
}
31+
$this->content["meta"]->addContent($value);
32+
return $this->content["meta"];
33+
}
34+
35+
public function addImage($src="", $alt="", $size=NULL) {
36+
$image=new HtmlImg("img-", $src, $alt);
37+
if (isset($size))
38+
$image->setSize($size);
39+
$this->content["image"]=$image;
40+
return $image;
41+
}
42+
43+
public function addMetas($metas) {
44+
if (\is_array($metas)) {
45+
foreach ( $metas as $meta ) {
46+
$this->addMeta($meta);
47+
}
48+
} else
49+
$this->addMeta($metas);
50+
return $this;
51+
}
52+
53+
public function addContentIcon($icon, $caption=NULL, $direction=Direction::LEFT) {
54+
if ($direction === Direction::RIGHT) {
55+
if (isset($caption)) {
56+
$result=new HtmlSemDoubleElement("", "span", "", $caption);
57+
$result->addIcon($icon);
58+
$this->addContent($result);
59+
} else {
60+
$result=new HtmlIcon("", $icon);
61+
$this->addContent($result);
62+
}
63+
$result->setFloated($direction);
64+
} else {
65+
$this->addIcon($icon);
66+
$result=$this->addContent($caption);
67+
}
68+
return $result;
69+
}
70+
71+
public function addContentText($caption, $direction=Direction::LEFT) {
72+
if ($direction === Direction::RIGHT) {
73+
$result=new HtmlSemDoubleElement("", "span", "", $caption);
74+
$this->addContent($result);
75+
$result->setFloated($direction);
76+
} else
77+
$result=$this->addContent($caption);
78+
return $result;
79+
}
80+
81+
public function addContentIcons($icons, $direction=Direction::LEFT) {
82+
foreach ( $icons as $icon ) {
83+
$this->addContentIcon($icon, NULL, $direction);
84+
}
85+
return $this;
86+
}
87+
88+
public function addHeaderContent($header, $metas=array(), $description=NULL) {
89+
$this->addElement($header, "header");
90+
$this->addMetas($metas);
91+
if (isset($description)) {
92+
$this->addElement($description, "description");
93+
}
94+
return $this;
95+
}
96+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
9+
abstract class HtmlViewGroups extends HtmlSemCollection {
10+
11+
public function __construct($identifier, $uiClass,$items=array()) {
12+
parent::__construct($identifier, "div", $uiClass);
13+
$this->addItems($items);
14+
}
15+
16+
abstract protected function createElement();
17+
18+
protected function createItem($value) {
19+
$result=$this->createElement();
20+
if (\is_array($value)) {
21+
$header=JArray::getValue($value, "header", 0);
22+
$metas=JArray::getValue($value, "metas", 1);
23+
$description=JArray::getValue($value, "description", 2);
24+
$image=JArray::getValue($value, "image", 3);
25+
$extra=JArray::getValue($value, "extra", 4);
26+
if (isset($image)) {
27+
$result->addImage($image);
28+
}
29+
$result->addItemHeaderContent($header, $metas, $description);
30+
if (isset($extra)) {
31+
$result->addExtraContent($extra);
32+
}
33+
} else
34+
$result->addItemContent($value);
35+
return $result;
36+
}
37+
38+
/**
39+
* Defines the ites width (alias for setWidth)
40+
* @param int $wide
41+
*/
42+
public function setWide($wide) {
43+
$wide=Wide::getConstants()["W" . $wide];
44+
return $this->addToPropertyCtrl("class", $wide, Wide::getConstants());
45+
}
46+
47+
abstract public function newItem($identifier);
48+
49+
50+
public function getItemContent($itemIndex, $contentIndex) {
51+
$item=$this->getItem($itemIndex);
52+
if (isset($item)) {
53+
return $item->getItemContent($contentIndex);
54+
}
55+
}
56+
57+
public function fromDatabaseObject($object, $function) {
58+
return $this->addItem($function($object));
59+
}
60+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Ajax\semantic\html\content\view;
4+
5+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6+
use Ajax\JsUtils;
7+
8+
use Ajax\service\JArray;
9+
10+
class HtmlViewHeaderContent extends HtmlViewContent {
11+
12+
public function __construct($identifier, $header=NULL, $metas=array(), $description=NULL,$extra=null) {
13+
parent::__construct($identifier, array ());
14+
if (isset($header)) {
15+
$this->setHeader($header);
16+
}
17+
$this->addMetas($metas);
18+
if (isset($description)) {
19+
$this->setDescription($description);
20+
}
21+
if (isset($extra)) {
22+
$this->setExtra($extra);
23+
}
24+
}
25+
26+
public function setDescription($value) {
27+
$this->content["description"]=new HtmlSemDoubleElement("description-" . $this->identifier, "div", "description", $value);
28+
}
29+
30+
public function setHeader($value) {
31+
$this->content["header"]=new HtmlSemDoubleElement("header-" . $this->identifier, "a", "header", $value);
32+
}
33+
34+
public function setExtra($value) {
35+
$this->content["extra"]=new HtmlSemDoubleElement("extra-" . $this->identifier, "a", "extra", $value);
36+
}
37+
38+
/**
39+
*
40+
* {@inheritDoc}
41+
*
42+
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
43+
*/
44+
public function compile(JsUtils $js=NULL, &$view=NULL) {
45+
$this->content=JArray::sortAssociative($this->content, [ "image","header","meta","description","extra" ]);
46+
return parent::compile($js, $view);
47+
}
48+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
namespace Ajax\semantic\html\content\view;
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+
10+
use Ajax\semantic\html\elements\HtmlImage;
11+
use Ajax\semantic\html\elements\HtmlReveal;
12+
use Ajax\semantic\html\base\constants\RevealType;
13+
use Ajax\semantic\html\elements\HtmlButtonGroups;
14+
use Ajax\semantic\html\content\view\HtmlViewContent;
15+
use Ajax\semantic\html\content\view\HtmlViewHeaderContent;
16+
17+
abstract class HtmlViewItem extends HtmlSemDoubleElement {
18+
19+
protected $_sortContentBy=[];
20+
21+
public function __construct($identifier,$baseClass,$content=[]) {
22+
parent::__construct($identifier, "div", $baseClass, $content);
23+
}
24+
25+
private function createContent($content, $baseClass="content") {
26+
$count=\sizeof($this->content);
27+
$result=new HtmlViewContent("content-" . $count . "-" . $this->identifier, $content);
28+
$result->setClass($baseClass);
29+
return $result;
30+
}
31+
32+
private function addElementInContent($key, $element) {
33+
if (\array_key_exists($key, $this->content) === false) {
34+
$this->content[$key]=array ();
35+
}
36+
$this->content[$key][]=$element;
37+
return $element;
38+
}
39+
40+
private function getPart($part, $index=NULL) {
41+
if (\array_key_exists($part, $this->content)) {
42+
if (isset($index))
43+
return $this->content[$part][$index];
44+
return $this->content[$part];
45+
}
46+
return NULL;
47+
}
48+
49+
public function addHeader($header, $niveau=4, $type="page") {
50+
if (!$header instanceof HtmlHeader) {
51+
$header=new HtmlHeader("header-" . $this->identifier, $niveau, $header, $type);
52+
}
53+
$this->content["header"]=$this->createContent($header);
54+
}
55+
56+
public function addImage($image, $title="") {
57+
if (!$image instanceof HtmlImage) {
58+
$image=new HtmlImage("image-" . $this->identifier, $image, $title);
59+
}
60+
$image->setClass("ui image");
61+
return $this->addElementInContent("content", $image);
62+
}
63+
64+
public function addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) {
65+
$reveal=$visibleContent;
66+
if (!$visibleContent instanceof HtmlReveal) {
67+
$reveal=new HtmlReveal("reveral-" . $this->identifier, $visibleContent, $hiddenContent, $type, $attributeType);
68+
}
69+
return $this->addElementInContent("content", $reveal);
70+
}
71+
72+
public function addRevealImage($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) {
73+
$reveal=$visibleContent;
74+
if (!$visibleContent instanceof HtmlReveal) {
75+
return $this->addReveal(new HtmlImage("", $visibleContent), new HtmlImage("", $hiddenContent), $type, $attributeType);
76+
}
77+
return $this->addElementInContent("content", $reveal);
78+
}
79+
80+
public function addExtraContent($content=array()) {
81+
return $this->addElementInContent("extra-content", $this->createContent($content, "extra content"));
82+
}
83+
84+
public function addContent($content=array(), $before=false) {
85+
if (!$content instanceof HtmlViewContent) {
86+
$content=$this->createContent($content);
87+
}
88+
return $this->addElementInContent("content", $content);
89+
}
90+
91+
/**
92+
* @param array $elements
93+
* @param boolean $asIcons
94+
* @return \Ajax\semantic\html\elements\HtmlButtonGroups
95+
*/
96+
public function addButtons($elements=array(), $asIcons=false){
97+
$buttons=new HtmlButtonGroups("buttons-".$this->identifier,$elements,$asIcons);
98+
$this->addElementInContent("content", $buttons);
99+
return $buttons;
100+
}
101+
102+
103+
104+
public function addItemHeaderContent($header, $metas=array(), $description=NULL,$extra=NULL) {
105+
$count=\sizeof($this->content);
106+
return $this->addElementInContent("content", new HtmlViewHeaderContent("content-" . $count . "-" . $this->identifier, $header, $metas, $description,$extra));
107+
}
108+
109+
public function addItemContent($content=array()) {
110+
$count=\sizeof($this->content);
111+
return $this->addElementInContent("content", new HtmlViewContent("content-" . $count . "-" . $this->identifier, $content));
112+
}
113+
114+
public function getItemContent($index=NULL) {
115+
return $this->getPart("content", $index);
116+
}
117+
118+
public function getItemExtraContent() {
119+
return $this->getPart("extra-content");
120+
}
121+
122+
public function getItemImage() {
123+
return $this->getPart("image");
124+
}
125+
126+
public function getItemHeader() {
127+
return $this->getPart("header");
128+
}
129+
130+
/**
131+
*
132+
* {@inheritDoc}
133+
*
134+
* @see HtmlSemDoubleElement::compile()
135+
*/
136+
public function compile(JsUtils $js=NULL, &$view=NULL) {
137+
$this->content=JArray::sortAssociative($this->content, [ "header","image","content","extra-content" ]);
138+
return parent::compile($js, $view);
139+
}
140+
141+
public function asLink($href="",$target=NULL) {
142+
$this->addToProperty("class", "link");
143+
if ($href !== "") {
144+
$this->setProperty("href", $href);
145+
if (isset($target))
146+
$this->setProperty("target", $target);
147+
}
148+
return $this;
149+
}
150+
}

0 commit comments

Comments
 (0)