SMWTemperatureValue Class Reference
[SMWDataValues]

This datavalue implements unit support for measuring temperatures. 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.
 getUnitID ($unit)
 Helper method to find the main representation of a certain unit.


Detailed Description

This datavalue implements unit support for measuring temperatures.

This is mostly an example implementation of how to realise custom unit types easily. The implementation lacks support for localization and for selecting "display units" on the property page as possible for the types with linear unit conversion.

Author:
Markus Krötzsch

Definition at line 17 of file SMW_DV_Temperature.php.


Member Function Documentation

SMWTemperatureValue::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 19 of file SMW_DV_Temperature.php.

References getUnitID().

SMWTemperatureValue::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 42 of file SMW_DV_Temperature.php.

References SMWDataValue::isValid().

SMWTemperatureValue::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 55 of file SMW_DV_Temperature.php.

References getUnitID(), SMWNumberValue::normalizeUnit(), and smwfNumberFormat().

SMWTemperatureValue::getUnitID ( unit  )  [protected]

Helper method to find the main representation of a certain unit.

TODO possibly localise some of those strings

Definition at line 98 of file SMW_DV_Temperature.php.

Referenced by convertToMainUnit(), and makeUserValue().

SMWTemperatureValue::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 111 of file SMW_DV_Temperature.php.

SMWTemperatureValue::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 115 of file SMW_DV_Temperature.php.


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

Generated on Fri Feb 10 07:15:48 2012 for Semantic MediaWiki by  doxygen 1.5.6