SMWQuantityValue Class Reference
[SMWDataValues]

This datavalue implements unit support custom units, for which users have provided linear conversion factors within the wiki. More...

Inherits SMWNumberValue.

List of all members.

Public Member Functions

 getUnitList ()
 Return an array of major unit strings (ids only recommended) supported by this datavalue.
 getUnit ()
 Return the unit in which the returned value is to be interpreted.

Protected Member Functions

 convertToMainUnit ($number, $unit)
 Compute the value based on the given input number and unit string.
 makeConversionValues ()
 This method creates an array of unit-value-pairs that should be printed.
 makeUserValue ()
 This method is used when no user input was given to find the best values for m_unitin and m_caption.
 initConversionData ()
 The remaining functions are relatively "private" but are kept protected since subclasses might exploit this to, e.g., "fake" conversion factors instead of getting them from the database.
 initDisplayData ()
 This method initializes $m_displayunits.

Protected Attributes

 $m_unitfactors = false
 Array with format (canonical unit ID string) => (conversion factor).
 $m_unitids = false
 Array with format (normalised unit string) => (canonical unit ID string).
 $m_displayunits = false
 Ordered array of (normalized) units that should be displayed in tooltips, etc.
 $m_mainunit = false
 Main unit in canonical form (recognised by the conversion factor 1).


Detailed Description

This datavalue implements unit support custom units, for which users have provided linear conversion factors within the wiki.

Those user settings are retrieved from a property page associated with this object.

Author:
Markus Krötzsch

Definition at line 15 of file SMW_DV_Quantity.php.


Member Function Documentation

SMWQuantityValue::convertToMainUnit ( number,
unit 
) [protected]

Compute the value based on the given input number and unit string.

If the unit is not supported, return false, otherwise return true. This is called when parsing user input, where the given unit value has already been normalized.

This class does not support any (non-empty) units, but subclasses may overwrite this behavior.

Parameters:
$number float value obtained by parsing user input
$unit string after the numericla user input
Returns:
boolean specifying if the unit string is allowed

Reimplemented from SMWNumberValue.

Definition at line 26 of file SMW_DV_Quantity.php.

References initConversionData().

SMWQuantityValue::makeConversionValues (  )  [protected]

This method creates an array of unit-value-pairs that should be printed.

Units are the keys and should be canonical unit IDs. The result is stored in $this->m_unitvalues. Again, any class that requires effort for doing this should first check whether the array is already set (i.e. not false) before doing any work. Note that the values should be plain numbers. Output formatting is done later when needed. Also, it should be checked if the value is valid before trying to calculate with its contents. This method also must call or implement convertToMainUnit().

Overwritten by subclasses that support units.

Reimplemented from SMWNumberValue.

Definition at line 38 of file SMW_DV_Quantity.php.

References initDisplayData(), and SMWDataValue::isValid().

SMWQuantityValue::makeUserValue (  )  [protected]

This method is used when no user input was given to find the best values for m_unitin and m_caption.

After conversion, these fields will look as if they were generated from user input, and convertToMainUnit() will have been called (if not, it would be blocked by the presence of m_unitin).

Overwritten by subclasses that support units.

Reimplemented from SMWNumberValue.

Definition at line 60 of file SMW_DV_Quantity.php.

References getUnit(), initDisplayData(), SMWNumberValue::normalizeUnit(), and smwfNumberFormat().

SMWQuantityValue::getUnitList (  ) 

Return an array of major unit strings (ids only recommended) supported by this datavalue.

Overwritten by subclasses that support units.

Reimplemented from SMWNumberValue.

Definition at line 98 of file SMW_DV_Quantity.php.

References initConversionData().

SMWQuantityValue::getUnit (  ) 

Return the unit in which the returned value is to be interpreted.

This string is a plain UTF-8 string without wiki or html markup. The returned value is a canonical ID for the main unit. Returns the empty string if no unit is given for the value. Overwritten by subclasses that support units.

Reimplemented from SMWNumberValue.

Definition at line 103 of file SMW_DV_Quantity.php.

References initConversionData().

Referenced by makeUserValue().

SMWQuantityValue::initConversionData (  )  [protected]

The remaining functions are relatively "private" but are kept protected since subclasses might exploit this to, e.g., "fake" conversion factors instead of getting them from the database.

A cheap way of making built-in types. This method initializes $m_unitfactors, $m_unitids, and $m_mainunit.

Definition at line 115 of file SMW_DV_Quantity.php.

References SMWDataValue::addError(), SMWNumberValue::normalizeUnit(), SMWNumberValue::parseNumberValue(), smwfGetStore(), and SMWDataItem::TYPE_STRING.

Referenced by convertToMainUnit(), getUnit(), getUnitList(), and initDisplayData().

SMWQuantityValue::initDisplayData (  )  [protected]

This method initializes $m_displayunits.

Definition at line 171 of file SMW_DV_Quantity.php.

References initConversionData(), SMWNumberValue::normalizeUnit(), smwfGetStore(), and SMWDataItem::TYPE_STRING.

Referenced by makeConversionValues(), and makeUserValue().


Member Data Documentation

SMWQuantityValue::$m_unitfactors = false [protected]

Array with format (canonical unit ID string) => (conversion factor).

Definition at line 18 of file SMW_DV_Quantity.php.

SMWQuantityValue::$m_unitids = false [protected]

Array with format (normalised unit string) => (canonical unit ID string).

Definition at line 20 of file SMW_DV_Quantity.php.

SMWQuantityValue::$m_displayunits = false [protected]

Ordered array of (normalized) units that should be displayed in tooltips, etc.

Definition at line 22 of file SMW_DV_Quantity.php.

SMWQuantityValue::$m_mainunit = false [protected]

Main unit in canonical form (recognised by the conversion factor 1).

Definition at line 24 of file SMW_DV_Quantity.php.


The documentation for this class was generated from the following file:

Generated on Sun Mar 18 07:15:43 2012 for Semantic MediaWiki by  doxygen 1.5.6