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

Public Member Functions

 __construct ( $typeid='')
 
 parseNumberValue ( $value, &$number, &$unit, &$asPrefix=false)
 
 setOutputFormat ( $formatstring)
 
 getNumber ()
 
 getLocalizedFormattedNumber ( $value)
 
 getNormalizedFormattedNumber ( $value)
 
 getShortWikiText ( $linker=null)
 
 getShortHTMLText ( $linker=null)
 
 getLongWikiText ( $linker=null)
 
 getLongHTMLText ( $linker=null)
 
 getWikiValue ()
 
 getInfolinks ()
 
 getCanonicalMainUnit ()
 
 getConvertedUnitValues ()
 
 getUnit ()
 
 hasPrefixalUnitPreference ( $unit)
 
 normalizeUnit ( $unit)
 
 getUnitList ()
 
- Public Member Functions inherited from SMWDataValue
 __construct ( $typeid)
 
 getTypeID ()
 
 setUserValue ( $value, $caption=false)
 
 setDataItem (SMWDataItem $dataItem)
 
 setDataValueServiceFactory (DataValueServiceFactory $dataValueServiceFactory)
 
 setProperty (DIProperty $property)
 
 getProperty ()
 
 setContextPage (SMWDIWikiPage $contextPage=null)
 
 getContextPage ()
 
 setCaption ( $caption)
 
 getCaption ()
 
 getPreferredCaption ()
 
 setOutputFormat ( $formatString)
 
 getOutputFormat ()
 
 addError ( $error)
 
 addErrorMsg ( $error, $type=Message::TEXT)
 
 getErrorText ()
 
 getErrors ()
 
 getErrorsByType ( $type=null)
 
 getRestrictionError ()
 
 clearErrors ()
 
 getQueryDescription ( $value)
 
 getDataItem ()
 
 __toString ()
 
 getShortWikiText ( $linker=null)
 
 getShortHTMLText ( $linker=null)
 
 getLongWikiText ( $linker=null)
 
 getLongHTMLText ( $linker=null)
 
 getWikiValue ()
 
 getShortText ( $outputFormat, $linker=null)
 
 getLongText ( $outputFormat, $linker=null)
 
 getInfolinkText ( $outputFormat, $linker=null)
 
 getInfolinks ()
 
 getHash ()
 
 isNumeric ()
 
 isValid ()
 
 canUse ()
 
 isRestricted ()
 
 addCallable ( $key, callable $callable)
 
 hasCallable ( $key)
 
 getCallable ( $key)
 
 clearCallable ( $key)
 
 copyOptions (Options $options=null)
 
 setOption ( $key, $value)
 
 getOption ( $key, $default=false)
 
 hasFeature ( $feature)
 
 isEnabledFeature ( $feature)
 
 checkConstraints ()
 

Public Attributes

const TYPE_ID = '_num'
 
const NO_DISP_PRECISION_LIMIT = 'num.no.displayprecision.limit'
 
const DECIMAL_SEPARATOR = 'decimal.separator'
 
const THOUSANDS_SEPARATOR = 'thousands.separator'
 
- 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'
 
const OPT_DISABLE_SERVICELINKS = 'disable.servicelinks'
 
const OPT_COMPACT_INFOLINKS = 'compact.infolinks'
 

Protected Member Functions

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

Protected Attributes

 $m_unitvalues
 
 $prefixalUnitPreference = []
 
 $m_unitin
 
 $precision = null
 
- Protected Attributes inherited from SMWDataValue
 $m_dataitem
 
 $m_property = null
 
 $m_contextPage = null
 
 $m_caption
 
 $m_typeid
 
 $m_outformat = false
 
 $restrictionError = 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 choosing 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

◆ __construct()

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

Member Function Documentation

◆ convertToMainUnit()

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

◆ getCanonicalMainUnit()

SMWNumberValue::getCanonicalMainUnit ( )
Since
2.4
Returns
string

◆ getConvertedUnitValues()

SMWNumberValue::getConvertedUnitValues ( )

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

Since
2.4
Returns
array

◆ getInfolinks()

SMWNumberValue::getInfolinks ( )
See also
DataVelue::getInfolinks
Returns
array

◆ getLocalizedFormattedNumber()

SMWNumberValue::getLocalizedFormattedNumber (   $value)
Since
2.4
Returns
float

◆ getLongHTMLText()

SMWNumberValue::getLongHTMLText (   $linker = null)
See also
DataValue::getLongHTMLText
Returns
string

◆ getLongWikiText()

SMWNumberValue::getLongWikiText (   $linker = null)
See also
DataValue::getLongWikiText
Returns
string

◆ getNormalizedFormattedNumber()

SMWNumberValue::getNormalizedFormattedNumber (   $value)
Since
2.4
Returns
float

◆ getNumber()

SMWNumberValue::getNumber ( )
Since
1.6
Returns
float

◆ getServiceLinkParams()

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

◆ getShortHTMLText()

SMWNumberValue::getShortHTMLText (   $linker = null)
See also
DataValue::getShortHTMLText
Returns
string

◆ getShortWikiText()

SMWNumberValue::getShortWikiText (   $linker = null)
See also
DataValue::getShortWikiText
Returns
string

◆ getUnit()

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.

◆ getUnitList()

SMWNumberValue::getUnitList ( )

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

Overwritten by subclasses that support units.

◆ getWikiValue()

SMWNumberValue::getWikiValue ( )
See also
DataValue::getWikiValue
Returns
string

◆ hasPrefixalUnitPreference()

SMWNumberValue::hasPrefixalUnitPreference (   $unit)
Since
2.4
Parameters
string$unit
Returns
boolean

◆ loadDataItem()

SMWNumberValue::loadDataItem ( SMWDataItem  $dataItem)
protected
See also
SMWDataValue::loadDataItem()
Parameters
$dataitemSMWDataItem
Returns
boolean

◆ makeConversionValues()

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.

◆ makeUserValue()

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.

◆ normalizeUnit()

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.

◆ parseNumberValue()

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)

◆ parseUserValue()

SMWNumberValue::parseUserValue (   $value)
protected
See also
DataValue::parseUserValue

◆ setOutputFormat()

SMWNumberValue::setOutputFormat (   $formatstring)
See also
DataValue::setOutputFormat
Parameters
$string$formatstring

Member Data Documentation

◆ DECIMAL_SEPARATOR

const SMWNumberValue::DECIMAL_SEPARATOR = 'decimal.separator'

Separator related constants

◆ NO_DISP_PRECISION_LIMIT

const SMWNumberValue::NO_DISP_PRECISION_LIMIT = 'num.no.displayprecision.limit'

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

◆ TYPE_ID

const SMWNumberValue::TYPE_ID = '_num'

DV identifier


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

About | General disclaimer | Privacy policy