r89257 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89256‎ | r89257 | r89258 >
Date:13:49, 1 June 2011
Author:yaron
Status:deferred
Tags:
Comment:
Replaced 'field_type' and 'field_type_id' fields with 'property_type' - simpler and clearer. Also simplified retrieval of property type.
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_TemplateField.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_TemplateField.php
@@ -14,8 +14,7 @@
1515 var $value_labels;
1616 var $label;
1717 var $semantic_property;
18 - var $field_type;
19 - var $field_type_id;
 18+ var $property_type;
2019 var $possible_values;
2120 var $is_list;
2221 var $input_type;
@@ -55,43 +54,39 @@
5655
5756 function setTypeAndPossibleValues() {
5857 $proptitle = Title::makeTitleSafe( SMW_NS_PROPERTY, $this->semantic_property );
59 - if ( $proptitle === NULL )
 58+ if ( $proptitle === null ) {
6059 return;
 60+ }
 61+
6162 $store = smwfGetStore();
62 - $types = SFUtils::getSMWPropertyValues( $store, $this->semantic_property, SMW_NS_PROPERTY, "Has type" );
6363 // this returns an array of objects
6464 $allowed_values = SFUtils::getSMWPropertyValues( $store, $this->semantic_property, SMW_NS_PROPERTY, "Allows value" );
6565 $label_formats = SFUtils::getSMWPropertyValues( $store, $this->semantic_property, SMW_NS_PROPERTY, "Has field label format" );
6666 // SMW 1.6+
6767 if ( class_exists( 'SMWDIProperty' ) ) {
6868 $propValue = new SMWDIProperty( $this->semantic_property );
69 - $this->field_type_id = $propValue->findPropertyTypeID();
 69+ $this->property_type = $propValue->findPropertyTypeID();
7070 } else {
7171 $propValue = SMWPropertyValue::makeUserProperty( $this->semantic_property );
72 - $this->field_type_id = $propValue->getPropertyTypeID();
 72+ $this->property_type = $propValue->getPropertyTypeID();
7373 }
74 - // TODO - need handling for the case of more than one type.
75 - if ( count( $types ) > 0 ) {
76 - $this->field_type = $types[0];
77 - }
7874
7975 foreach ( $allowed_values as $allowed_value ) {
8076 // HTML-unencode each value
8177 $this->possible_values[] = html_entity_decode( $allowed_value );
8278 if ( count( $label_formats ) > 0 ) {
8379 $label_format = $label_formats[0];
84 - $prop_instance = SMWDataValueFactory::findTypeID( $this->field_type );
 80+ $prop_instance = SMWDataValueFactory::findTypeID( $this->property_type );
8581 $label_value = SMWDataValueFactory::newTypeIDValue( $prop_instance, $wiki_value );
8682 $label_value->setOutputFormat( $label_format );
8783 $this->value_labels[$wiki_value] = html_entity_decode( $label_value->getWikiValue() );
8884 }
8985 }
9086
91 - // HACK - if there were any possible values, set the field
 87+ // HACK - if there were any possible values, set the property
9288 // type to be 'enumeration', regardless of what the actual type is
9389 if ( count( $this->possible_values ) > 0 ) {
94 - $this->field_type = 'enumeration';
95 - $this->field_type_id = 'enumeration';
 90+ $this->property_type = 'enumeration';
9691 }
9792 }
9893