MediaWiki  REL1_23
SiteList.php
Go to the documentation of this file.
00001 <?php
00002 
00029 class SiteList extends GenericArrayObject {
00030 
00038     protected $byInternalId = array();
00039 
00047     protected $byGlobalId = array();
00048 
00057     protected $byNavigationId = array();
00058 
00066     public function getObjectType() {
00067         return 'Site';
00068     }
00069 
00080     protected function preSetElement( $index, $site ) {
00081         if ( $this->hasSite( $site->getGlobalId() ) ) {
00082             $this->removeSite( $site->getGlobalId() );
00083         }
00084 
00085         $this->byGlobalId[$site->getGlobalId()] = $index;
00086         $this->byInternalId[$site->getInternalId()] = $index;
00087 
00088         $ids = $site->getNavigationIds();
00089         foreach ( $ids as $navId ) {
00090             $this->byNavigationId[$navId] = $index;
00091         }
00092 
00093         return true;
00094     }
00095 
00103     public function offsetUnset( $index ) {
00104         if ( $this->offsetExists( $index ) ) {
00108             $site = $this->offsetGet( $index );
00109 
00110             unset( $this->byGlobalId[$site->getGlobalId()] );
00111             unset( $this->byInternalId[$site->getInternalId()] );
00112 
00113             $ids = $site->getNavigationIds();
00114             foreach ( $ids as $navId ) {
00115                 unset( $this->byNavigationId[$navId] );
00116             }
00117         }
00118 
00119         parent::offsetUnset( $index );
00120     }
00121 
00130     public function getGlobalIdentifiers() {
00131         return array_keys( $this->byGlobalId );
00132     }
00133 
00141     public function hasSite( $globalSiteId ) {
00142         return array_key_exists( $globalSiteId, $this->byGlobalId );
00143     }
00144 
00155     public function getSite( $globalSiteId ) {
00156         return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
00157     }
00158 
00167     public function removeSite( $globalSiteId ) {
00168         $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
00169     }
00170 
00178     public function isEmpty() {
00179         return $this->byGlobalId === array();
00180     }
00181 
00189     public function hasInternalId( $id ) {
00190         return array_key_exists( $id, $this->byInternalId );
00191     }
00192 
00203     public function getSiteByInternalId( $id ) {
00204         return $this->offsetGet( $this->byInternalId[$id] );
00205     }
00206 
00215     public function removeSiteByInternalId( $id ) {
00216         $this->offsetUnset( $this->byInternalId[$id] );
00217     }
00218 
00226     public function hasNavigationId( $id ) {
00227         return array_key_exists( $id, $this->byNavigationId );
00228     }
00229 
00240     public function getSiteByNavigationId( $id ) {
00241         return $this->offsetGet( $this->byNavigationId[$id] );
00242     }
00243 
00252     public function removeSiteByNavigationId( $id ) {
00253         $this->offsetUnset( $this->byNavigationId[$id] );
00254     }
00255 
00264     public function setSite( Site $site ) {
00265         $this[] = $site;
00266     }
00267 
00277     public function getGroup( $groupName ) {
00278         $group = new self();
00279 
00283         foreach ( $this as $site ) {
00284             if ( $site->getGroup() === $groupName ) {
00285                 $group[] = $site;
00286             }
00287         }
00288 
00289         return $group;
00290     }
00291 
00300     const SERIAL_VERSION_ID = '2014-03-17';
00301 
00311     public static function getSerialVersionId() {
00312         return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
00313     }
00314 
00322     protected function getSerializationData() {
00323         //NOTE: When changing the structure, either implement unserialize() to handle the
00324         //      old structure too, or update SERIAL_VERSION_ID to kill any caches.
00325         return array_merge(
00326             parent::getSerializationData(),
00327             array(
00328                 'internalIds' => $this->byInternalId,
00329                 'globalIds' => $this->byGlobalId,
00330                 'navigationIds' => $this->byNavigationId
00331             )
00332         );
00333     }
00334 
00344     public function unserialize( $serialization ) {
00345         $serializationData = parent::unserialize( $serialization );
00346 
00347         $this->byInternalId = $serializationData['internalIds'];
00348         $this->byGlobalId = $serializationData['globalIds'];
00349         $this->byNavigationId = $serializationData['navigationIds'];
00350 
00351         return $serializationData;
00352     }
00353 
00354 }
00355 
00359 class SiteArray extends SiteList {}