phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlCarousel.php
Go to the documentation of this file.
1<?php
2
3namespace Ajax\bootstrap\html;
4
10
18class HtmlCarousel extends BaseHtml {
19 protected $indicators=array ();
20 protected $slides=array ();
21 protected $leftControl="";
22 protected $rightControl="";
23 protected $_base="";
24 protected $_glyphs=array ();
25
26 public function __construct($identifier, $images=NULL) {
27 parent::__construct($identifier);
28 $this->_template=include 'templates/tplCarousel.php';
29 if ($images!=NULL) {
30 if (\is_array($images)) {
31 $this->fromArray($images);
32 }
33 }
34 }
35
36 public function getBase() {
37 return $this->_base;
38 }
39
40 public function setBase($_base) {
41 foreach ($this->slides as $slide){
42 $imgSrc=$slide->getImageSrc();
43 $slide->setImageSrc(str_replace($this->_base.$imgSrc, $_base.$imgSrc, $imgSrc));
44 }
45 $this->_base=$_base;
46 return $this;
47 }
48
49 public function run(JsUtils $js) {
50 $this->_bsComponent=$js->bootstrap()->carousel("#".$this->identifier);
51 $this->addEventsOnRun($js);
53 }
54
55 private function createControls() {
56 $this->rightControl=$this->createControl("next", "right");
57 $this->leftControl=$this->createControl("previous", "left");
58 }
59
66 private function createControl($caption="next", $sens="left") {
67 $control=new HtmlCarouselControl($sens."-ctrl-".$this->identifier);
68 $control->setClass($sens." carousel-control");
69 $control->setProperty("data-slide", substr($caption, 0, 4));
70 $control->setHref("#".$this->identifier);
71 $control->setRole("button");
72 $control->setCaption(ucfirst($caption));
73 $control->setGlyphIcon($this->getGlyph($sens));
74 return $control;
75 }
76
77 private function getGlyph($sens="left") {
78 if (array_key_exists($sens, $this->_glyphs))
79 return $this->_glyphs [$sens];
80 return "glyphicon-chevron-".$sens;
81 }
82
83 public function setRightGlyph($glyphicon) {
84 $glyphs=CssRef::glyphIcons();
85 if (array_search($glyphicon, $glyphs)!==false)
86 $this->_glyphs ["right"]=$glyphicon;
87 }
88
89 public function setLeftGlyph($glyphicon) {
90 $glyphs=CssRef::glyphIcons();
91 if (array_search($glyphicon, $glyphs)!==false)
92 $this->_glyphs ["left"]=$glyphicon;
93 }
94
95 public function addImage($imageSrc, $imageAlt="", $caption=NULL, $description=NULL) {
96 if(\is_array($imageSrc)){
97 $this->addImage($imageSrc[0],@$imageSrc[1],@$imageSrc[2],@$imageSrc[3]);
98 }else{
99 $image=new HtmlCarouselItem("item-".$this->identifier);
100 $image->setImageSrc($this->_base.$imageSrc);
101 $image->setImageAlt($imageAlt);
102 $image->setClass("item");
103 if (isset($caption)) {
104 $optCaption="<h3>".$caption."</h3>";
105 if (isset($description)) {
106 $optCaption.="<p>".$description."</p>";
107 }
108 $image->setCaption($optCaption);
109 }
110 $this->slides []=$image;
111 $this->createIndicator();
112 }
113 }
114
115 /*
116 * (non-PHPdoc)
117 * @see \Ajax\bootstrap\html\base\BaseHtml::fromArray()
118 */
119 public function fromArray($array) {
120 if (\is_array($array) && sizeof($array)>0) {
121 foreach ( $array as $value ) {
122 if (\is_array($value)) {
123 $this->addImage($value ["src"], @$value ["alt"], @$value ["caption"], @$value ["description"]);
124 } else {
125 $this->addImage($value);
126 }
127 }
128 }
129 return $this;
130 }
131
132 private function createIndicator() {
133 $indicator=new HtmlBsDoubleElement("indicator-".$this->identifier);
134 $indicator->setProperty("data-target", "#".$this->identifier);
135 $indicator->setProperty("data-slide-to", sizeof($this->indicators));
136 $indicator->setTagName("li");
137 $this->indicators []=$indicator;
138 }
139
140 /*
141 * (non-PHPdoc)
142 * @see \Ajax\bootstrap\html\base\BaseHtml::compile()
143 */
144 public function compile(JsUtils $js=NULL, &$view=NULL) {
145 $this->slides [0]->setClass("item active");
146 $this->indicators [0]->setClass("active");
147 $this->createControls();
148 return parent::compile($js, $view);
149 }
150
151
152 /* (non-PHPdoc)
153 * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject()
154 */
155 public function fromDatabaseObject($object, $function) {
156 $this->addImage($function($object));
157 }
158}
JQuery PHP library.
Definition JsUtils.php:23
bootstrap(Bootstrap $bootstrap=NULL)
getter or setter of the Twitter Bootstrap variable
Definition JsUtils.php:140
Default HTML values for Twitter Bootstrap HTML components.
Definition CssRef.php:12
BaseHtml for HTML components.
Definition BaseHtml.php:17