00001 <?php
00022 class SMWSqlStubSemanticData extends SMWSemanticData {
00023
00032 protected $mStubPropVals = array();
00033
00041 protected $mSubject;
00042
00053 public static function newFromSemanticData( SMWSemanticData $semanticData ) {
00054 $result = new SMWSqlStubSemanticData( $semanticData->getSubject() );
00055 $result->mPropVals = $semanticData->mPropVals;
00056 $result->mProperties = $semanticData->mProperties;
00057 $result->mHasVisibleProps = $semanticData->mHasVisibleProps;
00058 $result->mHasVisibleSpecs = $semanticData->mHasVisibleSpecs;
00059 $result->stubObject = $semanticData->stubObject;
00060 return $result;
00061 }
00062
00068 public function getProperties() {
00069 $this->unstubProperties();
00070 return parent::getProperties();
00071 }
00072
00079 public function getPropertyValues( SMWDIProperty $property ) {
00080 if ( $property->isInverse() ) {
00081 return array();
00082 }
00083
00084 if ( array_key_exists( $property->getKey(), $this->mStubPropVals ) ) {
00085 $this->unstubProperty( $property->getKey(), $property );
00086 $propertyTypeId = $property->findPropertyTypeID();
00087 $propertyDiId = SMWDataValueFactory::getDataItemId( $propertyTypeId );
00088
00089 foreach ( $this->mStubPropVals[$property->getKey()] as $dbkeys ) {
00090 try {
00091 if ( $propertyDiId == SMWDataItem::TYPE_CONTAINER ) {
00092 $diSubWikiPage = SMWCompatibilityHelpers::dataItemFromDBKeys( '_wpg', $dbkeys );
00093 $semanticData = new SMWContainerSemanticData( $diSubWikiPage );
00094 $semanticData->copyDataFrom( smwfGetStore()->getSemanticData( $diSubWikiPage ) );
00095
00096 $di = new SMWDIContainer( $semanticData );
00097 } else {
00098 $di = SMWCompatibilityHelpers::dataItemFromDBKeys( $propertyTypeId, $dbkeys );
00099 }
00100
00101 if ( $this->mNoDuplicates ) {
00102 $this->mPropVals[$property->getKey()][$di->getHash()] = $di;
00103 } else {
00104 $this->mPropVals[$property->getKey()][] = $di;
00105 }
00106 } catch ( SMWDataItemException $e ) {
00107
00108 }
00109 }
00110
00111 unset( $this->mStubPropVals[$property->getKey()] );
00112 }
00113
00114 return parent::getPropertyValues( $property );
00115 }
00116
00122 public function hasVisibleProperties() {
00123 $this->unstubProperties();
00124 return parent::hasVisibleProperties();
00125 }
00126
00133 public function hasVisibleSpecialProperties() {
00134 $this->unstubProperties();
00135 return parent::hasVisibleSpecialProperties();
00136 }
00137
00146 public function addPropertyStubValue( $propertyKey, array $valueKeys ) {
00147 $this->mStubPropVals[$propertyKey][] = $valueKeys;
00148 }
00149
00153 public function clear() {
00154 $this->mStubPropVals = array();
00155 parent::clear();
00156 }
00157
00162 protected function unstubProperties() {
00163 foreach ( $this->mStubPropVals as $pkey => $values ) {
00164 $this->unstubProperty( $pkey );
00165 }
00166 }
00167
00177 protected function unstubProperty( $propertyKey, $diProperty = null ) {
00178 if ( !array_key_exists( $propertyKey, $this->mProperties ) ) {
00179 if ( is_null( $diProperty ) ) {
00180
00181
00182 $diProperty = new SMWDIProperty( $propertyKey, false );
00183 }
00184
00185 $this->mProperties[$propertyKey] = $diProperty;
00186
00187 if ( !$diProperty->isUserDefined() ) {
00188 if ( $diProperty->isShown() ) {
00189 $this->mHasVisibleSpecs = true;
00190 $this->mHasVisibleProps = true;
00191 }
00192 } else {
00193 $this->mHasVisibleProps = true;
00194 }
00195 }
00196 }
00197
00198 }