Inherits SMWDataValue.
Inherited by SMWQuantityValue, and SMWTemperatureValue.
Public Member Functions | |
| setOutputFormat ($formatstring) | |
| Define a particular output format. | |
| getShortWikiText ($linked=null) | |
| Returns a short textual representation for this data value. | |
| getShortHTMLText ($linker=null) | |
| Returns a short textual representation for this data value. | |
| getLongWikiText ($linked=null) | |
| Return the long textual description of the value, as printed for example in the factbox. | |
| getLongHTMLText ($linker=null) | |
| Return the long textual description of the value, as printed for example in the factbox. | |
| getNumber () | |
| getWikiValue () | |
| Return the plain wiki version of the value, or FALSE if no such version is available. | |
| getUnit () | |
| Return the unit in which the returned value is to be interpreted. | |
| getUnitList () | |
| Return an array of major unit strings (ids only recommended) supported by this datavalue. | |
Protected Member Functions | |
| parseUserValue ($value) | |
| Initialise the datavalue from the given value string. | |
| loadDataItem (SMWDataItem $dataItem) | |
| getServiceLinkParams () | |
| Create links to mapping services based on a wiki-editable message. | |
| 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. | |
Static Protected Member Functions | |
| static | parseNumberValue ($value, &$number, &$unit) |
| Parse a string of the form "number unit" where unit is optional. | |
| static | normalizeUnit ($unit) |
| Transform a (typically unit-) string into a normalised form, so that, e.g., "km²" and "km<sup>2</sup>" do not need to be distinguished. | |
Protected Attributes | |
| $m_unitvalues | |
| $m_unitin | |
It parses and manages unit strings, since even plain numbers may have (not further specified) units that are stored. However, only subclasses implement full unit conversion by extending the methods convertToMainUnit() and makeConversionValues().
Units work as follows: a unit is a string, but many such strings might refer to the same unit of measurement. There is always one string, that canonically represents the unit, and we will call this version of writing the unit the /unit id/. IDs for units are needed for tasks like duplicate avoidance. If no conversion information is given, any unit is its own ID. In any case, units are /normalised/, i.e. given a more standardised meaning before being processed. All units, IDs or otherwise, should be suitable for printout in wikitext, and main IDs should moreover be suitable for printout in HTML.
Subclasses that support unit conversion may interpret the output format set via setOutputFormat() to allow a unit to be selected for display. Note that this setting does not affect the internal representation of the value though. So chosing a specific output format will change the behavior of output functions like getLongWikiText(), but not of functions that access the value itself, such as getUnit() or getDBKeys().
Definition at line 37 of file SMW_DV_Number.php.
| static SMWNumberValue::parseNumberValue | ( | $ | value, | |
| &$ | number, | |||
| &$ | unit | |||
| ) | [static, protected] |
Parse a string of the form "number unit" where unit is optional.
The results are stored in the $number and $unit parameters. Returns an error code.
| $value | string to parse | |
| $number | call-by-ref parameter that will be set to the numerical value | |
| $unit | call-by-ref parameter that will be set to the "unit" string (after the number) |
Definition at line 67 of file SMW_DV_Number.php.
Referenced by SMWQuantityValue::initConversionData().
| SMWNumberValue::parseUserValue | ( | $ | value | ) | [protected] |
Initialise the datavalue from the given value string.
The format of this strings might be any acceptable user input and especially includes the output of getWikiValue().
| string | $value |
Reimplemented from SMWDataValue.
Definition at line 97 of file SMW_DV_Number.php.
References SMWDataValue::addError(), and convertToMainUnit().
| SMWNumberValue::loadDataItem | ( | SMWDataItem $ | dataItem | ) | [protected] |
| $dataitem | SMWDataItem |
Reimplemented from SMWDataValue.
Definition at line 120 of file SMW_DV_Number.php.
References makeUserValue(), and SMWDataItem::TYPE_NUMBER.
| SMWNumberValue::setOutputFormat | ( | $ | formatString | ) |
Define a particular output format.
Output formats are user-supplied strings that the datavalue may (or may not) use to customise its return value. For example, quantities with units of measurement may interpret the string as a desired output unit. In other cases, the output format might be built-in and subject to internationalisation (which the datavalue has to implement). In any case, an empty string resets the output format to the default.
There is one predeeind output format that all datavalues should respect: the format '-' indicates "plain" output that is most useful for further processing the value in a template. It should not use any wiki markup or beautification, and it should also avoid localization to the current language. When users explicitly specify an empty format string in a query, it is normalized to "-" to avoid confusion. Note that empty format strings are not interpreted in this way when directly passed to this function.
| string | $formatString |
Reimplemented from SMWDataValue.
Definition at line 133 of file SMW_DV_Number.php.
References SMWDataValue::isValid(), and makeUserValue().
| SMWNumberValue::getShortWikiText | ( | $ | linked = null |
) |
Returns a short textual representation for this data value.
If the value was initialised from a user supplied string, then this original string should be reflected in this short version (i.e. no normalisation should normally happen). There might, however, be additional parts such as code for generating tooltips. The output is in wiki text.
The parameter $linked controls linking of values such as titles and should be non-NULL and non-false if this is desired.
Reimplemented from SMWDataValue.
Definition at line 144 of file SMW_DV_Number.php.
References SMWDataValue::isValid(), makeConversionValues(), SMWOutputs::requireResource(), and smwfNumberFormat().
Referenced by getShortHTMLText().
| SMWNumberValue::getShortHTMLText | ( | $ | linker = null |
) |
Returns a short textual representation for this data value.
If the value was initialised from a user supplied string, then this original string should be reflected in this short version (i.e. no normalisation should normally happen). There might, however, be additional parts such as code for generating tooltips. The output is in HTML text.
The parameter $linker controls linking of values such as titles and should be some Linker object (or NULL for no linking).
Reimplemented from SMWDataValue.
Definition at line 175 of file SMW_DV_Number.php.
References getShortWikiText().
| SMWNumberValue::getLongWikiText | ( | $ | linked = null |
) |
Return the long textual description of the value, as printed for example in the factbox.
If errors occurred, return the error message The result always is a wiki-source string.
The parameter $linked controls linking of values such as titles and should be non-NULL and non-false if this is desired.
Reimplemented from SMWDataValue.
Definition at line 179 of file SMW_DV_Number.php.
References SMWDataValue::getErrorText(), SMWDataValue::isValid(), makeConversionValues(), and smwfNumberFormat().
Referenced by getLongHTMLText().
| SMWNumberValue::getLongHTMLText | ( | $ | linker = null |
) |
Return the long textual description of the value, as printed for example in the factbox.
If errors occurred, return the error message The result always is an HTML string.
The parameter $linker controls linking of values such as titles and should be some Linker object (or NULL for no linking).
Reimplemented from SMWDataValue.
Definition at line 208 of file SMW_DV_Number.php.
References getLongWikiText().
| SMWNumberValue::getNumber | ( | ) |
| SMWNumberValue::getWikiValue | ( | ) |
Return the plain wiki version of the value, or FALSE if no such version is available.
The returned string suffices to reobtain the same DataValue when passing it as an input string to setUserValue().
Reimplemented from SMWDataValue.
Definition at line 216 of file SMW_DV_Number.php.
References getUnit(), SMWDataValue::isValid(), and smwfNumberFormat().
| SMWNumberValue::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 in SMWQuantityValue, and SMWTemperatureValue.
Definition at line 232 of file SMW_DV_Number.php.
Referenced by getWikiValue().
| SMWNumberValue::getServiceLinkParams | ( | ) | [protected] |
Create links to mapping services based on a wiki-editable message.
The parameters available to the message are: $1: string of numerical value in English punctuation $2: string of integer version of value, in English punctuation
Reimplemented from SMWDataValue.
Definition at line 244 of file SMW_DV_Number.php.
References SMWDataValue::isValid().
| static SMWNumberValue::normalizeUnit | ( | $ | unit | ) | [static, protected] |
Transform a (typically unit-) string into a normalised form, so that, e.g., "km²" and "km<sup>2</sup>" do not need to be distinguished.
Definition at line 257 of file SMW_DV_Number.php.
References smwfXMLContentEncode().
Referenced by SMWQuantityValue::initConversionData(), SMWQuantityValue::initDisplayData(), SMWTemperatureValue::makeUserValue(), and SMWQuantityValue::makeUserValue().
| SMWNumberValue::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.
| $number | float value obtained by parsing user input | |
| $unit | string after the numericla user input |
Reimplemented in SMWQuantityValue, and SMWTemperatureValue.
Definition at line 276 of file SMW_DV_Number.php.
Referenced by parseUserValue().
| SMWNumberValue::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 in SMWQuantityValue, and SMWTemperatureValue.
Definition at line 295 of file SMW_DV_Number.php.
Referenced by getLongWikiText(), and getShortWikiText().
| SMWNumberValue::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 in SMWQuantityValue, and SMWTemperatureValue.
Definition at line 308 of file SMW_DV_Number.php.
References smwfNumberFormat().
Referenced by loadDataItem(), and setOutputFormat().
| SMWNumberValue::getUnitList | ( | ) |
Return an array of major unit strings (ids only recommended) supported by this datavalue.
Overwritten by subclasses that support units.
Reimplemented in SMWQuantityValue, and SMWTemperatureValue.
Definition at line 323 of file SMW_DV_Number.php.
SMWNumberValue::$m_unitvalues [protected] |
Definition at line 44 of file SMW_DV_Number.php.
SMWNumberValue::$m_unitin [protected] |
Definition at line 55 of file SMW_DV_Number.php.
1.5.6