phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
BaseTrait.php
Go to the documentation of this file.
1 <?php
2 
4 
11 
17 trait BaseTrait {
18  protected $_variations=[ ];
19  protected $_states=[ ];
20  protected $_baseClass;
21 
22  abstract protected function setPropertyCtrl($name, $value, $typeCtrl);
23 
24  abstract protected function addToPropertyCtrl($name, $value, $typeCtrl);
25 
26  abstract protected function addToPropertyCtrlCheck($name, $value, $typeCtrl);
27 
28  abstract public function addToProperty($name, $value, $separator=" ");
29 
30  abstract public function setProperty($name, $value);
31 
32  abstract public function addContent($content,$before=false);
33 
34  abstract public function onCreate($jsCode);
35 
36  public function addVariation($variation) {
37  return $this->_self->addToPropertyCtrlCheck("class", $variation, $this->_self->getVariations());
38  }
39 
40  public function addState($state) {
41  return $this->_self->addToPropertyCtrlCheck("class", $state, $this->_self->getStates());
42  }
43 
44  public function setVariation($variation) {
45  $this->_self->setPropertyCtrl("class", $variation, $this->_self->getVariations());
46  return $this->_self->addToProperty("class", $this->_self->getBaseClass());
47  }
48 
49  public function setVariations($variations) {
50  $this->_self->setProperty("class", $this->_self->getBaseClass());
51  if (\is_string($variations))
52  $variations=\explode(" ", $variations);
53  foreach ( $variations as $variation ) {
54  $this->_self->addVariation($variation);
55  }
56  return $this;
57  }
58 
59  public function setState($state) {
60  $this->_self->setPropertyCtrl("class", $state, $this->_self->getStates());
61  return $this->_self->addToProperty("class", $this->_self->getBaseClass());
62  }
63 
64  public function addVariations($variations=array()) {
65  if (\is_string($variations))
66  $variations=\explode(" ", $variations);
67  foreach ( $variations as $variation ) {
68  $this->_self->addVariation($variation);
69  }
70  return $this;
71  }
72 
73  public function addStates($states=array()) {
74  if (\is_string($states))
75  $states=\explode(" ", $states);
76  foreach ( $states as $state ) {
77  $this->_self->addState($state);
78  }
79  return $this;
80  }
81 
82  public function setStates($states) {
83  $this->_self->setProperty("class", $this->_self->getBaseClass());
84  if (\is_string($states))
85  $states=\explode(" ", $states);
86  foreach ( $states as $state ) {
87  $this->_self->addState($state);
88  }
89  return $this;
90  }
91 
92  public function addIcon($icon, $before=true) {
93  return $this->_self->addContent(new HtmlIcon("icon-" . $this->_self->getIdentifier(), $icon), $before);
94  }
95 
96  public function addSticky($context="body"){
97  $this->_self->onCreate("$('#".$this->_self->getIdentifier()."').sticky({ context: '".$context."'});");
98  return $this;
99  }
100 
107  public function setSize($size) {
108  return $this->_self->addToPropertyCtrl("class", $size, Size::getConstants());
109  }
110 
116  public function setDisabled($disable=true) {
117  if($disable)
118  $this->_self->addToProperty("class", "disabled");
119  return $this;
120  }
121 
127  public function setColor($color) {
128  return $this->_self->addToPropertyCtrl("class", $color, Color::getConstants());
129  }
130 
135  public function setFluid() {
136  return $this->_self->addToProperty("class", "fluid");
137  }
138 
143  public function asHeader(){
144  return $this->_self->addToProperty("class", "header");
145  }
146 
151  public function setActive($value=true){
152  if($value)
153  $this->_self->addToProperty("class", "active");
154  return $this;
155  }
156 
157  public function setAttached($value=true){
158  if($value)
159  $this->_self->addToPropertyCtrl("class", "attached", array ("attached" ));
160  return $this;
161  }
162 
166  public function setInverted($recursive=true) {
167  if($recursive===true){
168  $content=$this->_self->getContent();
169  if($content instanceof HtmlSemDoubleElement)
170  $content->setInverted($recursive);
171  elseif(\is_array($content) || $content instanceof \Traversable){
172  foreach ($content as $elm){
173  if($elm instanceof HtmlSemDoubleElement){
174  $elm->setInverted($recursive);
175  }
176  }
177  }
178  }
179  return $this->_self->addToProperty("class", "inverted");
180  }
181 
182  public function setCircular() {
183  return $this->_self->addToProperty("class", "circular");
184  }
185 
186  public function setFloated($direction="right") {
187  return $this->_self->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated"));
188  }
189 
190  public function floatRight() {
191  return $this->_self->setFloated();
192  }
193 
194  public function floatLeft() {
195  return $this->_self->setFloated("left");
196  }
197 
198  public function getBaseClass() {
199  return $this->_baseClass;
200  }
201 
202  protected function addBehavior(&$array,$key,$value,$before="",$after=""){
203  if(\is_string($value)){
204  if(isset($array[$key])){
205  $p=JString::replaceAtFirstAndLast($array[$key], $before, "", $after, "");
206  $array[$key]=$before.$p.$value.$after;
207  }else
208  $array[$key]=$before.$value.$after;
209  }else{
210  $array[$key]=$value;
211  }
212  return $this;
213  }
214 
215  public function getVariations() {
216  return $this->_variations;
217  }
218 
219  public function getStates() {
220  return $this->_states;
221  }
222 
223 }
addSticky($context="body")
Definition: BaseTrait.php:96
addToPropertyCtrlCheck($name, $value, $typeCtrl)
static replaceAtFirstAndLast($subject, $fromFirst, $toFirst, $fromLast, $toLast)
Definition: JString.php:52
static getConstants()
Definition: BaseEnum.php:17
setActive($value=true)
show it is currently the active user selection
Definition: BaseTrait.php:151
setFloated($direction="right")
Definition: BaseTrait.php:186
Semantic Icon component.
Definition: HtmlIcon.php:14
addToProperty($name, $value, $separator=" ")
static getConstantValues($postFix="", $prefixBefore=false)
Definition: BaseEnum.php:29
Base class for Semantic double elements.
addBehavior(&$array, $key, $value, $before="", $after="")
Definition: BaseTrait.php:202
addStates($states=array())
Definition: BaseTrait.php:73
addVariations($variations=array())
Definition: BaseTrait.php:64
setDisabled($disable=true)
show it is currently unable to be interacted with
Definition: BaseTrait.php:116
addToPropertyCtrl($name, $value, $typeCtrl)
addIcon($icon, $before=true)
Definition: BaseTrait.php:92
setPropertyCtrl($name, $value, $typeCtrl)
setInverted($recursive=true)
can be formatted to appear on dark backgrounds
Definition: BaseTrait.php:166
addContent($content, $before=false)