Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.php |
— | — | @@ -10,19 +10,21 @@ |
11 | 11 | */ |
12 | 12 | |
13 | 13 | class SFTemplateField { |
14 | | - var $field_name; |
15 | | - var $value_labels; |
16 | | - var $label; |
17 | | - var $semantic_property; |
18 | | - var $property_type; |
19 | | - var $possible_values; |
20 | | - var $is_list; |
21 | | - var $input_type; |
| 14 | + private $mFieldName; |
| 15 | + private $mValueLabels; |
| 16 | + private $mLabel; |
| 17 | + private $mSemanticProperty; |
| 18 | + private $mPropertyType; |
| 19 | + private $mPossibleValues; |
| 20 | + private $mIsList; |
| 21 | + private $mInputType; |
22 | 22 | |
23 | | - static function create( $name, $label ) { |
| 23 | + static function create( $name, $label, $semanticProperty = null, $isList = null ) { |
24 | 24 | $f = new SFTemplateField(); |
25 | | - $f->field_name = trim( str_replace( '\\', '', $name ) ); |
26 | | - $f->label = trim( str_replace( '\\', '', $label ) ); |
| 25 | + $f->mFieldName = trim( str_replace( '\\', '', $name ) ); |
| 26 | + $f->mLabel = trim( str_replace( '\\', '', $label ) ); |
| 27 | + $f->setSemanticProperty( $semanticProperty ); |
| 28 | + $f->mIsList = $isList; |
27 | 29 | return $f; |
28 | 30 | } |
29 | 31 | |
— | — | @@ -38,7 +40,7 @@ |
39 | 41 | // template has a 'strict' setting in the form definition. |
40 | 42 | $the_field = null; |
41 | 43 | foreach ( $all_fields as $cur_field ) { |
42 | | - if ( $field_name == $cur_field->field_name ) { |
| 44 | + if ( $field_name == $cur_field->mFieldName ) { |
43 | 45 | $the_field = $cur_field; |
44 | 46 | break; |
45 | 47 | } |
— | — | @@ -53,7 +55,7 @@ |
54 | 56 | } |
55 | 57 | |
56 | 58 | function setTypeAndPossibleValues() { |
57 | | - $proptitle = Title::makeTitleSafe( SMW_NS_PROPERTY, $this->semantic_property ); |
| 59 | + $proptitle = Title::makeTitleSafe( SMW_NS_PROPERTY, $this->mSemanticProperty ); |
58 | 60 | if ( $proptitle === null ) { |
59 | 61 | return; |
60 | 62 | } |
— | — | @@ -64,29 +66,29 @@ |
65 | 67 | $label_formats = SFUtils::getSMWPropertyValues( $store, $proptitle, "Has field label format" ); |
66 | 68 | if ( class_exists( 'SMWDIProperty' ) ) { |
67 | 69 | // SMW 1.6+ |
68 | | - $propValue = SMWDIProperty::newFromUserLabel( $this->semantic_property ); |
69 | | - $this->property_type = $propValue->findPropertyTypeID(); |
| 70 | + $propValue = SMWDIProperty::newFromUserLabel( $this->mSemanticProperty ); |
| 71 | + $this->mPropertyType = $propValue->findPropertyTypeID(); |
70 | 72 | } else { |
71 | | - $propValue = SMWPropertyValue::makeUserProperty( $this->semantic_property ); |
72 | | - $this->property_type = $propValue->getPropertyTypeID(); |
| 73 | + $propValue = SMWPropertyValue::makeUserProperty( $this->mSemanticProperty ); |
| 74 | + $this->mPropertyType = $propValue->getPropertyTypeID(); |
73 | 75 | } |
74 | 76 | |
75 | 77 | foreach ( $allowed_values as $allowed_value ) { |
76 | 78 | // HTML-unencode each value |
77 | | - $this->possible_values[] = html_entity_decode( $allowed_value ); |
| 79 | + $this->mPossibleValues[] = html_entity_decode( $allowed_value ); |
78 | 80 | if ( count( $label_formats ) > 0 ) { |
79 | 81 | $label_format = $label_formats[0]; |
80 | | - $prop_instance = SMWDataValueFactory::findTypeID( $this->property_type ); |
| 82 | + $prop_instance = SMWDataValueFactory::findTypeID( $this->mPropertyType ); |
81 | 83 | $label_value = SMWDataValueFactory::newTypeIDValue( $prop_instance, $wiki_value ); |
82 | 84 | $label_value->setOutputFormat( $label_format ); |
83 | | - $this->value_labels[$wiki_value] = html_entity_decode( $label_value->getWikiValue() ); |
| 85 | + $this->mValueLabels[$wiki_value] = html_entity_decode( $label_value->getWikiValue() ); |
84 | 86 | } |
85 | 87 | } |
86 | 88 | |
87 | 89 | // HACK - if there were any possible values, set the property |
88 | 90 | // type to be 'enumeration', regardless of what the actual type is |
89 | | - if ( count( $this->possible_values ) > 0 ) { |
90 | | - $this->property_type = 'enumeration'; |
| 91 | + if ( count( $this->mPossibleValues ) > 0 ) { |
| 92 | + $this->mPropertyType = 'enumeration'; |
91 | 93 | } |
92 | 94 | } |
93 | 95 | |
— | — | @@ -95,12 +97,52 @@ |
96 | 98 | * a template is parsed during the creation of a form. |
97 | 99 | */ |
98 | 100 | function setSemanticProperty( $semantic_property ) { |
99 | | - $this->semantic_property = str_replace( '\\', '', $semantic_property ); |
100 | | - $this->possible_values = array(); |
| 101 | + $this->mSemanticProperty = str_replace( '\\', '', $semantic_property ); |
| 102 | + $this->mPossibleValues = array(); |
101 | 103 | // set field type and possible values, if any |
102 | 104 | $this->setTypeAndPossibleValues(); |
103 | 105 | } |
104 | 106 | |
| 107 | + function getFieldName() { |
| 108 | + return $this->mFieldName; |
| 109 | + } |
| 110 | + |
| 111 | + function getValueLabels() { |
| 112 | + return $this->mValueLabels; |
| 113 | + } |
| 114 | + |
| 115 | + function getLabel() { |
| 116 | + return $this->mLabel; |
| 117 | + } |
| 118 | + |
| 119 | + function getSemanticProperty() { |
| 120 | + return $this->mSemanticProperty; |
| 121 | + } |
| 122 | + |
| 123 | + function getPropertyType() { |
| 124 | + return $this->mPropertyType; |
| 125 | + } |
| 126 | + |
| 127 | + function getPossibleValues() { |
| 128 | + return $this->mPossibleValues; |
| 129 | + } |
| 130 | + |
| 131 | + function getIsList() { |
| 132 | + return $this->mIsList; |
| 133 | + } |
| 134 | + |
| 135 | + function getInputType() { |
| 136 | + return $this->mInputType; |
| 137 | + } |
| 138 | + |
| 139 | + function setTemplateField( $templateField ) { |
| 140 | + $this->mTemplateField = $templateField; |
| 141 | + } |
| 142 | + |
| 143 | + function setLabel( $label ) { |
| 144 | + $this->mLabel = $label; |
| 145 | + } |
| 146 | + |
105 | 147 | /** |
106 | 148 | * Creates the text of a template, when called from either |
107 | 149 | * Special:CreateTemplate or Special:CreateClass. |
— | — | @@ -119,7 +161,7 @@ |
120 | 162 | $text .= '{{' . $template_name; |
121 | 163 | if ( count( $template_fields ) > 0 ) { $text .= "\n"; } |
122 | 164 | foreach ( $template_fields as $field ) { |
123 | | - $text .= "|" . $field->field_name . "=\n"; |
| 165 | + $text .= "|" . $field->mFieldName . "=\n"; |
124 | 166 | } |
125 | 167 | $template_footer = wfMsgForContent( 'sf_template_docufooter' ); |
126 | 168 | $text .= <<<END |
— | — | @@ -156,35 +198,35 @@ |
157 | 199 | if ( $i > 0 ) { |
158 | 200 | $tableText .= "|-\n"; |
159 | 201 | } |
160 | | - $tableText .= "! " . $field->label . "\n"; |
161 | | - if ( $field->semantic_property == null || $field->semantic_property == '' ) { |
162 | | - $tableText .= "| {{{" . $field->field_name . "|}}}\n"; |
| 202 | + $tableText .= "! " . $field->mLabel . "\n"; |
| 203 | + if ( empty( $field->mSemanticProperty ) ) { |
| 204 | + $tableText .= "| {{{" . $field->mFieldName . "|}}}\n"; |
163 | 205 | // if this field is meant to contain a list, |
164 | 206 | // add on an 'arraymap' function, that will |
165 | 207 | // call this semantic markup tag on every |
166 | 208 | // element in the list |
167 | 209 | } elseif ( !is_null( $setInternalText ) ) { |
168 | | - if ( $field->is_list ) { |
169 | | - $setInternalText .= '|' . $field->semantic_property . '#list={{{' . $field->field_name . '|}}}'; |
| 210 | + if ( $field->mIsList ) { |
| 211 | + $setInternalText .= '|' . $field->mSemanticProperty . '#list={{{' . $field->mFieldName . '|}}}'; |
170 | 212 | } else { |
171 | | - $setInternalText .= '|' . $field->semantic_property . '={{{' . $field->field_name . '|}}}'; |
| 213 | + $setInternalText .= '|' . $field->mSemanticProperty . '={{{' . $field->mFieldName . '|}}}'; |
172 | 214 | } |
173 | | - } elseif ( $field->is_list ) { |
| 215 | + } elseif ( $field->mIsList ) { |
174 | 216 | // find a string that's not in the semantic |
175 | 217 | // field call, to be used as the variable |
176 | 218 | $var = "x"; // default - use this if all the attempts fail |
177 | | - if ( strstr( $field->semantic_property, $var ) ) { |
| 219 | + if ( strstr( $field->mSemanticProperty, $var ) ) { |
178 | 220 | $var_options = array( 'y', 'z', 'xx', 'yy', 'zz', 'aa', 'bb', 'cc' ); |
179 | 221 | foreach ( $var_options as $option ) { |
180 | | - if ( ! strstr( $field->semantic_property, $option ) ) { |
| 222 | + if ( ! strstr( $field->mSemanticProperty, $option ) ) { |
181 | 223 | $var = $option; |
182 | 224 | break; |
183 | 225 | } |
184 | 226 | } |
185 | 227 | } |
186 | | - $tableText .= "| {{#arraymap:{{{" . $field->field_name . "|}}}|,|$var|[[" . $field->semantic_property . "::$var]]}}\n"; |
| 228 | + $tableText .= "| {{#arraymap:{{{" . $field->mFieldName . "|}}}|,|$var|[[" . $field->mSemanticProperty . "::$var]]}}\n"; |
187 | 229 | } else { |
188 | | - $tableText .= "| [[" . $field->semantic_property . "::{{{" . $field->field_name . "|}}}]]\n"; |
| 230 | + $tableText .= "| [[" . $field->mSemanticProperty . "::{{{" . $field->mFieldName . "|}}}]]\n"; |
189 | 231 | } |
190 | 232 | } |
191 | 233 | |