/** * @since 2.5 * * {@inheritDoc} */ public function addResourceValue(ExpData $expData, DIProperty $property, DataItem $dataItem) { $expElement = $this->exporter->getDataItemExpElement($dataItem); if ($expElement === null) { return; } if ($property->getKey() === $property->findPropertyTypeID()) { // Ensures that Boolean remains Boolean and not localized canonical // representation such as "Booléen" when the content languageis not // English $expNsResource = $this->getResourceElementForProperty(new DIProperty($property->getCanonicalDiWikiPage()->getDBKey())); } else { $expNsResource = $this->getResourceElementHelperForProperty($property); } $expData->addPropertyObjectValue($expNsResource, $expElement); $this->addResourceHelperValue($expData, $property, $dataItem); }
/** * Produce a formatted string representation for showing a property in * the list of unused properties. * * @since 1.8 * * @param DIProperty $property * * @return string */ protected function formatPropertyItem(DIProperty $property) { // Clear formatter before invoking messages and // avoid having previous data to be present $this->getMessageFormatter()->clear(); if ($property->isUserDefined()) { $title = $property->getDiWikiPage()->getTitle(); if (!$title instanceof \Title) { return ''; } $propertyLink = $this->getLinker()->link($title, $property->getLabel()); $types = $this->store->getPropertyValues($property->getDiWikiPage(), new DIProperty('_TYPE')); if (count($types) >= 1) { $typeDataValue = DataValueFactory::getInstance()->newDataItemValue(current($types), new DIProperty('_TYPE')); } else { $typeDataValue = SMWTypesValue::newFromTypeId('_wpg'); $this->getMessageFormatter()->addFromKey('smw_propertylackstype', $typeDataValue->getLongHTMLText()); } } else { $typeDataValue = SMWTypesValue::newFromTypeId($property->findPropertyTypeID()); $propertyLink = DataValueFactory::getInstance()->newDataItemValue($property, null)->getShortHtmlText($this->getLinker()); } return $this->msg('smw_unusedproperty_template', $propertyLink, $typeDataValue->getLongHTMLText($this->getLinker()))->text() . ' ' . $this->getMessageFormatter()->getHtml(); }
/** * Create a value for the given property, provided as an SMWDIProperty * object. If no value is given, an empty container is created, the * value of which can be set later on. * * @param $property SMWDIProperty property object for which this value is made * @param $valueString mixed user value string, or false if unknown * @param $caption mixed user-defined caption, or false if none given * @param $contextPage SMWDIWikiPage that provides a context for parsing the value string, or null * * @return DataValue */ public static function newPropertyObjectValue(DIProperty $property, $valueString = false, $caption = false, $contextPage = null) { $typeId = $property->isInverse() ? '_wpg' : $property->findPropertyTypeID(); return self::newTypeIdValue($typeId, $valueString, $caption, $property, $contextPage); }
/** * Check whether the values of a given type of dataitem have helper * values in the sense of SMWExporter::getInstance()->getDataItemHelperExpElement(). * * @param DIProperty $property * * @return boolean */ public static function hasHelperExpElement(DIProperty $property) { return $property->findPropertyTypeID() === '_dat' || $property->findPropertyTypeID() === '_geo' || !$property->isUserDefined() && !self::hasSpecialPropertyResource($property); }
public function testSetPropertyTypeIdOnPredefinedProperty() { $property = new DIProperty('_MDAT'); $property->setPropertyTypeId('_dat'); $this->assertEquals('_dat', $property->findPropertyTypeID()); }
/** * Retrieve the id of the property table that is to be used for storing * values for the given property object. * * @since 2.2 * * @param DIProperty $property * * @return string */ public function findTableIdForProperty(DIProperty $property) { if ($this->fixedPropertyTableIds === null) { $this->buildDefinitionsForPropertyTables(); } $propertyKey = $property->getKey(); if (array_key_exists($propertyKey, $this->fixedPropertyTableIds)) { return $this->fixedPropertyTableIds[$propertyKey]; } return $this->findTableIdForDataTypeTypeId($property->findPropertyTypeID()); }
/** * @since 2.5 * * {@inheritDoc} */ public function isResourceBuilderFor(DIProperty $property) { return $property->findPropertyTypeID() === '_mlt_rec'; }
/** * @since 2.5 * * @param DIProperty $property * * @return boolean */ public function isExemptedProperty(DIProperty $property) { $dataItemTypeId = DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID()); // Is neither therefore is exempted if ($dataItemTypeId !== DataItem::TYPE_BLOB && $dataItemTypeId !== DataItem::TYPE_URI) { return true; } return isset($this->propertyExemptionList[$property->getKey()]); }
/** * Returns DataItemId for a property * * @note findPropertyTypeID is calling the Store to find the * typeId reference this is costly but at the moment there is no other * way to determine the typeId * * This check is to ensure that during unserialization the correct item * in terms of its definition is being sought otherwise inconsistencies * can occur due to type changes of a property between the time of * the serialization and the deserialization (e.g for when the * serialization object is stored in cache, DB etc.) * * @return integer */ protected function getDataItemId(DIProperty $property) { if (!isset($this->dataItemTypeIdCache[$property->getKey()])) { $this->dataItemTypeIdCache[$property->getKey()] = DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID()); } return $this->dataItemTypeIdCache[$property->getKey()]; }
/** * Returns information related to predefined properties * * @since 1.9 * * @param DIProperty $property * * @return array */ private function getPredefinedPropertyInfo(DIProperty $property) { return array(SMWTypesValue::newFromTypeId($property->findPropertyTypeID())->getLongHTMLText($this->getLinker()), DataValueFactory::getInstance()->newDataItemValue($property, null)->getShortHtmlText($this->getLinker())); }
/** * @since 2.1 * * @return SemanticData */ public function getDependencies() { $semanticData = new SemanticData($this->property->getDiWikiPage()); $semanticData->addDataValue(DataValueFactory::getInstance()->newPropertyObjectValue(new DIProperty('_TYPE'), $this->property->findPropertyTypeID())); return $semanticData; }
/** * Create an ExpElement for some internal resource, given by an * DIProperty object. * * This code is only applied to user-defined properties, since the * code for special properties in * Exporter::getSpecialPropertyResource may require information * about the namespace in which some special property is used. * * @note $useAuxiliaryModifier is to determine whether an auxiliary * property resource is to store a helper value * (see Exporter::getDataItemHelperExpElement) should be generated * * @param DIProperty $property * @param boolean $useAuxiliaryModifier * * @return ExpResource * @throws RuntimeException */ public function mapPropertyToResourceElement(DIProperty $property, $useAuxiliaryModifier = false) { $diWikiPage = $property->getDiWikiPage(); if ($diWikiPage === null) { throw new RuntimeException('Only non-inverse, user-defined properties are permitted.'); } // No need for any aux properties besides those listed here if (!$this->bcAuxiliaryUse && $property->findPropertyTypeID() !== '_dat' && $property->findPropertyTypeID() !== '_geo') { $useAuxiliaryModifier = false; } return $this->mapWikiPageToResourceElement($diWikiPage, $useAuxiliaryModifier); }
/** * Retrieve the id of the property table that is to be used for storing * values for the given property object. * * @since 1.8 * @param DIProperty $diProperty * @return string */ public function findPropertyTableID(DIProperty $diProperty) { $propertyKey = $diProperty->getKey(); // This is needed to initialize the $fixedPropertyTableIds field $this->getPropertyTables(); if (array_key_exists($propertyKey, self::$fixedPropertyTableIds)) { return self::$fixedPropertyTableIds[$propertyKey]; } else { return $this->findTypeTableId($diProperty->findPropertyTypeID()); } }
/** * Create a value for the given property, provided as an SMWDIProperty * object. If no value is given, an empty container is created, the * value of which can be set later on. * * @param $property SMWDIProperty property object for which this value is made * @param $valueString mixed user value string, or false if unknown * @param $caption mixed user-defined caption, or false if none given * @param $contextPage SMWDIWikiPage that provides a context for parsing the value string, or null * * @return DataValue */ public function newDataValueByProperty(DIProperty $property, $valueString = false, $caption = false, $contextPage = null) { $typeId = $property->isInverse() ? '_wpg' : $property->findPropertyTypeID(); return $this->newDataValueByType($typeId, $valueString, $caption, $property, $contextPage); }
/** * Create an ExpElement for some internal resource, given by an * DIProperty object. * * This code is only applied to user-defined properties, since the * code for special properties in * Exporter::getSpecialPropertyResource may require information * about the namespace in which some special property is used. * * @note $useAuxiliaryModifier is to determine whether an auxiliary * property resource is to store a helper value * (see Exporter::getDataItemHelperExpElement) should be generated * * @param DIProperty $property * @param boolean $useAuxiliaryModifier * @param boolean $seekImportVocabulary * * @return ExpResource * @throws RuntimeException */ public function mapPropertyToResourceElement(DIProperty $property, $useAuxiliaryModifier = false, $seekImportVocabulary = true) { // We want the a canonical representation to ensure that resources // are language independent $this->seekImportVocabulary = $seekImportVocabulary; $diWikiPage = $property->getCanonicalDiWikiPage(); if ($diWikiPage === null) { throw new RuntimeException('Only non-inverse, user-defined properties are permitted.'); } // No need for any aux properties besides those listed here if (!$this->bcAuxiliaryUse && $property->findPropertyTypeID() !== '_dat' && $property->findPropertyTypeID() !== '_geo') { $useAuxiliaryModifier = false; } $expResource = $this->mapWikiPageToResourceElement($diWikiPage, $useAuxiliaryModifier); $this->seekImportVocabulary = true; return $expResource; }