phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
HtmlFormFields.php
Go to the documentation of this file.
1 <?php
2 
4 
7 use Ajax\JsUtils;
8 
11 
13 
14  use FieldsTrait;
15  protected $_equalWidth;
16  protected $_name;
17 
18  public function __construct($identifier, $fields=array(), $equalWidth=true) {
19  parent::__construct($identifier, "div");
20  $this->_equalWidth=$equalWidth;
21  $this->addItems($fields);
22  }
23 
24  public function addFields($fields=NULL, $label=NULL) {
25  if (!$fields instanceof HtmlFormFields) {
26  if (!\is_array($fields)) {
27  $fields=\func_get_args();
28  $end=\end($fields);
29  if (\is_string($end)) {
30  $label=$end;
31  \array_pop($fields);
32  } else
33  $label=NULL;
34  }
35  }
36  if (isset($label))
37  $this->setLabel($label);
38  foreach ( $fields as $field ) {
39  $this->addItem($field);
40  }
41  return $this;
42  }
43 
49  public function setLabel($label) {
50  $labelO=$label;
51  if (\is_string($label)) {
52  $labelO=new HtmlSemDoubleElement("", "label", "", $label);
53  }
54  $this->insertItem($labelO, 0);
55  return $labelO;
56  }
57 
58  public function addItem($item) {
59  $item=parent::addItem($item);
60  if($item instanceof HtmlFormField)
61  $item->setContainer($this);
62  return $item;
63  }
64 
68  public function getItem($index){
69  return parent::getItem($index);
70  }
71 
72  public function compile(JsUtils $js=NULL, &$view=NULL) {
73  if ($this->_equalWidth) {
74  $count=$this->count();
75  $this->addToProperty("class", Wide::getConstants()["W".$count]." fields");
76  } else
77  $this->addToProperty("class", "fields");
78  return parent::compile($js, $view);
79  }
80 
81  public function setWidth($index, $width) {
82  $this->_equalWidth=false;
83  return $this->getItem($index)->setWidth($width);
84  }
85 
86  public function setInline() {
87  $this->_equalWidth=false;
88  $this->addToProperty("class", "inline");
89  return $this;
90  }
91 
92  public function setGrouped() {
93  $this->_equalWidth=false;
94  $this->addToProperty("class", "grouped");
95  }
96 
97  public function getName() {
98  return $this->_name;
99  }
100 
101  public function setName($_name) {
102  $this->_name=$_name;
103  return $this;
104  }
105 
106 
107  public static function radios($identifier,$name, $items=array(), $label=NULL, $value=null, $type=NULL) {
108  $fields=array ();
109  $i=0;
110  foreach ( $items as $val => $caption ) {
111  $itemO=new HtmlFormRadio($name."-".$i++, $name, $caption, $val, $type);
112  if ($val===$value) {
113  $itemO->getDataField()->setProperty("checked", "");
114  }
115  $fields[]=$itemO;
116  }
117  $radios=new HtmlFormFields($identifier, $fields);
118  if (isset($label)){
119  $lbl=$radios->setLabel($label);
120  if($lbl instanceof HtmlSemDoubleElement){
121  $lbl->setProperty("for", $name);
122  }
123  }
124  return $radios;
125  }
126 
127  public static function checkeds($identifier,$name, $items=array(), $label=NULL, $values=array(), $type=NULL) {
128  $fields=array ();
129  $i=0;
130  foreach ( $items as $val => $caption ) {
131  $itemO=new HtmlFormCheckbox($name."-".$i++, $caption, $val, $type);
132  $itemO->setName($name);
133  if (\array_search($val, $values)!==false) {
134  $itemO->getDataField()->setProperty("checked", "");
135  }
136  $fields[]=$itemO;
137  }
138  $radios=new HtmlFormFields($identifier, $fields);
139  if (isset($label))
140  $radios->setLabel($label)->setProperty("for", $name);
141  return $radios;
142  }
143 
144  public function setEqualWidth($_equalWidth) {
145  $this->_equalWidth=$_equalWidth;
146  return $this;
147  }
148 
149  public function run(JsUtils $js){
150  return parent::run($js);
151  //return $result->setItemSelector("[data-value]");
152  }
153 }
addToProperty($name, $value, $separator=" ")
static getConstants()
Definition: BaseEnum.php:17
static radios($identifier, $name, $items=array(), $label=NULL, $value=null, $type=NULL)
insertItem($item, $position=0)
Base class for Semantic double elements.
Base class for Semantic Html collections.
JQuery PHP library.
Definition: JsUtils.php:23
static checkeds($identifier, $name, $items=array(), $label=NULL, $values=array(), $type=NULL)
__construct($identifier, $fields=array(), $equalWidth=true)