phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
HtmlViewItem.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Ajax\JsUtils;
9 
15 
16 abstract class HtmlViewItem extends HtmlSemDoubleElement {
17  use ContentPartTrait;
18 
19  public function __construct($identifier,$baseClass,$content=NULL) {
20  parent::__construct($identifier, "div", $baseClass);
21  $this->content=["content"=>new HtmlViewContent("content-".$this->identifier)];
22  if(isset($content))
23  $this->setContent($content);
24  }
25 
26  public function setContent($value){
27  if (\is_array($value)) {
28  $image=JArray::getValue($value, "image", 0);
29  $content=JArray::getValue($value, "content", 1);
30  $extra=JArray::getValue($value, "extra", 2);
31  if (isset($image)) {
32  $this->addImage($image);
33  }
34  if(isset($content))
35  $this->content["content"]->setContent($content);
36  if(isset($extra))
37  $this->addExtraContent($extra);
38  }
39  }
40 
41  private function createContent($content, $baseClass="content") {
42  $count=\sizeof($this->content);
43  $result=new HtmlViewContent("content-" . $count . "-" . $this->identifier, $content);
44  $result->setClass($baseClass);
45  return $result;
46  }
47 
48  private function addElementIn($key, $element) {
49  if (\array_key_exists($key, $this->content) === false) {
50  $this->content[$key]=[];
51  }
52  if($this->content[$key] instanceof HtmlViewContent)
53  $this->content[$key]->addElement($element);
54  else
55  $this->content[$key][]=$element;
56  return $element;
57  }
58 
59  public function addIcon($icon,$before=true){
60  return $this->addElementIn("icon",new HtmlIcon("icon-" . $this->identifier, $icon));
61  }
62 
63 
64  public function addHeader($header, $niveau=4, $type="page") {
65  if (!$header instanceof HtmlHeader) {
66  $header=new HtmlHeader("header-" . $this->identifier, $niveau, $header, $type);
67  }
68  return $this->addElementIn("header",$this->createContent($header));
69  }
70 
71  public function addImage($image, $title="") {
72  if (!$image instanceof HtmlImage) {
73  $image=new HtmlImage("image-" . $this->identifier, $image, $title);
74  }
75  $image->setClass("ui image");
76  return $this->content["image"]= $image;
77  }
78 
79  public function addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL,$key="extra-content") {
80  $reveal=$visibleContent;
81  if (!$visibleContent instanceof HtmlReveal) {
82  $reveal=new HtmlReveal("reveral-" . $this->identifier, $visibleContent, $hiddenContent, $type, $attributeType);
83  }
84  return $this->content[$key]= $reveal;
85  }
86 
87  public function addRevealImage($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL) {
88  $reveal=$visibleContent;
89  if (!$visibleContent instanceof HtmlReveal) {
90  return $this->addReveal(new HtmlImage("", $visibleContent), new HtmlImage("", $hiddenContent), $type, $attributeType);
91  }
92  return $this->content["image"]= $reveal;
93  }
94 
95  public function addExtraContent($content=array()) {
96  return $this->content["extra-content"]= $this->createContent($content, "extra content");
97  }
98 
106  public function addContentButtons($elements=array(), $asIcons=false,$part="extra",$before=false){
107  return $this->content["content"]->addContentButtons($elements,$asIcons,$part, $before);
108  }
109 
110 
111 
112  public function addItemHeaderContent($header, $metas=array(), $description=NULL,$extra=NULL) {
113  return $this->content["content"]->addHeaderContent($header, $metas, $description,$extra);
114  }
115 
116  public function addItemContent($content=array()) {
117  $count=\sizeof($this->content);
118  return $this->addElementIn("content", new HtmlViewContent("content-" . $count . "-" . $this->identifier, $content));
119  }
120 
121  public function getItemContent() {
122  return $this->getPart("content",null,true);
123  }
124 
125  public function getItemExtraContent() {
126  return $this->getPart("extra-content");
127  }
128 
129  public function getItemImage() {
130  return $this->getPart("image");
131  }
132 
133  public function getItemHeader() {
134  return $this->getPart("header");
135  }
136 
143  public function compile(JsUtils $js=NULL, &$view=NULL) {
144  $this->content=JArray::sortAssociative($this->content, ["header","image","icon","content","extra-content"]);
145  return parent::compile($js, $view);
146  }
147 
148  public function asLink($href="",$target=NULL) {
149  $this->addToProperty("class", "link");
150  if ($href !== "") {
151  $this->setProperty("href", $href);
152  if (isset($target))
153  $this->setProperty("target", $target);
154  }
155  return $this;
156  }
157 }
__construct($identifier, $baseClass, $content=NULL)
addRevealImage($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL)
static getValue($array, $key, $pos)
Definition: JArray.php:10
addToProperty($name, $value, $separator=" ")
Semantic Image component.
Definition: HtmlImage.php:16
addContentButtons($elements=array(), $asIcons=false, $part="extra", $before=false)
Semantic Icon component.
Definition: HtmlIcon.php:14
addReveal($visibleContent, $hiddenContent=NULL, $type=RevealType::FADE, $attributeType=NULL, $key="extra-content")
addHeader($header, $niveau=4, $type="page")
compile(JsUtils $js=NULL, &$view=NULL)
Base class for Semantic double elements.
JQuery PHP library.
Definition: JsUtils.php:23
Semantic Header component.
Definition: HtmlHeader.php:19
addItemHeaderContent($header, $metas=array(), $description=NULL, $extra=NULL)
createContent($content, $baseClass="content")
static sortAssociative($array, $sortedKeys=array())
Definition: JArray.php:66