00001 <?php 00026 class SMWContainerSemanticData extends SMWSemanticData { 00027 00036 public static function makeAnonymousContainer( $noDuplicates = true ) { 00037 $subject = new SMWDIWikiPage( 'SMWInternalObject', NS_SPECIAL, '' ); 00038 return new SMWContainerSemanticData( $subject, $noDuplicates ); 00039 } 00040 00044 public function __sleep() { 00045 return array( 'mSubject', 'mProperties', 'mPropVals', 00046 'mHasVisibleProps', 'mHasVisibleSpecs', 'mNoDuplicates' ); 00047 } 00048 00055 public function hasAnonymousSubject() { 00056 if ( $this->mSubject->getNamespace() == NS_SPECIAL && 00057 $this->mSubject->getDBkey() == 'SMWInternalObject' && 00058 $this->mSubject->getInterwiki() === '' ) { 00059 return true; 00060 } else { 00061 return false; 00062 } 00063 } 00064 00072 public function getSubject() { 00073 if ( $this->hasAnonymousSubject() ) { 00074 throw new SMWDataItemException("Trying to get the subject of a container data item that has not been given any. This container can only be used as a search pattern."); 00075 } else { 00076 return $this->mSubject; 00077 } 00078 } 00079 00090 public function copyDataFrom( SMWSemanticData $semanticData ) { 00091 $this->mSubject = $semanticData->getSubject(); 00092 $this->mProperties = $semanticData->getProperties(); 00093 $this->mPropVals = array(); 00094 foreach ( $this->mProperties as $property ) { 00095 $this->mPropVals[$property->getKey()] = $semanticData->getPropertyValues( $property ); 00096 } 00097 $this->mHasVisibleProps = $semanticData->hasVisibleProperties(); 00098 $this->mHasVisibleSpecs = $semanticData->hasVisibleSpecialProperties(); 00099 $this->mNoDuplicates = $semanticData->mNoDuplicates; 00100 } 00101 00102 } 00103 00130 class SMWDIContainer extends SMWDataItem { 00131 00137 protected $m_semanticData; 00138 00146 public function __construct( SMWContainerSemanticData $semanticData ) { 00147 $this->m_semanticData = $semanticData; 00148 } 00149 00150 public function getDIType() { 00151 return SMWDataItem::TYPE_CONTAINER; 00152 } 00153 00154 public function getSemanticData() { 00155 return $this->m_semanticData; 00156 } 00157 00158 public function getSortKey() { 00159 return ''; 00160 } 00161 00162 public function getSerialization() { 00163 return serialize( $this->m_semanticData ); 00164 } 00165 00171 public function getHash() { 00172 return $this->m_semanticData->getHash(); 00173 } 00174 00181 public static function doUnserialize( $serialization ) { 00183 $data = unserialize( $serialization ); 00184 if ( !( $data instanceof SMWContainerSemanticData ) ) { 00185 throw new SMWDataItemException( "Could not unserialize SMWDIContainer from the given string." ); 00186 } 00187 return new SMWDIContainer( $data ); 00188 } 00189 00190 }
1.5.6