function setTypeAndPossibleValues() { $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty); if ($proptitle === null) { return; } $store = smwfGetStore(); // this returns an array of objects $allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value"); $label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format"); $propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty); $this->mPropertyType = $propValue->findPropertyTypeID(); foreach ($allowed_values as $allowed_value) { // HTML-unencode each value $this->mPossibleValues[] = html_entity_decode($allowed_value); if (count($label_formats) > 0) { $label_format = $label_formats[0]; $prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType); $label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value); $label_value->setOutputFormat($label_format); $this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue()); } } // HACK - if there were any possible values, set the property // type to be 'enumeration', regardless of what the actual type is if (count($this->mPossibleValues) > 0) { $this->mPropertyType = 'enumeration'; } }
function setTypeAndPossibleValues() { // The presence of "-" at the beginning of a property name // (which happens if SF tries to parse an inverse query) // leads to an error in SMW - just exit if that's the case. if (strpos($this->mSemanticProperty, '-') === 0) { return; } $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty); if ($proptitle === null) { return; } $store = SFUtils::getSMWStore(); // this returns an array of objects $allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value"); $label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format"); $propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty); $this->mPropertyType = $propValue->findPropertyTypeID(); foreach ($allowed_values as $allowed_value) { // HTML-unencode each value $this->mPossibleValues[] = html_entity_decode($allowed_value); if (count($label_formats) > 0) { $label_format = $label_formats[0]; $prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType); $label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value); $label_value->setOutputFormat($label_format); $this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue()); } } // HACK - if there were any possible values, set the property // type to be 'enumeration', regardless of what the actual type is if (count($this->mPossibleValues) > 0) { $this->mPropertyType = 'enumeration'; } }
/** * Gets the forms specified, if any, of either type "default form", * "alternate form", or "default form for page", for a specific page * (which should be a category, property, or namespace page) */ static function getFormsThatPagePointsTo($page_name, $page_namespace, $form_connection_type) { if ($page_name == NULL) { return array(); } // Check if we've already gotten the set of forms for this // combination of page and "form connection type" (default, // alternate or "creates pages with"). If so, use that - // otherwise, prepare the array so that we can add this // data to it. $page_key = "{$page_namespace}:{$page_name}"; if (array_key_exists($page_key, self::$mLinkedForms)) { if (array_key_exists($form_connection_type, self::$mLinkedForms[$page_key])) { return self::$mLinkedForms[$page_key][$form_connection_type]; } else { // Do nothing - an entry with this key will // be added at the end of this method. } } else { self::$mLinkedForms[$page_key] = array(); } if ($form_connection_type == self::DEFAULT_FORM) { $prop_smw_id = '_SF_DF'; $backup_prop_smw_id = '_SF_DF_BACKUP'; } elseif ($form_connection_type == self::ALTERNATE_FORM) { $prop_smw_id = '_SF_AF'; $backup_prop_smw_id = '_SF_AF_BACKUP'; } elseif ($form_connection_type == self::PAGE_DEFAULT_FORM) { $prop_smw_id = '_SF_PDF'; $backup_prop_smw_id = '_SF_PDF_BACKUP'; } elseif ($form_connection_type == self::AUTO_CREATE_FORM) { $prop_smw_id = '_SF_CP'; $backup_prop_smw_id = '_SF_CP_BACKUP'; } else { return array(); } global $sfgContLang; $store = SFUtils::getSMWStore(); $subject = Title::makeTitleSafe($page_namespace, $page_name); $form_names = SFUtils::getSMWPropertyValues($store, $subject, $prop_smw_id); // If we're using a non-English language, check for the English // string as well. if (!class_exists('SF_LanguageEn') || !$sfgContLang instanceof SF_LanguageEn) { $backup_form_names = SFUtils::getSMWPropertyValues($store, $subject, $backup_prop_smw_id); $form_names = array_merge($form_names, $backup_form_names); } // These form names will all start with "Form:" - remove the // namespace prefix. foreach ($form_names as $i => $form_name) { $form_names[$i] = preg_replace('/^Form:/', '', $form_name); } // Add this data to the "cache". self::$mLinkedForms[$page_key][$form_connection_type] = $form_names; return $form_names; }