r60725 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60724‎ | r60725 | r60726 >
Date:10:46, 6 January 2010
Author:mkroetzsch
Status:deferred
Tags:
Comment:
implement getDVs() method as in former SMWNAryValue
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php
@@ -118,48 +118,20 @@
119119 return $this->makeOutputText(4);
120120 }
121121
122 - private function makeOutputText($type = 0, $linker = NULL) {
123 - if (!$this->isValid()) {
124 - return ( ($type == 0)||($type == 1) )? '' : $this->getErrorText();
125 - }
126 - $result = '';
127 - for ($i = 0; $i < count($this->getTypeValues()); $i++) {
128 - if ($i == 1) {
129 - $result .= ($type == 4)?'; ':' (';
130 - } elseif ($i > 1) {
131 - $result .= ($type == 4)?'; ':", ";
132 - }
133 - $property = SMWPropertyValue::makeProperty('_' . ($i+1));
134 - $dv = reset($this->m_data->getPropertyValues($property));
135 - $result .= ($dv !== false)? $this->makeValueOutputText($type, $dv, $linker): '?';
136 - }
137 - if ( ($i>1) && ($type != 4) ) $result .= ')';
138 - return $result;
139 - }
140 -
141 - private function makeValueOutputText($type, $datavalue, $linker) {
142 - switch ($type) {
143 - case 0: return $datavalue->getShortWikiText($linker);
144 - case 1: return $datavalue->getShortHTMLText($linker);
145 - case 2: return $datavalue->getShortWikiText($linker);
146 - case 3: return $datavalue->getShortHTMLText($linker);
147 - case 4: return $datavalue->getWikiValue();
148 - }
149 - }
150 -
151122 /// @todo Allowed values for multi-valued properties are not supported yet.
152123 protected function checkAllowedValues() {}
153124
154125 /**
155126 * Make sure that the content is reset in this case.
156127 * @todo This is not a full reset yet (the case that property is changed after a value
157 - * was set does not occur in the normal flow of things, hence thishas low priority).
 128+ * was set does not occur in the normal flow of things, hence this has low priority).
158129 */
159130 public function setProperty(SMWPropertyValue $property) {
160131 parent::setProperty($property);
161132 $this->m_typevalues = NULL;
162133 }
163134
 135+ ///@todo Update (implementation below still from SMWNAryValue)
164136 public function getExportData() {
165137 if (!$this->isValid()) return NULL;
166138
@@ -185,9 +157,60 @@
186158 return $result;
187159 }
188160
189 -////// Custom functions for n-ary attributes
 161+////// Additional API for value lists
190162
191163 /**
 164+ * Create a list (array with numeric keys) containing the datavalue objects
 165+ * that this SMWListValue object holds. Values that are not present are set
 166+ * to NULL, but the array still contains keys for each index from 0 through
 167+ * 4. Note that the first index in the array is 0, not 1, and that the
 168+ * declared length of the list is not taken into account: the size of the
 169+ * result array is always 5.
 170+ */
 171+ public function getDVs() {
 172+ if (!$this->isValid()) return array(0=>NULL,1=>NULL,2=>NULL,3=>NULL,4=>NULL);
 173+ $result = array();
 174+ for ($i=1; $i<6; $i++) {
 175+ $property = SMWPropertyValue::makeProperty("_$i");
 176+ $dv = reset($this->m_data->getPropertyValues($property));
 177+ $result[$i-1] = ($dv instanceof SMWDataValue)?$dv:NULL;
 178+ }
 179+ }
 180+
 181+////// Internal helper functions
 182+
 183+ private function makeOutputText($type = 0, $linker = NULL) {
 184+ if (!$this->isValid()) {
 185+ return ( ($type == 0)||($type == 1) )? '' : $this->getErrorText();
 186+ }
 187+ $result = '';
 188+ for ($i = 0; $i < count($this->getTypeValues()); $i++) {
 189+ if ($i == 1) {
 190+ $result .= ($type == 4)?'; ':' (';
 191+ } elseif ($i > 1) {
 192+ $result .= ($type == 4)?'; ':", ";
 193+ }
 194+ $property = SMWPropertyValue::makeProperty('_' . ($i+1));
 195+ $dv = reset($this->m_data->getPropertyValues($property));
 196+ $result .= ($dv !== false)? $this->makeValueOutputText($type, $dv, $linker): '?';
 197+ }
 198+ if ( ($i>1) && ($type != 4) ) $result .= ')';
 199+ return $result;
 200+ }
 201+
 202+ private function makeValueOutputText($type, $datavalue, $linker) {
 203+ switch ($type) {
 204+ case 0: return $datavalue->getShortWikiText($linker);
 205+ case 1: return $datavalue->getShortHTMLText($linker);
 206+ case 2: return $datavalue->getShortWikiText($linker);
 207+ case 3: return $datavalue->getShortHTMLText($linker);
 208+ case 4: return $datavalue->getWikiValue();
 209+ }
 210+ }
 211+
 212+////// Custom functions for old n-aries; may become obsolete.
 213+
 214+ /**
192215 * Change to query syntax mode.
193216 */
194217 public function acceptQuerySyntax() {

Status & tagging log