Semantic MediaWiki and related extensions
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SMWNumberValue Class Reference
Collaboration diagram for SMWNumberValue:
Collaboration graph
[legend]

Public Member Functions

 __construct ($typeid= '')
 
 parseNumberValue ($value, &$number, &$unit, &$asPrefix=false)
 
 setOutputFormat ($formatstring)
 
 getLocalizedFormattedNumber ($value)
 
 getNormalizedFormattedNumber ($value)
 
 getShortWikiText ($linker=null)
 
 getShortHTMLText ($linker=null)
 
 getLongWikiText ($linker=null)
 
 getLongHTMLText ($linker=null)
 
 getNumber ()
 
 getWikiValue ()
 
 getInfolinks ()
 
 getCanonicalMainUnit ()
 
 getConvertedUnitValues ()
 
 getUnit ()
 
 hasPrefixalUnitPreference ($unit)
 
 normalizeUnit ($unit)
 
 getUnitList ()
 
- Public Member Functions inherited from SMWDataValue
 __construct ($typeid)
 
 setUserValue ($value, $caption=false)
 
 setDataItem (SMWDataItem $dataItem)
 
 setDataValueServiceFactory ($dataValueServiceFactory)
 
 setProperty (SMWDIProperty $property)
 
 getProperty ()
 
 setContextPage (SMWDIWikiPage $contextPage=null)
 
 getContextPage ()
 
 setOptions (Options $options=null)
 
 setOption ($key, $value)
 
 getOption ($key)
 
 isEnabledFeature ($feature)
 
 setCaption ($caption)
 
 getCaption ()
 
 getPreferredCaption ()
 
 setOutputFormat ($formatString)
 
 getOutputFormat ()
 
 addError ($error)
 
 addErrorMsg ($parameters, $type=null)
 
 clearErrors ()
 
 getQueryDescription ($value)
 
 getDataItem ()
 
 __toString ()
 
 getShortWikiText ($linked=null)
 
 getShortHTMLText ($linker=null)
 
 getLongWikiText ($linked=null)
 
 getLongHTMLText ($linker=null)
 
 getShortText ($outputformat, $linker=null)
 
 getLongText ($outputformat, $linker=null)
 
 getInfolinkText ($outputformat, $linker=null)
 
 getWikiValue ()
 
 getTypeID ()
 
 getInfolinks ()
 
 getHash ()
 
 isNumeric ()
 
 isValid ()
 
 canUse ()
 
 getExtraneousFunctionFor ($name, array $parameters=array())
 
 getErrorText ()
 
 getErrors ()
 

Public Attributes

const TYPE_ID = '_num'
 
const NO_DISP_PRECISION_LIMIT = 'num.no.displayprecision.limit'
 
- Public Attributes inherited from SMWDataValue
const OPT_USER_LANGUAGE = 'user.language'
 
const OPT_CONTENT_LANGUAGE = 'content.language'
 
const OPT_QUERY_CONTEXT = 'query.context'
 
const OPT_QUERY_COMP_CONTEXT = 'query.comparator.context'
 
const OPT_DISABLE_INFOLINKS = 'disable.infolinks'
 

Protected Member Functions

 parseUserValue ($value)
 
 loadDataItem (SMWDataItem $dataItem)
 
 getServiceLinkParams ()
 
 convertToMainUnit ($number, $unit)
 
 makeConversionValues ()
 
 makeUserValue ()
 
 getPreferredDisplayPrecision ()
 
- Protected Member Functions inherited from SMWDataValue
 parseUserValue ($value)
 
 loadDataItem (SMWDataItem $dataItem)
 
 getServiceLinkParams ()
 
 checkAllowedValues ()
 
 getOptions ()
 

Protected Attributes

 $m_unitvalues
 
 $prefixalUnitPreference = array()
 
 $m_unitin
 
 $precision = null
 
- Protected Attributes inherited from SMWDataValue
 $m_dataitem
 
 $m_property = null
 
 $m_contextPage = null
 
 $m_caption
 
 $m_typeid
 
 $m_outformat = false
 
 $dataValueServiceFactory
 

Additional Inherited Members

- Static Public Member Functions inherited from SMWDataValue
static prepareValue (&$value, &$comparator)
 

Detailed Description

This datavalue implements numerical datavalues, and supports optional unit conversions. 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().

Author
Markus Krötzsch
Todo:
Wiki-HTML-conversion for unit strings must be revisited, as the current solution might be unsafe.

Constructor & Destructor Documentation

SMWNumberValue::__construct (   $typeid = '')
Since
2.4
Parameters
string$typeid

Member Function Documentation

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.

Parameters
$numberfloat value obtained by parsing user input
$unitstring after the numericla user input
Returns
boolean specifying if the unit string is allowed
SMWNumberValue::getCanonicalMainUnit ( )
Since
2.4
Returns
string
SMWNumberValue::getConvertedUnitValues ( )

Returns array of converted unit-value-pairs that can be printed.

Since
2.4
Returns
array
SMWNumberValue::getInfolinks ( )
See also
DataVelue::getInfolinks
Returns
array
SMWNumberValue::getLocalizedFormattedNumber (   $value)
Since
2.4
Returns
float
SMWNumberValue::getLongHTMLText (   $linker = null)
See also
DataValue::getLongHTMLText
Returns
string
SMWNumberValue::getLongWikiText (   $linker = null)
See also
DataValue::getLongWikiText
Returns
string
SMWNumberValue::getNormalizedFormattedNumber (   $value)
Since
2.4
Returns
float
SMWNumberValue::getNumber ( )
SMWNumberValue::getPreferredDisplayPrecision ( )
protected
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

Returns
array
SMWNumberValue::getShortHTMLText (   $linker = null)
See also
DataValue::getShortHTMLText
Returns
string
SMWNumberValue::getShortWikiText (   $linker = null)
See also
DataValue::getShortWikiText
Returns
string
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.

SMWNumberValue::getUnitList ( )

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

Overwritten by subclasses that support units.

SMWNumberValue::getWikiValue ( )
SMWNumberValue::hasPrefixalUnitPreference (   $unit)
Since
2.4
Parameters
string$unit
Returns
boolean
SMWNumberValue::loadDataItem ( SMWDataItem  $dataItem)
protected
See also
SMWDataValue::loadDataItem()
Parameters
$dataitemSMWDataItem
Returns
boolean
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.

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.

SMWNumberValue::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.

SMWNumberValue::parseNumberValue (   $value,
$number,
$unit,
$asPrefix = false 
)

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.

Parameters
$valuestring to parse
$numbercall-by-ref parameter that will be set to the numerical value
$unitcall-by-ref parameter that will be set to the "unit" string (after the number)
Returns
integer 0 (no errors), 1 (no number found at all), 2 (number too large for this platform)
SMWNumberValue::parseUserValue (   $value)
protected
See also
DataValue::parseUserValue
SMWNumberValue::setOutputFormat (   $formatstring)
See also
DataValue::setOutputFormat
Parameters
$string$formatstring

Member Data Documentation

SMWNumberValue::$m_unitin
protected
SMWNumberValue::$m_unitvalues
protected
SMWNumberValue::$precision = null
protected
SMWNumberValue::$prefixalUnitPreference = array()
protected
const SMWNumberValue::NO_DISP_PRECISION_LIMIT = 'num.no.displayprecision.limit'

Internal state to ensure no precision limitation is applied to an output

const SMWNumberValue::TYPE_ID = '_num'

DV identifier


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