XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
formelement.class.php
Go to the documentation of this file.
1 <?php
2 // $Id: formelement.class.php 924 2012-01-13 06:23:22Z 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 
15 abstract class RMFormElement
16 {
17  private $_name = '';
18  private $_caption = '';
19  private $_class = '';
20  private $_extra = '';
21  private $_required = '';
22  private $_description = '';
23  private $_formname = '';
24  private $_id = '';
25  static $elementsIds = array();
26 
31  public function setName($name){
32  $this->_name = trim($name);
33 
34  return $this;
35  }
40  public function getName(){
41  return $this->_name;
42  }
43 
44  public function setId($id){
45  $this->_id = $id;
46  }
47 
52  public function id(){
53 
54  // If not id has been provided then generate one
55  if($this->_id==''){
56  $name = $this->_name;
57  if(preg_match("/\[.*\]/", $name)){
58  $name = preg_replace("/\[.*\]/",'',$name);
59  if(isset(self::$elementsIds[$name]))
60  self::$elementsIds[$name]++;
61  else
62  self::$elementsIds[$name] = 1;
63 
64  $name .= '-'.self::$elementsIds[$name];
65  }
66  $this->_id = $name;
67  }
68 
69  return $this->_id;
70  }
71 
77  public function setClass($class){
78  $this->_class = $class;
79  return $this;
80  }
81  public function addClass($class){
82  $this->_class .= " $class";
83  return $this;
84  }
89  public function getClass(){
90  return $this->_class;
91  }
97  public function setCaption($caption){
98  $this->_caption = trim($caption);
99  return $this;
100  }
105  public function getCaption(){
106  return $this->_caption;
107  }
115  public function setDescription($desc){
116  $this->_description = $desc;
117  return $this;
118  }
123  public function getDescription(){
124  return $this->_description;
125  }
133  public function setExtra($extra){
134  $this->_extra = $extra;
135  return $this;
136  }
141  public function getExtra(){
142  return $this->_extra;
143  }
147  public function setForm($name){
148  $this->_formname = $name;
149  return $this;
150  }
151  public function getForm(){
152  return $this->_formname;
153  }
159  abstract function render();
160 }
161 ?>