Index: trunk/extensions/SemanticForms/includes/SF_FormField.php |
— | — | @@ -13,28 +13,25 @@ |
14 | 14 | * @ingroup SF |
15 | 15 | */ |
16 | 16 | class SFFormField { |
17 | | - var $num; |
18 | | - var $template_field; |
19 | | - var $input_type; |
20 | | - var $is_mandatory; |
21 | | - var $is_hidden; |
22 | | - var $is_restricted; |
23 | | - var $possible_values; |
| 17 | + private $num; |
| 18 | + public $template_field; |
| 19 | + private $input_type; |
| 20 | + public $is_mandatory; |
| 21 | + public $is_hidden; |
| 22 | + private $is_restricted; |
| 23 | + private $possible_values; |
| 24 | + public $is_list; |
24 | 25 | // the following fields are not set by the form-creation page |
25 | 26 | // (though they could be) |
26 | | - var $is_uploadable; |
27 | | - var $field_args; |
28 | | - var $autocomplete_source; |
29 | | - var $autocomplete_field_type; |
30 | | - var $no_autocomplete; |
31 | | - var $part_of_multiple; |
| 27 | + private $is_uploadable; |
| 28 | + private $field_args; |
32 | 29 | // somewhat of a hack - these two fields are for a field in a specific |
33 | 30 | // representation of a form, not the form definition; ideally these |
34 | 31 | // should be contained in a third 'field' class, called something like |
35 | 32 | // SFFormInstanceField, that holds these fields plus an instance of |
36 | 33 | // SFFormField. Too much work? |
37 | | - var $input_name; |
38 | | - var $is_disabled; |
| 34 | + public $input_name; |
| 35 | + public $is_disabled; |
39 | 36 | |
40 | 37 | static function create( $num, $template_field ) { |
41 | 38 | $f = new SFFormField(); |
— | — | @@ -58,7 +55,7 @@ |
59 | 56 | // setting in the form definition |
60 | 57 | $the_field = null; |
61 | 58 | foreach ( $all_fields as $cur_field ) { |
62 | | - if ( $field_name == $cur_field->field_name ) { |
| 59 | + if ( $field_name == $cur_field->getFieldName() ) { |
63 | 60 | $the_field = $cur_field; |
64 | 61 | break; |
65 | 62 | } |
— | — | @@ -89,6 +86,22 @@ |
90 | 87 | return $f; |
91 | 88 | } |
92 | 89 | |
| 90 | + public function getTemplateField() { |
| 91 | + return $this->template_field; |
| 92 | + } |
| 93 | + |
| 94 | + public function getInputType() { |
| 95 | + return $this->input_type; |
| 96 | + } |
| 97 | + |
| 98 | + public function setTemplateField( $templateField ) { |
| 99 | + $this->template_field = $templateField; |
| 100 | + } |
| 101 | + |
| 102 | + public function setSemanticProperty( $semanticProperty ) { |
| 103 | + $this->template_field->setSemanticProperty( $semanticProperty ); |
| 104 | + } |
| 105 | + |
93 | 106 | function inputTypeDropdownHTML( $field_form_text, $default_input_type, $possible_input_types, $cur_input_type ) { |
94 | 107 | if ( !is_null( $default_input_type ) ) { |
95 | 108 | array_unshift( $possible_input_types, $default_input_type ); |
— | — | @@ -119,15 +132,15 @@ |
120 | 133 | function creationHTML( $template_num ) { |
121 | 134 | $field_form_text = $template_num . "_" . $this->num; |
122 | 135 | $template_field = $this->template_field; |
123 | | - $text = '<h3>' . wfMsg( 'sf_createform_field' ) . " '" . $template_field->field_name . "'</h3>\n"; |
124 | | - $prop_link_text = SFUtils::linkText( SMW_NS_PROPERTY, $template_field->semantic_property ); |
| 136 | + $text = '<h3>' . wfMsg( 'sf_createform_field' ) . " '" . $template_field->getFieldName() . "'</h3>\n"; |
| 137 | + $prop_link_text = SFUtils::linkText( SMW_NS_PROPERTY, $template_field->getSemanticProperty() ); |
125 | 138 | // TODO - remove this probably-unnecessary check? |
126 | | - if ( $template_field->semantic_property == "" ) { |
| 139 | + if ( $template_field->getSemanticProperty() == "" ) { |
127 | 140 | // Print nothing if there's no semantic property. |
128 | | - } elseif ( $template_field->property_type == "" ) { |
| 141 | + } elseif ( $template_field->getPropertyType() == "" ) { |
129 | 142 | $text .= '<p>' . wfMsg( 'sf_createform_fieldpropunknowntype', $prop_link_text ) . "</p>\n"; |
130 | 143 | } else { |
131 | | - if ( $template_field->is_list ) { |
| 144 | + if ( $template_field->getIsList() ) { |
132 | 145 | $propDisplayMsg = 'sf_createform_fieldproplist'; |
133 | 146 | } else { |
134 | 147 | $propDisplayMsg = 'sf_createform_fieldprop'; |
— | — | @@ -139,13 +152,13 @@ |
140 | 153 | if ( $smwgContLang != null ) { |
141 | 154 | $datatypeLabels = $smwgContLang->getDatatypeLabels(); |
142 | 155 | $datatypeLabels['enumeration'] = 'enumeration'; |
143 | | - $propertyType = $datatypeLabels[$template_field->property_type]; |
| 156 | + $propertyTypeLabel = $datatypeLabels[$template_field->getPropertyType()]; |
144 | 157 | if ( class_exists( 'SMWDIProperty' ) ) { |
145 | 158 | // "Type:" namespace was removed in SMW 1.6. |
146 | 159 | // TODO: link to Special:Types instead? |
147 | | - $propertyTypeStr = $propertyType; |
| 160 | + $propertyTypeStr = $propertyTypeLabel; |
148 | 161 | } else { |
149 | | - $propertyTypeStr = SFUtils::linkText( SMW_NS_TYPE, $propertyType ); |
| 162 | + $propertyTypeStr = SFUtils::linkText( SMW_NS_TYPE, $propertyTypeLabel ); |
150 | 163 | } |
151 | 164 | } |
152 | 165 | $text .= Xml::tags( 'p', null, wfMsg( $propDisplayMsg, $prop_link_text, $propertyTypeStr ) ) . "\n"; |
— | — | @@ -157,7 +170,7 @@ |
158 | 171 | 'type' => 'text', |
159 | 172 | 'name' => 'label_' . $field_form_text, |
160 | 173 | 'size' => 20, |
161 | | - 'value' => $template_field->label, |
| 174 | + 'value' => $template_field->getLabel(), |
162 | 175 | ), null ); |
163 | 176 | $input_type_text = wfMsg( 'sf_createform_inputtype' ); |
164 | 177 | $text .= <<<END |
— | — | @@ -167,17 +180,17 @@ |
168 | 181 | |
169 | 182 | END; |
170 | 183 | global $sfgFormPrinter; |
171 | | - if ( is_null( $template_field->property_type ) ) { |
| 184 | + if ( is_null( $template_field->getPropertyType() ) ) { |
172 | 185 | $default_input_type = null; |
173 | 186 | $possible_input_types = $sfgFormPrinter->getAllInputTypes(); |
174 | 187 | } else { |
175 | | - $default_input_type = $sfgFormPrinter->getDefaultInputType( $template_field->is_list, $template_field->property_type ); |
176 | | - $possible_input_types = $sfgFormPrinter->getPossibleInputTypes( $template_field->is_list, $template_field->property_type ); |
| 188 | + $default_input_type = $sfgFormPrinter->getDefaultInputType( $template_field->getIsList(), $template_field->getPropertyType() ); |
| 189 | + $possible_input_types = $sfgFormPrinter->getPossibleInputTypes( $template_field->getIsList(), $template_field->getPropertyType() ); |
177 | 190 | } |
178 | | - $text .= $this->inputTypeDropdownHTML( $field_form_text, $default_input_type, $possible_input_types, $template_field->input_type ); |
| 191 | + $text .= $this->inputTypeDropdownHTML( $field_form_text, $default_input_type, $possible_input_types, $template_field->getInputType() ); |
179 | 192 | |
180 | | - if (! is_null( $template_field->input_type ) ) { |
181 | | - $cur_input_type = $template_field->input_type; |
| 193 | + if (! is_null( $template_field->getInputType() ) ) { |
| 194 | + $cur_input_type = $template_field->getInputType(); |
182 | 195 | } elseif (! is_null( $default_input_type ) ) { |
183 | 196 | $cur_input_type = $default_input_type; |
184 | 197 | } else { |
— | — | @@ -214,20 +227,19 @@ |
215 | 228 | // such templates in form definitions gets more sophisticated |
216 | 229 | function createMarkup( $part_of_multiple, $is_last_field_in_template ) { |
217 | 230 | $text = ""; |
218 | | - if ( $this->template_field->label != "" ) { |
| 231 | + if ( $this->template_field->getLabel() != '' ) { |
219 | 232 | if ( $part_of_multiple ) { |
220 | | - $text .= "'''" . $this->template_field->label . ":''' "; |
| 233 | + $text .= "'''" . $this->template_field->getLabel() . ":''' "; |
221 | 234 | } else { |
222 | | - $text .= "! " . $this->template_field->label . ":\n"; |
| 235 | + $text .= "! " . $this->template_field->getLabel() . ":\n"; |
223 | 236 | } |
224 | 237 | } |
225 | 238 | if ( ! $part_of_multiple ) { $text .= "| "; } |
226 | | - $text .= "{{{field|" . $this->template_field->field_name; |
| 239 | + $text .= "{{{field|" . $this->template_field->getFieldName(); |
227 | 240 | if ( $this->is_hidden ) { |
228 | 241 | $text .= "|hidden"; |
229 | | - } elseif ( isset( $this->template_field->input_type ) && |
230 | | - $this->template_field->input_type != null ) { |
231 | | - $text .= "|input type=" . $this->template_field->input_type; |
| 242 | + } elseif ( $this->template_field->getInputType() != '' ) { |
| 243 | + $text .= "|input type=" . $this->template_field->getInputType(); |
232 | 244 | } |
233 | 245 | foreach ( $this->field_args as $arg => $value ) { |
234 | 246 | if ( $value === true ) { |
— | — | @@ -264,25 +276,25 @@ |
265 | 277 | if ( $this->possible_values != null ) |
266 | 278 | $other_args['possible_values'] = $this->possible_values; |
267 | 279 | else { |
268 | | - $other_args['possible_values'] = $this->template_field->possible_values; |
269 | | - $other_args['value_labels'] = $this->template_field->value_labels; |
| 280 | + $other_args['possible_values'] = $this->template_field->getPossibleValues(); |
| 281 | + $other_args['value_labels'] = $this->template_field->getValueLabels(); |
270 | 282 | } |
271 | | - $other_args['is_list'] = ( $this->is_list || $this->template_field->is_list ); |
272 | | - if ( $this->template_field->semantic_property != '' && |
| 283 | + $other_args['is_list'] = ( $this->is_list || $this->template_field->getIsList() ); |
| 284 | + if ( $this->template_field->getSemanticProperty() != '' && |
273 | 285 | ! array_key_exists( 'semantic_property', $other_args ) ) { |
274 | | - $other_args['semantic_property'] = $this->template_field->semantic_property; |
275 | | - $other_args['property_type'] = $this->template_field->property_type; |
| 286 | + $other_args['semantic_property'] = $this->template_field->getSemanticProperty(); |
| 287 | + $other_args['property_type'] = $this->template_field->getPropertyType(); |
276 | 288 | } |
277 | 289 | // If autocompletion hasn't already been hardcoded in the form, |
278 | 290 | // and it's a property of type page, or a property of another |
279 | 291 | // type with 'autocomplete' specified, set the necessary |
280 | 292 | // parameters. |
281 | 293 | if ( ! array_key_exists( 'autocompletion source', $other_args ) ) { |
282 | | - if ( $this->template_field->property_type == '_wpg' ) { |
283 | | - $other_args['autocompletion source'] = $this->template_field->semantic_property; |
| 294 | + if ( $this->template_field->getPropertyType() == '_wpg' ) { |
| 295 | + $other_args['autocompletion source'] = $this->template_field->getSemanticProperty(); |
284 | 296 | $other_args['autocomplete field type'] = 'relation'; |
285 | 297 | } elseif ( array_key_exists( 'autocomplete', $other_args ) || array_key_exists( 'remote autocompletion', $other_args ) ) { |
286 | | - $other_args['autocompletion source'] = $this->template_field->semantic_property; |
| 298 | + $other_args['autocompletion source'] = $this->template_field->getSemanticProperty(); |
287 | 299 | $other_args['autocomplete field type'] = 'attribute'; |
288 | 300 | } |
289 | 301 | } |