phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
FieldsTrait.php
Go to the documentation of this file.
1 <?php
2 
4 
17 
22 trait FieldsTrait {
23  abstract public function addFields($fields=NULL,$label=NULL);
24  abstract public function addItem($item);
25  abstract public function getItem($index);
26  abstract public function count();
27 
28  protected function createItem($value){
29  if(\is_array($value)){
30  $itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null)));
31  return $itemO;
32  }elseif(\is_object($value)){
33  $itemO=new HtmlFormField("field-".$this->identifier, $value);
34  return $itemO;
35  }else
36  return new HtmlFormInput($value);
37  }
38 
39  protected function createCondition($value){
40  return \is_object($value)===false || $value instanceof \Ajax\semantic\html\elements\HtmlInput;
41  }
42 
43  public function addInputs($inputs,$fieldslabel=null){
44  $fields=array();
45  foreach ($inputs as $input){
46  \extract($input);
47  $f=new HtmlFormInput("","");
48  $f->fromArray($input);
49  $fields[]=$f;
50  }
51  return $this->addFields($fields,$fieldslabel);
52  }
53 
60  public function setFieldsPropertyValues($property,$values){
61  $i=0;
62  if(\is_array($values)===false){
63  $values=\array_fill(0, $this->count(),$values);
64  }
65  foreach ($values as $value){
66  $c=$this->content[$i++];
67  if(isset($c)){
68  $df=$c->getDataField();
69  $df->setProperty($property,$value);
70  }
71  else{
72  return $this;
73  }
74  }
75  return $this;
76  }
77 
78  public function addFieldRule($index,$type,$prompt=NULL,$value=NULL){
79  $field=$this->getItem($index);
80  if(isset($field)){
81  $field->addRule($type,$prompt,$value);
82  }
83  return $this;
84  }
85 
86  public function addFieldRules($index,$rules){
87  $field=$this->getItem($index);
88  if(isset($field)){
89  $field->addRules($rules);
90  }
91  return $this;
92  }
93 
103  public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){
104  return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple));
105  }
106 
114  public function addButtonGroups($identifier,$elements=[],$asIcons=false){
115  return $this->addItem(new HtmlButtonGroups($identifier,$elements,$asIcons));
116  }
117 
127  public function addDropdownButton($identifier,$value,$items=[],$asCombo=false,$icon=null){
128  return $this->addItem(HtmlButton::dropdown($identifier, $value,$items,$asCombo,$icon));
129  }
130 
139  public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){
140  return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder));
141  }
142 
151  public function addTextarea($identifier, $label,$value=NULL,$placeholder=NULL,$rows=5){
152  return $this->addItem(new HtmlFormTextarea($identifier,$label,$value,$placeholder,$rows));
153  }
154 
155  public function addPassword($identifier, $label=NULL){
156  return $this->addItem(new HtmlFormInput($identifier,$label,"password","",""));
157  }
158 
159  public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){
160  return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick));
161  }
162 
163  public function addButtonIcon($identifier,$icon,$cssStyle=NULL,$onClick=NULL){
164  $bt=new HtmlButton($identifier);
165  $bt->asIcon($icon);
166  if(isset($onClick))
167  $bt->onClick($onClick);
168  if (isset($cssStyle))
169  $bt->addClass($cssStyle);
170  return $this->addItem($bt);
171  }
172 
180  public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){
181  return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type));
182  }
183 
184  public function addRadio($identifier, $name,$label=NULL,$value=NULL){
185  return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value));
186  }
187 
188  public function addElement($identifier,$content,$label,$tagName="div",$baseClass=""){
189  $div=new HtmlSemDoubleElement($identifier,$tagName,$baseClass,$content);
190  return $this->addItem(new HtmlFormField("field-".$identifier, $div,$label));
191  }
192 }
static getDefaultValue($array, $key, $default=NULL)
Definition: JArray.php:34
addInputs($inputs, $fieldslabel=null)
Definition: FieldsTrait.php:43
Semantic Button component.
Definition: HtmlButton.php:18
addDropdownButton($identifier, $value, $items=[], $asCombo=false, $icon=null)
Adds a button with a dropdown button.
addFieldRule($index, $type, $prompt=NULL, $value=NULL)
Definition: FieldsTrait.php:78
addTextarea($identifier, $label, $value=NULL, $placeholder=NULL, $rows=5)
addCheckbox($identifier, $label=NULL, $value=NULL, $type=NULL)
addDropdown($identifier, $items=array(), $label=NULL, $value=NULL, $multiple=false)
Adds a new dropdown element.
addInput($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL)
addButton($identifier, $value, $cssStyle=NULL, $onClick=NULL)
addRadio($identifier, $name, $label=NULL, $value=NULL)
Base class for Semantic double elements.
addButtonGroups($identifier, $elements=[], $asIcons=false)
Adds a new button groups.
static dropdown($identifier, $value, $items=[], $asCombo=false, $icon=null)
Returns a button with a dropdown button.
Definition: HtmlButton.php:284
addButtonIcon($identifier, $icon, $cssStyle=NULL, $onClick=NULL)
addElement($identifier, $content, $label, $tagName="div", $baseClass="")
addPassword($identifier, $label=NULL)
Semantic UI Buttongroups component.
setFieldsPropertyValues($property, $values)
Sets the values of a property for each Field of each item in the collection.
Definition: FieldsTrait.php:60