-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfield.php
113 lines (97 loc) · 2.43 KB
/
field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* @package midgardmvc_helper_forms
* @author The Midgard Project, http://www.midgard-project.org
* @copyright The Midgard Project, http://www.midgard-project.org
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
abstract class midgardmvc_helper_forms_field
{
protected $name = '';
protected $value = null;
protected $required = false;
protected $widget = null;
protected $actions = array();
protected $mvc = null;
protected $readonly = false;
public function __construct($name, $required = false, array $actions = array())
{
$this->name = $name;
$this->required = $required;
$this->actions = $actions;
$this->mvc = midgardmvc_core::get_instance();
}
public function __get($key)
{
if ($key == 'value')
{
return $this->value;
}
if ($key == 'widget')
{
return $this->widget;
}
if ($key == 'required')
{
return $this->required;
}
if ($key == 'readonly')
{
return $this->readonly;
}
return $this->set_widget($key);
}
public function set_widget($widget)
{
if (!is_null($this->widget))
{
// This field has a widget already
return $this->widget;
}
if (strpos($widget, '_') === false)
{
// Built-in type called using the shorthand notation
$widget = "midgardmvc_helper_forms_widget_{$widget}";
}
$this->widget = new $widget($this);
// TODO: Check widget compatibility with type
return $this->widget;
}
public function __toString()
{
return "".$this->value;
}
public function set_readonly($readonly = true)
{
$this->readonly = (bool) $readonly;
}
public function set_required($required = true)
{
$this->required = (bool) $required;
}
public function set_value($value)
{
$this->value = $value;
}
public function get_value()
{
return $this->value;
}
public function get_name()
{
return $this->name;
}
public function get_actions()
{
return $this->actions;
}
public function validate()
{
return;
}
public function clean()
{
//do nothing
}
}
?>