1 <?php
2 /**
3 * XAO_InputField.php
4 *
5 * This script provides the class definition for InputField. This
6 * class facilitates management of input field specifications for a single info
7 * item. This class is designed for complex applications and is not intended for
8 * usage by non-advanced PHP/XML application developers. It also requires sound
9 * knowlege of XSLT template design. See class doc comment for details.
10 */
11
12 /**
13 * Import the basic DomDoc class for inheritance.
14 *
15 * This class is based on DomDoc and hence supports all of it's
16 * functionality,
17 * including it's ability to be consumed by another DomDoc based object.
18 *
19 * @import DomDoc
20 */
21 include_once "XAO_DomDoc.php";
22
23 /**
24 * Collection requirements for a single information item.
25 *
26 * WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING
27 * DO NOT ATTEMPT TO USE THIS CLASS. IT IS A WORK IN PROGRESS. IT IS VAPOURWARE.
28 * IT PROBABLY HAS NOT EVEN BEEN THROUGH THE INTERPRETER/PARSER YET. IT WILL NOT
29 * WORK. THE DESIGN WILL CHANGE. THERE'S STILL MUCH WORK TO BE DONE. LEAVE IT.
30 * This class provides facilities for building and storing specifications for the
31 * input of a single information item. The InputControl class was designed to
32 * group InputField objects. While there is no UML class relationship with the
33 * InputValidator class, there is indeed a strong relationship between the two.
34 * This class is designed for complex applications and is not intended for
35 * usage by non-advanced PHP/XML application developers. It also requires sound
36 * knowlege of XSLT template design.
37 * The InputValidator class is obligated to know how to validate each requirement
38 * specifiable by this class. The InputValidator will require these specs to be
39 * bassed on using name/value pairs that conform to a particular naming
40 * convention. The XSLT template developer is obligated to expand the XAO
41 * stnadard XML (in the XAO namespace) to
42 * generate the neccesary name/value pairs
43 * required by InputValidator. Don't worry, sample XSL files will be provided to
44 * give the developer hints on how to construct such templates. Note, that the
45 * DomXsl class has been provided
46 * for those who want to generate XSL templates at runtime. Note that the display
47 * logic is still descrete - you can have multiple display templates using the
48 * same input spec.
49 *
50 * @author Terence Kearns
51 * @version 0.2
52 * @copyright Terence Kearns 2003
53 * @license LGPL
54 * @package XAO
55 * @link http://xao-php.sourceforge.net
56 */
57 class InputField extends DomDoc {
58
59 var $arrParams;
60
61 var $ndValue;
62
63 var $ndName;
64
65 var $ndType;
66
67 function InputField(&$mxdParams,$strDefault = null) {
68 if(is_array($mxdParams)) {
69 $this->arrParams = $mxdParams;
70 $strRoot = "inputField";
71 $this->DomDoc($strRoot);
72 $this->Arr2Atts($mxdParams,$this->ndRoot);
73 if(strlen($strDefault)) $this->ndRoot->set_content($strDefault);
74 }
75 elseif(is_object($mxdParams)) {
76 if(is_a($mxdParams,"InputField")) {
77 $this->DomDoc($mxdParams,XAO_DOC_REFERENCE);
78 $this->arrParams = $this->Atts2Arr($this->ndRoot);
79 $this->ExtractProperties();
80 }
81 else {
82 $this->Throw(
83 "Cannot create InputField using a non-InputField object",
84 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
85 );
86 }
87 }
88 else {
89 $this->Throw(
90 "Cannot creat InputField using supplied parameter.",
91 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
92 );
93 }
94 //if(!$this->strError) $this->CheckRules();
95 }
96
97 function ndSetAtt($strName,$strVal) {
98 $this->arrParams[$strName] = $strVal;
99 return $this->ndRoot->set_attribute($strName,$strVal);
100 }
101
102 function ndSetProperty($strName,$strValue) {
103 if($this->blnTestSafeName($strName)) {
104 $strLName = "nd".$strName;
105 if(isset($this->$strLName)) {
106 return $this->$strLName = $this->ndAppendToRoot($strName,$strValue);
107 }
108 else {
109 $this->Throw(
110 $strName." is not a recognised InputField property.",
111 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
112 );
113 }
114 }
115 else {
116 $this->Throw(
117 $strName." cannot be used as a InputField property name.",
118 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
119 );
120 }
121 }
122
123 function ExtractProperties() {
124 $arrNd =& $this->ndRoot->child_nodes();
125 foreach($arrNd AS $nd) {
126 if($this->blnTestElementNode($nd)) {
127 $strName = $nd->tagname();
128 $strLName = "nd".$strName;
129 if(isset($this->$strLName)) {
130 $this->$strLName =& $nd;
131 }
132 else {
133 $this->Throw(
134 $strName." is not a recognised InputField property.",
135 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
136 );
137 }
138 }
139 }
140 }
141
142 function CheckRules() {
143 $arrMethods = get_class_methods($this);
144 foreach($arrMethods AS $strMethName) {
145 if(substr($strMethName,0,14) == "InFldRuleCheck") {
146 $this->$strMethName();
147 }
148 }
149 }
150
151 function InFldRuleCheckRequiredProperties() {
152 $arrPropNames = array("name","type");
153 foreach($arrPropNames AS $strName) {
154 $this->CheckProperty($strName);
155 }
156 }
157
158 function CheckProperty($strName) {
159 $strLName = "nd".$strName;
160 if(!$this->blnTestElementNode($this->$strLName)) {
161 $this->Throw(
162 "The InputField property \"".$strName."\" must be set. "
163 ."Use InputField::ndSetProperty(\"".$strName."\",...).",
164 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
165 );
166 }
167 else {
168 if(strlen($strPropVal = $this->$strLName->get_content())) {
169 if(!$this->blnTestSafeName($strPropVal)) {
170 $this->Throw(
171 $strPropVal. " is not a valid value for the \""
172 .$strName."\" property.",
173 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
174 );
175 }
176 }
177 else {
178 $this->Throw(
179 "The InputField property \"".$strName."\" must be set. "
180 ."Currently \"".$strName."\" is set with an empty "
181 ."value. "
182 ."Use InputField::ndSetProperty(\"".$strName."\",...).",
183 $this->arrSetErrFnc(__FUNCTION__,__LINE__)
184 );
185 }
186 }
187 }
188 }
189
190 ?>