Index: trunk/extensions/SemanticMediaWiki/includes/SMW_OldDataValue.php |
— | — | @@ -115,6 +115,8 @@ |
116 | 116 | var $attribute; // wiki name (without namespace) of the attribute that this value was |
117 | 117 | // assigned to, or FALSE if no attribute was given. |
118 | 118 | /**#@-*/ |
| 119 | + |
| 120 | + private $byxsd = false; // hack hack hack (temporary to ease DV transition) |
119 | 121 | |
120 | 122 | /** |
121 | 123 | * Just initialise variables. To create value objects, use one of the |
— | — | @@ -139,6 +141,7 @@ |
140 | 142 | */ |
141 | 143 | function setUserValue($value) { |
142 | 144 | $this->clear(); |
| 145 | + $this->byxsd = false; // DV transition hack to distinguish this case and to use others[0] for XSD-values |
143 | 146 | $this->vuser = $value; |
144 | 147 | //this is needed since typehandlers are not strictly required to |
145 | 148 | //set the user value, especially if errors are reported. |
— | — | @@ -154,6 +157,7 @@ |
155 | 158 | * Set the xsd value (and compute other representations if possible) |
156 | 159 | */ |
157 | 160 | function setXSDValue($value, $unit) { |
| 161 | + $this->byxsd = true; // DV transition hack to distinguish this case and to use others[0] for XSD-values |
158 | 162 | $this->vxsd = $value; |
159 | 163 | if ($this->type_handler === NULL) { |
160 | 164 | return false; |
— | — | @@ -173,7 +177,7 @@ |
174 | 178 | * @param unit - see $unit |
175 | 179 | */ |
176 | 180 | function setProcessedValues($user, $xsd, $num=NULL, $unit='') { |
177 | | - $this->vuser = $user; |
| 181 | + $this->vuser = $user; |
178 | 182 | $this->vxsd = $xsd; |
179 | 183 | $this->vnum = $num; |
180 | 184 | $this->unit = $unit; |
— | — | @@ -296,13 +300,29 @@ |
297 | 301 | $this->infolinks = array(); |
298 | 302 | } |
299 | 303 | |
| 304 | + public function setOutputFormat($formatstring) { |
| 305 | + // interpret new output format as the desired unit for united quantities |
| 306 | + $this->setDesiredUnits(array($formatstring)); |
| 307 | + } |
300 | 308 | |
| 309 | + |
301 | 310 | /*********************************************************************/ |
302 | 311 | /* Get methods */ |
303 | 312 | /*********************************************************************/ |
304 | 313 | |
305 | 314 | public function getShortWikiText($linked = NULL) { |
306 | | - return $this->vuser; |
| 315 | + // behave like old getUserValue if DV was initialised from user value, |
| 316 | + // else behave like old getStringValue. Transition hack. |
| 317 | + if ($this->byxsd) { |
| 318 | + if ( count($this->others) > 0 ) { |
| 319 | + reset($this->others); |
| 320 | + return current($this->others); // return first element |
| 321 | + } else { |
| 322 | + return $this->vuser; |
| 323 | + } |
| 324 | + } else { |
| 325 | + return $this->vuser; |
| 326 | + } |
307 | 327 | } |
308 | 328 | |
309 | 329 | public function getShortHTMLText($linker = NULL) { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -101,6 +101,16 @@ |
102 | 102 | */ |
103 | 103 | abstract public function setAttribute($attribute); |
104 | 104 | |
| 105 | + /** |
| 106 | + * Define a particular output format. Output formats are user-supplied strings |
| 107 | + * that the datavalue may (or may not) use to customise its return value. For |
| 108 | + * example, quantities with units of measurement may interpret the string as |
| 109 | + * a desired output unit. In other cases, the output format might be built-in |
| 110 | + * and subject to internationalisation (which the datavalue has to implement). |
| 111 | + * In any case, an empty string resets the output format to the default. |
| 112 | + */ |
| 113 | + abstract public function setOutputFormat($formatstring); |
| 114 | + |
105 | 115 | /*********************************************************************/ |
106 | 116 | /* Get methods */ |
107 | 117 | /*********************************************************************/ |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php |
— | — | @@ -25,10 +25,11 @@ |
26 | 26 | * obtain additional information for the retrieved results. |
27 | 27 | */ |
28 | 28 | class SMWPrintRequest { |
29 | | - protected $m_mode; |
30 | | - protected $m_label; |
31 | | - protected $m_title; |
32 | | - protected $m_datavalue; |
| 29 | + protected $m_mode; // type of print request |
| 30 | + protected $m_label; // string for labelling results, contains no markup |
| 31 | + protected $m_title; // title object to which print request refers (if any) |
| 32 | + protected $m_typeid = false; // id of the datatype of the printed objects, if applicable |
| 33 | + protected $m_outputformat; // output format string for formatting results, if applicable |
33 | 34 | |
34 | 35 | /** |
35 | 36 | * Create a print request. |
— | — | @@ -37,11 +38,11 @@ |
38 | 39 | * @param $title optional Title object that specifies the request (usually a relation or attribute) |
39 | 40 | * @param $datavalue optional SMWDataValue container that sets parameters for printing data values (e.g. the unit) |
40 | 41 | */ |
41 | | - public function SMWPrintRequest($mode, $label, Title $title = NULL, $datavalue = NULL) { |
| 42 | + public function SMWPrintRequest($mode, $label, Title $title = NULL, $outputformat = '') { |
42 | 43 | $this->m_mode = $mode; |
43 | 44 | $this->m_label = $label; |
44 | 45 | $this->m_title = $title; |
45 | | - $this->m_datavalue = $datavalue; |
| 46 | + $this->m_outputformat = $outputformat; |
46 | 47 | } |
47 | 48 | |
48 | 49 | public function getMode() { |
— | — | @@ -91,10 +92,18 @@ |
92 | 93 | return $this->m_title; |
93 | 94 | } |
94 | 95 | |
95 | | - public function getDatavalue() { |
96 | | - return $this->m_datavalue; |
| 96 | + public function getOutputFormat() { |
| 97 | + return $this->m_outputformat; |
97 | 98 | } |
98 | 99 | |
| 100 | + public function getTypeID() { |
| 101 | + if ($this->m_typeid === false) { |
| 102 | + $dv = SMWDataValueFactory::newAttributeValue($this->m_title->getText()); |
| 103 | + $this->m_typeid = $dv->getTypeID(); |
| 104 | + } |
| 105 | + return $this->m_typeid; |
| 106 | + } |
| 107 | + |
99 | 108 | /** |
100 | 109 | * Return a hash string that is used to eliminate duplicate |
101 | 110 | * print requests. |
— | — | @@ -104,11 +113,7 @@ |
105 | 114 | if ($this->m_title !== NULL) { |
106 | 115 | $hash .= $this->m_title->getPrefixedText() . ':'; |
107 | 116 | } |
108 | | - if ($this->m_datavalue !== NULL) { |
109 | | - foreach ($this->m_datavalue->getDesiredUnits() as $unit) { |
110 | | - $hash .= $unit . ':'; |
111 | | - } |
112 | | - } |
| 117 | + $hash .= $this->m_outputformat . ':'; |
113 | 118 | return $hash; |
114 | 119 | } |
115 | 120 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php |
— | — | @@ -168,7 +168,7 @@ |
169 | 169 | } |
170 | 170 | |
171 | 171 | |
172 | | - function getAttributeValues(Title $subject, Title $attribute, $requestoptions = NULL) { |
| 172 | + function getAttributeValues(Title $subject, Title $attribute, $requestoptions = NULL, $outputformat = '') { |
173 | 173 | $db =& wfGetDB( DB_MASTER ); // TODO: can we use SLAVE here? Is '=&' needed in PHP5? |
174 | 174 | $result = array(); |
175 | 175 | |
— | — | @@ -187,6 +187,7 @@ |
188 | 188 | while($row = $db->fetchObject($res)) { |
189 | 189 | $dv = SMWDataValueFactory::newTypehandlerValue(SMWTypeHandlerFactory::getTypeHandlerByID($row->value_datatype)); |
190 | 190 | $dv->setAttribute($attribute->getText()); |
| 191 | + $dv->setOutputFormat($outputformat); |
191 | 192 | $dv->setXSDValue($row->value_xsd, $row->value_unit); |
192 | 193 | $result[] = $dv; |
193 | 194 | } |
— | — | @@ -203,6 +204,7 @@ |
204 | 205 | while($row = $db->fetchObject($res)) { |
205 | 206 | $dv = SMWDataValueFactory::newTypehandlerValue(SMWTypeHandlerFactory::getTypeHandlerByID('text')); |
206 | 207 | $dv->setAttribute($attribute->getText()); |
| 208 | + $dv->setOutputFormat($outputformat); |
207 | 209 | $dv->setXSDValue($row->value_blob, ''); |
208 | 210 | $result[] = $dv; |
209 | 211 | } |
— | — | @@ -607,8 +609,7 @@ |
608 | 610 | $row[] = new SMWResultArray($this->getSpecialValues($qt,SMW_SP_HAS_CATEGORY), $pr); |
609 | 611 | break; |
610 | 612 | case SMW_PRINT_ATTS: |
611 | | - ///TODO: respect given datavalue (desired unit), needs extension of getAttributeValues() |
612 | | - $row[] = new SMWResultArray($this->getAttributeValues($qt,$pr->getTitle()), $pr); |
| 613 | + $row[] = new SMWResultArray($this->getAttributeValues($qt,$pr->getTitle(), NULL, $pr->getOutputFormat()), $pr); |
613 | 614 | break; |
614 | 615 | } |
615 | 616 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php |
— | — | @@ -130,9 +130,11 @@ |
131 | 131 | |
132 | 132 | /** |
133 | 133 | * Get an array of all attribute values stored for the given subject and atttribute. The result |
134 | | - * is an array of SMWDataValue objects. |
| 134 | + * is an array of SMWDataValue objects. The provided outputformat is a string identifier that |
| 135 | + * may be used by the datavalues to modify their output behaviour, e.g. when interpreted as a |
| 136 | + * desierd unit to convert the output to. |
135 | 137 | */ |
136 | | - abstract function getAttributeValues(Title $subject, Title $attribute, $requestoptions = NULL); |
| 138 | + abstract function getAttributeValues(Title $subject, Title $attribute, $requestoptions = NULL, $outputformat = ''); |
137 | 139 | |
138 | 140 | /** |
139 | 141 | * Get an array of all subjects that have the given value for the given attribute. The |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php |
— | — | @@ -33,6 +33,10 @@ |
34 | 34 | public function setAttribute($attribute) { // ignore |
35 | 35 | } |
36 | 36 | |
| 37 | + public function setOutputFormat($formatstring) { |
| 38 | + // no output formats supported, ignore |
| 39 | + } |
| 40 | + |
37 | 41 | /*********************************************************************/ |
38 | 42 | /* Get methods */ |
39 | 43 | /*********************************************************************/ |