r24220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24219‎ | r24220 | r24221 >
Date:22:50, 17 July 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Minor cleanup
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php
@@ -30,22 +30,6 @@
3131 private $m_printstatement = false;
3232 private $m_outputmodifiers;
3333
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 -
5034 protected function parseUserValue($value) {
5135 $this->m_values = array();
5236 $this->m_comparators = array(); // only for query mode
@@ -61,7 +45,8 @@
6246 $vi = 0; // index in value array
6347 $empty = true;
6448 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) {
6651 $comparator = SMW_CMP_EQ;
6752 $printmodifier = '';
6853 $this->prepareValue($values[$vi], $comparator, $printmodifier);
@@ -73,6 +58,7 @@
7459 $printmodifiers[$vi] = '';
7560 }
7661 }
 62+ // generating the DVs:
7763 if ( (count($values) > $vi) &&
7864 ( ($values[$vi] == '') || ($values[$vi] == '?') ) ) { // explicit omission
7965 $this->m_values[$i] = NULL;
@@ -266,6 +252,22 @@
267253 return $this->m_type;
268254 }
269255
 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+
270272 public function getDVs() {
271273 return $this->isValid() ? $this->m_values : NULL;
272274 }
@@ -293,6 +295,36 @@
294296 $this->m_isset = true;
295297 }
296298
 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+
297329 private function prepareValue(&$value, &$comparator, &$printmodifier) {
298330 // get print modifier behind *
299331 $list = preg_split('/^\*/',$value,2);
@@ -325,36 +357,6 @@
326358 }
327359 }
328360 }
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 - }
347361
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 -
360362 }
361363

Status & tagging log