XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
button.class.php
Go to the documentation of this file.
1 <?php
2 // $Id: button.class.php 825 2011-12-09 00:06:11Z i.bitcero $
3 // --------------------------------------------------------------
4 // Red México Common Utilities
5 // A framework for Red México Modules
6 // Author: Eduardo Cortés <i.bitcero@gmail.com>
7 // Email: i.bitcero@gmail.com
8 // License: GPL 2.0
9 // --------------------------------------------------------------
10 
16 {
17  private $_type = 'submit';
18  private $_value = '';
24  function __construct($name, $value, $type = 'submit'){
25  $this->setName($name);
26  $this->_value = $value;
27  $this->_type = $type;
32  $this->setCaption('&nbsp;');
33  }
38  public function setType($type){
39  $this->_type = $type;
40  }
45  public function getType($type){
46  return $this->_type;
47  }
52  public function setValue($value){
53  $this->_value = $value;
54  }
59  public function getValue(){
60  return $this->_value;
61  }
66  public function render(){
67  $ret = "<input type='".$this->_type."' name='".$this->getName()."' id='".$this->id()."' value='".$this->_value."' ";
68  if ($this->getClass()!='' || $this->_type = 'submit'){
69  if ($this->_type = 'submit' && $this->getClass()==''){
70  $ret .= "class='formButton' ";
71  } else {
72  $ret .= "class='".$this->getClass()."' ";
73  }
74  }
75 
76  $ret .= $this->getExtra()." />";
77  return $ret;
78  }
79 
80 }
81 
87 {
88  private $sep = '';
89  private $buttons = array();
90  private $ok = '';
91 
96  public function __construct($caption='&nbsp;',$separator=' '){
97  $this->setCaption($caption);
98  $this->sep = $separator;
99  }
100 
107  public function addButton($name, $value, $type = 'button', $extra='', $ok=false){
108  $index = count($this->buttons);
109  $this->buttons[$index] = new RMFormButton($name,$value,$type);
110  if (trim($extra)!='') $this->buttons[$index]->setExtra($extra);
115  if ($ok) $this->ok = $name;
116  }
121  public function getButtons(){
122  return $this->buttons;
123  }
131  public function setExtra($name, $extra){
132  //if (!isset($this->buttons[$name])) return;
133  foreach ($this->buttons as $index => $button){
134  if ($button->getName()==$name){
135  $this->buttons[$index]->setExtra($extra);
136  break;
137  }
138  }
139  }
146  public function render(){
147 
148  $ret = '';
149 
150  foreach ($this->buttons as $k => $button){
151 
152  if ($k==$this->ok)
153  $button->setClass('button formButton');
154  else
155  $button->setClass('button');
156 
157  if ($ret==''){
158  $ret = $button->render();
159  } else {
160  $ret .= $this->sep . $button->render();
161  }
162  }
163 
164  return $ret;
165  }
166 }