r93055 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93054‎ | r93055 | r93056 >
Date:16:16, 25 July 2011
Author:yaron
Status:deferred
Tags:
Comment:
Made all class fields private, renamed them for consistency, and added more getter and setter methods
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormField.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormField.php
@@ -13,58 +13,58 @@
1414 * @ingroup SF
1515 */
1616 class SFFormField {
17 - private $num;
 17+ private $mNum;
1818 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;
 19+ private $mInputType;
 20+ private $mIsMandatory;
 21+ private $mIsHidden;
 22+ private $mIsRestricted;
 23+ private $mPossibleValues;
 24+ private $mIsList;
2525 // the following fields are not set by the form-creation page
2626 // (though they could be)
27 - private $is_uploadable;
28 - private $field_args;
 27+ private $mIsUploadable;
 28+ private $mFieldArgs;
2929 // somewhat of a hack - these two fields are for a field in a specific
3030 // representation of a form, not the form definition; ideally these
3131 // should be contained in a third 'field' class, called something like
3232 // SFFormInstanceField, that holds these fields plus an instance of
3333 // SFFormField. Too much work?
34 - public $input_name;
35 - public $is_disabled;
 34+ private $mInputName;
 35+ private $mIsDisabled;
3636
3737 static function create( $num, $template_field ) {
3838 $f = new SFFormField();
39 - $f->num = $num;
 39+ $f->mNum = $num;
4040 $f->template_field = $template_field;
41 - $f->input_type = "";
42 - $f->is_mandatory = false;
43 - $f->is_hidden = false;
44 - $f->is_restricted = false;
45 - $f->is_uploadable = false;
46 - $f->possible_values = null;
47 - $f->field_args = array();
 41+ $f->mInputType = "";
 42+ $f->mIsMandatory = false;
 43+ $f->mIsHidden = false;
 44+ $f->mIsRestricted = false;
 45+ $f->mIsUploadable = false;
 46+ $f->mPossibleValues = null;
 47+ $f->mFieldArgs = array();
4848 return $f;
4949 }
5050
51 - static function createFromDefinition( $field_name, $input_name, $is_mandatory, $is_hidden, $is_uploadable, $possible_values, $is_disabled, $is_list, $input_type, $field_args, $all_fields, $strict_parsing ) {
 51+ static function createFromDefinition( $fieldName, $inputName, $isMandatory, $isHidden, $isUploadable, $possibleValues, $isDisabled, $isList, $inputType, $fieldArgs, $allFields, $strictParsing ) {
5252 // see if this field matches one of the fields defined for this
5353 // template - if it is, use all available information about
5454 // that field; if it's not, either include it in the form or
5555 // not, depending on whether the template has a 'strict'
5656 // setting in the form definition
5757 $the_field = null;
58 - foreach ( $all_fields as $cur_field ) {
59 - if ( $field_name == $cur_field->getFieldName() ) {
 58+ foreach ( $allFields as $cur_field ) {
 59+ if ( $fieldName == $cur_field->getFieldName() ) {
6060 $the_field = $cur_field;
6161 break;
6262 }
6363 }
6464 if ( $the_field == null ) {
65 - if ( $strict_parsing ) {
 65+ if ( $strictParsing ) {
6666 $dummy_ff = new SFFormField();
6767 $dummy_ff->template_field = new SFTemplateField();
68 - $dummy_ff->is_list = false;
 68+ $dummy_ff->mIsList = false;
6969 return $dummy_ff;
7070 }
7171 $the_field = new SFTemplateField();
@@ -74,15 +74,15 @@
7575 // as settings from the form definition file
7676 $f = new SFFormField();
7777 $f->template_field = $the_field;
78 - $f->is_mandatory = $is_mandatory;
79 - $f->is_hidden = $is_hidden;
80 - $f->is_uploadable = $is_uploadable;
81 - $f->possible_values = $possible_values;
82 - $f->input_type = $input_type;
83 - $f->field_args = $field_args;
84 - $f->input_name = $input_name;
85 - $f->is_disabled = $is_disabled;
86 - $f->is_list = $is_list;
 78+ $f->mIsMandatory = $isMandatory;
 79+ $f->mIsHidden = $isHidden;
 80+ $f->mIsUploadable = $isUploadable;
 81+ $f->mPossibleValues = $possibleValues;
 82+ $f->mInputType = $inputType;
 83+ $f->mFieldArgs = $fieldArgs;
 84+ $f->mInputName = $inputName;
 85+ $f->mIsDisabled = $isDisabled;
 86+ $f->mIsList = $isList;
8787 return $f;
8888 }
8989
@@ -91,13 +91,37 @@
9292 }
9393
9494 public function getInputType() {
95 - return $this->input_type;
 95+ return $this->mInputType;
9696 }
9797
 98+ public function isMandatory() {
 99+ return $this->mIsMandatory;
 100+ }
 101+
 102+ public function isHidden() {
 103+ return $this->mIsHidden;
 104+ }
 105+
 106+ public function isList() {
 107+ return $this->mIsList;
 108+ }
 109+
 110+ public function getInputName() {
 111+ return $this->mInputName;
 112+ }
 113+
 114+ public function isDisabled() {
 115+ return $this->mIsDisabled;
 116+ }
 117+
98118 public function setTemplateField( $templateField ) {
99119 $this->template_field = $templateField;
100120 }
101121
 122+ public function setIsHidden( $isHidden ) {
 123+ $this->mIsHidden = $isHidden;
 124+ }
 125+
102126 public function setSemanticProperty( $semanticProperty ) {
103127 $this->template_field->setSemanticProperty( $semanticProperty );
104128 }
@@ -130,7 +154,7 @@
131155 }
132156
133157 function creationHTML( $template_num ) {
134 - $field_form_text = $template_num . "_" . $this->num;
 158+ $field_form_text = $template_num . "_" . $this->mNum;
135159 $template_field = $this->template_field;
136160 $text = '<h3>' . wfMsg( 'sf_createform_field' ) . " '" . $template_field->getFieldName() . "'</h3>\n";
137161 $prop_link_text = SFUtils::linkText( SMW_NS_PROPERTY, $template_field->getSemanticProperty() );
@@ -140,7 +164,7 @@
141165 } elseif ( $template_field->getPropertyType() == "" ) {
142166 $text .= '<p>' . wfMsg( 'sf_createform_fieldpropunknowntype', $prop_link_text ) . "</p>\n";
143167 } else {
144 - if ( $template_field->getIsList() ) {
 168+ if ( $template_field->isList() ) {
145169 $propDisplayMsg = 'sf_createform_fieldproplist';
146170 } else {
147171 $propDisplayMsg = 'sf_createform_fieldprop';
@@ -184,8 +208,8 @@
185209 $default_input_type = null;
186210 $possible_input_types = $sfgFormPrinter->getAllInputTypes();
187211 } else {
188 - $default_input_type = $sfgFormPrinter->getDefaultInputType( $template_field->getIsList(), $template_field->getPropertyType() );
189 - $possible_input_types = $sfgFormPrinter->getPossibleInputTypes( $template_field->getIsList(), $template_field->getPropertyType() );
 212+ $default_input_type = $sfgFormPrinter->getDefaultInputType( $template_field->isList(), $template_field->getPropertyType() );
 213+ $possible_input_types = $sfgFormPrinter->getPossibleInputTypes( $template_field->isList(), $template_field->getPropertyType() );
190214 }
191215 $text .= $this->inputTypeDropdownHTML( $field_form_text, $default_input_type, $possible_input_types, $template_field->getInputType() );
192216
@@ -236,21 +260,21 @@
237261 }
238262 if ( ! $part_of_multiple ) { $text .= "| "; }
239263 $text .= "{{{field|" . $this->template_field->getFieldName();
240 - if ( $this->is_hidden ) {
 264+ if ( $this->mIsHidden ) {
241265 $text .= "|hidden";
242266 } elseif ( $this->template_field->getInputType() != '' ) {
243267 $text .= "|input type=" . $this->template_field->getInputType();
244268 }
245 - foreach ( $this->field_args as $arg => $value ) {
 269+ foreach ( $this->mFieldArgs as $arg => $value ) {
246270 if ( $value === true ) {
247271 $text .= "|$arg";
248272 } else {
249273 $text .= "|$arg=$value";
250274 }
251275 }
252 - if ( $this->is_mandatory ) {
 276+ if ( $this->mIsMandatory ) {
253277 $text .= "|mandatory";
254 - } elseif ( $this->is_restricted ) {
 278+ } elseif ( $this->mIsRestricted ) {
255279 $text .= "|restricted";
256280 }
257281 $text .= "}}}\n";
@@ -270,16 +294,16 @@
271295 */
272296 function getArgumentsForInputCall( $default_args = null ) {
273297 // start with the arguments array already defined
274 - $other_args = $this->field_args;
 298+ $other_args = $this->mFieldArgs;
275299 // a value defined for the form field should always supersede
276300 // the coresponding value for the template field
277 - if ( $this->possible_values != null )
278 - $other_args['possible_values'] = $this->possible_values;
279 - else {
 301+ if ( $this->mPossibleValues != null ) {
 302+ $other_args['possible_values'] = $this->mPossibleValues;
 303+ } else {
280304 $other_args['possible_values'] = $this->template_field->getPossibleValues();
281305 $other_args['value_labels'] = $this->template_field->getValueLabels();
282306 }
283 - $other_args['is_list'] = ( $this->is_list || $this->template_field->getIsList() );
 307+ $other_args['is_list'] = ( $this->mIsList || $this->template_field->isList() );
284308 if ( $this->template_field->getSemanticProperty() != '' &&
285309 ! array_key_exists( 'semantic_property', $other_args ) ) {
286310 $other_args['semantic_property'] = $this->template_field->getSemanticProperty();