function loadPropertyTypeFromProperty() { // Default the property type to "Page" (matching SMW's // default), in case there is no type set for this property. $this->property_type = 'page'; $store = SDUtils::getSMWStore(); $propPage = new SMWDIWikiPage($this->escaped_property, SMW_NS_PROPERTY, ''); $types = $store->getPropertyValues($propPage, new SMWDIProperty('_TYPE')); global $smwgContLang; $datatypeLabels = $smwgContLang->getDatatypeLabels(); if (count($types) > 0) { if ($types[0] instanceof SMWDIWikiPage) { $typeValue = $types[0]->getDBkey(); } elseif ($types[0] instanceof SMWDIURI) { // A bit inefficient, but it's the // simplest approach. $typeID = $types[0]->getFragment(); if ($typeID == '_str' && !array_key_exists('_str', $datatypeLabels)) { $typeID = '_txt'; } $typeValue = $datatypeLabels[$typeID]; } else { $typeValue = $types[0]->getWikiValue(); } if ($typeValue == $datatypeLabels['_wpg']) { $this->property_type = 'page'; // _str stopped existing in SMW 1.9 } elseif (array_key_exists('_str', $datatypeLabels) && $typeValue == $datatypeLabels['_str']) { $this->property_type = 'string'; } elseif (!array_key_exists('_str', $datatypeLabels) && $typeValue == $datatypeLabels['_txt']) { $this->property_type = 'string'; } elseif ($typeValue == $datatypeLabels['_num']) { $this->property_type = 'number'; } elseif ($typeValue == $datatypeLabels['_boo']) { $this->property_type = 'boolean'; } elseif ($typeValue == $datatypeLabels['_dat']) { $this->property_type = 'date'; } else { // This should hopefully never get called. print "Error! Unsupported property type ({$typeValue}) for filter {$this->name}."; } } // This requires the property type to be set. $this->loadDBStructureInformation(); }
/** * Generic static function - gets all the values that a specific page * points to with a specific property * * @deprecated as of SD 2.0 - will be removed when the "Filter:" * namespace goes away. */ static function getValuesForProperty($subject, $subjectNamespace, $specialPropID) { $store = SDUtils::getSMWStore(); $res = self::getSMWPropertyValues($store, $subject, $subjectNamespace, $specialPropID); $values = array(); foreach ($res as $prop_val) { // depends on version of SMW if ($prop_val instanceof SMWDIWikiPage) { $actual_val = $prop_val->getDBkey(); } elseif ($prop_val instanceof SMWDIString) { $actual_val = $prop_val->getString(); } elseif ($prop_val instanceof SMWDIBlob) { $actual_val = $prop_val->getString(); } elseif (method_exists($prop_val, 'getValueKey')) { $actual_val = $prop_val->getValueKey(); } else { $actual_val = $prop_val->getXSDValue(); } $values[] = html_entity_decode(str_replace('_', ' ', $actual_val)); } return $values; }
function addSemanticResultWrapper($dbr, $res, $num, $query, $mainlabel, $printouts) { $qr = array(); $count = 0; $store = SDUtils::getSMWStore(); while ($count < $num && ($row = $dbr->fetchObject($res))) { $count++; $qr[] = new SMWDIWikiPage($row->t, $row->ns, ''); if (method_exists($store, 'cacheSMWPageID')) { $store->cacheSMWPageID($row->id, $row->t, $row->ns, $row->iw, ''); } } if ($dbr->fetchObject($res)) { $count++; } $dbr->freeResult($res); $printrequest = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, $mainlabel); $main_printout = array(); $main_printout[$printrequest->getHash()] = $printrequest; $printouts = array_merge($main_printout, $printouts); return new SMWQueryResult($printouts, $query, $qr, $store, $count > $num); }