-
Notifications
You must be signed in to change notification settings - Fork 0
/
Element.php
100 lines (83 loc) · 2.57 KB
/
Element.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
<?php
#################################################################
# Copyright notice
#
# (c) 2012 Jérôme Schneider <[email protected]>
# All rights reserved
#
# http://formal.codr.fr
#
# This script is part of the Formal project. The Formal
# project is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# The GNU General Public License can be found at
# http://www.gnu.org/copyleft/gpl.html.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# This copyright notice MUST APPEAR in all copies of the script!
#################################################################
namespace Formal;
abstract class Element {
protected $aOptions = array(
"class" => "",
"inputclass" => "input-xlarge",
"readonly" => FALSE,
"validation" => "",
"error" => FALSE,
"placeholder" => "",
"help" => "",
"popover" => "",
"refreshonchange" => FALSE,
);
protected $sValue = "";
public function __construct($aOptions) {
$this->aOptions = array_merge($this->aOptions, $aOptions);
}
public function option($sName) {
if(array_key_exists($sName, $this->aOptions)) {
return $this->aOptions[$sName];
}
throw new \Exception("\Formal\Element->option(): Option '" . htmlspecialchars($sName) . "' not found.");
}
public function optionArray($sOptionName) {
$sOption = trim($this->option($sOptionName));
if($sOption !== "") {
$aOptions = explode(",", $sOption);
} else {
$aOptions = array();
}
reset($aOptions);
return $aOptions;
}
public function setOption($sOptionName, $sOptionValue) {
$this->aOptions[$sOptionName] = $sOptionValue;
}
public function value() {
return $this->sValue;
}
public function setValue($sValue) {
$this->sValue = $sValue;
}
public function __toString() {
return get_class($this) . "<" . $this->option("label") . ">";
}
public function renderWitness() {
return '<input type="hidden" name="witness[' . $this->option("prop") . ']" value="1" />';
}
public function posted() {
$aPost = \Flake\Util\Tools::POST("witness");
if(is_array($aPost)) {
$sProp = $this->option("prop");
return (array_key_exists($sProp, $aPost)) && (intval($aPost[$sProp]) === 1);
}
return FALSE;
}
public abstract function render();
}