m_semanticData = $semanticData; } public function getDIType() { return SMWDataItem::TYPE_CONTAINER; } public function getSemanticData() { return $this->m_semanticData; } public function getSortKey() { return ''; } /** * @since 2.5 * * @param string $sortKey */ public function setSortKey( $sortKey ) { $this->m_semanticData->addPropertyObjectValue( new DIProperty( '_SKEY' ), new DIBlob( $this->m_semanticData->getSubject()->getSortKey() . '#' . $sortKey ) ); } public function getSerialization() { return serialize( $this->m_semanticData ); } /** * Get a hash string for this data item. * * @return string */ public function getHash() { $hash = $this->getValueHash( $this->m_semanticData ); sort( $hash ); return md5( implode( '#', $hash ) ); // We want a value hash, not an entity hash!! // return $this->m_semanticData->getHash(); } private function getValueHash( $semanticData ) { $hash = []; foreach ( $semanticData->getProperties() as $property ) { $hash[] = $property->getKey(); foreach ( $semanticData->getPropertyValues( $property ) as $di ) { $hash[] = $di->getHash(); } } foreach ( $semanticData->getSubSemanticData() as $data ) { $hash[] = $this->getValueHash( $data ); } return $hash; } /** * Create a data item from the provided serialization string and type * ID. * * @return SMWDIContainer */ public static function doUnserialize( $serialization ) { /// TODO May issue an E_NOTICE when problems occur; catch this $data = unserialize( $serialization ); if ( !( $data instanceof SMWContainerSemanticData ) ) { throw new DataItemException( "Could not unserialize SMWDIContainer from the given string." ); } return new SMWDIContainer( $data ); } public function equals( SMWDataItem $di ) { if ( $di->getDIType() !== SMWDataItem::TYPE_CONTAINER ) { return false; } return $di->getSerialization() === $this->getSerialization(); } }