Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php |
— | — | @@ -30,22 +30,6 @@ |
31 | 31 | private $m_printstatement = false; |
32 | 32 | private $m_outputmodifiers; |
33 | 33 | |
34 | | - /** |
35 | | - * Set type array. Must be done before setting any values. |
36 | | - */ |
37 | | - public function setType($type) { |
38 | | - $this->m_type = $type; |
39 | | - $this->m_count = count($this->m_type->getTypeLabels()); |
40 | | - $this->m_values = array(); // careful: do not iterate to m_count if DV is not valid! |
41 | | - } |
42 | | - |
43 | | - /** |
44 | | - * Change to query syntax mode. |
45 | | - */ |
46 | | - public function acceptQuerySyntax() { |
47 | | - $this->m_querysyntax = true; |
48 | | - } |
49 | | - |
50 | 34 | protected function parseUserValue($value) { |
51 | 35 | $this->m_values = array(); |
52 | 36 | $this->m_comparators = array(); // only for query mode |
— | — | @@ -61,7 +45,8 @@ |
62 | 46 | $vi = 0; // index in value array |
63 | 47 | $empty = true; |
64 | 48 | for ($i = 0; $i < $this->m_count; $i++) { // iterate over slots |
65 | | - if ($this->m_querysyntax) { // special extension for supporting query parsing |
| 49 | + // special handling for supporting query parsing |
| 50 | + if ($this->m_querysyntax) { |
66 | 51 | $comparator = SMW_CMP_EQ; |
67 | 52 | $printmodifier = ''; |
68 | 53 | $this->prepareValue($values[$vi], $comparator, $printmodifier); |
— | — | @@ -73,6 +58,7 @@ |
74 | 59 | $printmodifiers[$vi] = ''; |
75 | 60 | } |
76 | 61 | } |
| 62 | + // generating the DVs: |
77 | 63 | if ( (count($values) > $vi) && |
78 | 64 | ( ($values[$vi] == '') || ($values[$vi] == '?') ) ) { // explicit omission |
79 | 65 | $this->m_values[$i] = NULL; |
— | — | @@ -266,6 +252,22 @@ |
267 | 253 | return $this->m_type; |
268 | 254 | } |
269 | 255 | |
| 256 | + /** |
| 257 | + * Set type array. Must be done before setting any values. |
| 258 | + */ |
| 259 | + public function setType($type) { |
| 260 | + $this->m_type = $type; |
| 261 | + $this->m_count = count($this->m_type->getTypeLabels()); |
| 262 | + $this->m_values = array(); // careful: do not iterate to m_count if DV is not valid! |
| 263 | + } |
| 264 | + |
| 265 | + /** |
| 266 | + * Change to query syntax mode. |
| 267 | + */ |
| 268 | + public function acceptQuerySyntax() { |
| 269 | + $this->m_querysyntax = true; |
| 270 | + } |
| 271 | + |
270 | 272 | public function getDVs() { |
271 | 273 | return $this->isValid() ? $this->m_values : NULL; |
272 | 274 | } |
— | — | @@ -293,6 +295,36 @@ |
294 | 296 | $this->m_isset = true; |
295 | 297 | } |
296 | 298 | |
| 299 | + /** |
| 300 | + * If valid and in querymode, build a suitable SMWValueList description from the |
| 301 | + * given input or return NULL if no such description was given. This requires the |
| 302 | + * input to be given to setUserValue(). Otherwise bad things will happen. |
| 303 | + */ |
| 304 | + public function getValueList() { |
| 305 | + $vl = new SMWValueList(); |
| 306 | + if (!$this->isValid() || !$this->m_querysyntax) { |
| 307 | + return NULL; |
| 308 | + } |
| 309 | + for ($i=0; $i < $this->m_count; $i++) { |
| 310 | + if ($this->m_values[$i] !== NULL) { |
| 311 | + $vl->setDescription($i,new SMWValueDescription($this->m_values[$i], $this->m_comparators[$i])); |
| 312 | + } |
| 313 | + } |
| 314 | + return $vl; |
| 315 | + } |
| 316 | + |
| 317 | + /** |
| 318 | + * If in querymode, return all printmodifiers given or false if no print request |
| 319 | + * was specified. This requires the input to be given to setUserValue(). |
| 320 | + * Otherwise bad things will happen. |
| 321 | + */ |
| 322 | + public function getPrintModifier() { |
| 323 | + if (!$this->m_printstatement || !$this->m_querysyntax) { |
| 324 | + return false; |
| 325 | + } |
| 326 | + return implode(';', $this->m_outputmodifiers); |
| 327 | + } |
| 328 | + |
297 | 329 | private function prepareValue(&$value, &$comparator, &$printmodifier) { |
298 | 330 | // get print modifier behind * |
299 | 331 | $list = preg_split('/^\*/',$value,2); |
— | — | @@ -325,36 +357,6 @@ |
326 | 358 | } |
327 | 359 | } |
328 | 360 | } |
329 | | - |
330 | | - /** |
331 | | - * If valid and in querymode, build a suitable SMWValueList description from the |
332 | | - * given input or return NULL if no such description was given. This requires the |
333 | | - * input to be given to setUserValue(). Otherwise bad things will happen. |
334 | | - */ |
335 | | - public function getValueList() { |
336 | | - $vl = new SMWValueList(); |
337 | | - if (!$this->isValid() || !$this->m_querysyntax) { |
338 | | - return NULL; |
339 | | - } |
340 | | - for ($i=0; $i < $this->m_count; $i++) { |
341 | | - if ($this->m_values[$i] !== NULL) { |
342 | | - $vl->setDescription($i,new SMWValueDescription($this->m_values[$i], $this->m_comparators[$i])); |
343 | | - } |
344 | | - } |
345 | | - return $vl; |
346 | | - } |
347 | 361 | |
348 | | - /** |
349 | | - * If in querymode, return all printmodifiers given or false if no print request |
350 | | - * was specified. This requires the input to be given to setUserValue(). |
351 | | - * Otherwise bad things will happen. |
352 | | - */ |
353 | | - public function getPrintModifier() { |
354 | | - if (!$this->m_printstatement || !$this->m_querysyntax) { |
355 | | - return false; |
356 | | - } |
357 | | - return implode(';', $this->m_outputmodifiers); |
358 | | - } |
359 | | - |
360 | 362 | } |
361 | 363 | |