MediaWiki  REL1_24
SiteList.php
Go to the documentation of this file.
00001 <?php
00002 
00029 class SiteList extends GenericArrayObject {
00037     protected $byInternalId = array();
00038 
00046     protected $byGlobalId = array();
00047 
00056     protected $byNavigationId = array();
00057 
00065     public function getObjectType() {
00066         return 'Site';
00067     }
00068 
00079     protected function preSetElement( $index, $site ) {
00080         if ( $this->hasSite( $site->getGlobalId() ) ) {
00081             $this->removeSite( $site->getGlobalId() );
00082         }
00083 
00084         $this->byGlobalId[$site->getGlobalId()] = $index;
00085         $this->byInternalId[$site->getInternalId()] = $index;
00086 
00087         $ids = $site->getNavigationIds();
00088         foreach ( $ids as $navId ) {
00089             $this->byNavigationId[$navId] = $index;
00090         }
00091 
00092         return true;
00093     }
00094 
00102     public function offsetUnset( $index ) {
00103         if ( $this->offsetExists( $index ) ) {
00107             $site = $this->offsetGet( $index );
00108 
00109             unset( $this->byGlobalId[$site->getGlobalId()] );
00110             unset( $this->byInternalId[$site->getInternalId()] );
00111 
00112             $ids = $site->getNavigationIds();
00113             foreach ( $ids as $navId ) {
00114                 unset( $this->byNavigationId[$navId] );
00115             }
00116         }
00117 
00118         parent::offsetUnset( $index );
00119     }
00120 
00129     public function getGlobalIdentifiers() {
00130         return array_keys( $this->byGlobalId );
00131     }
00132 
00140     public function hasSite( $globalSiteId ) {
00141         return array_key_exists( $globalSiteId, $this->byGlobalId );
00142     }
00143 
00154     public function getSite( $globalSiteId ) {
00155         return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
00156     }
00157 
00166     public function removeSite( $globalSiteId ) {
00167         $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
00168     }
00169 
00177     public function isEmpty() {
00178         return $this->byGlobalId === array();
00179     }
00180 
00188     public function hasInternalId( $id ) {
00189         return array_key_exists( $id, $this->byInternalId );
00190     }
00191 
00202     public function getSiteByInternalId( $id ) {
00203         return $this->offsetGet( $this->byInternalId[$id] );
00204     }
00205 
00214     public function removeSiteByInternalId( $id ) {
00215         $this->offsetUnset( $this->byInternalId[$id] );
00216     }
00217 
00225     public function hasNavigationId( $id ) {
00226         return array_key_exists( $id, $this->byNavigationId );
00227     }
00228 
00239     public function getSiteByNavigationId( $id ) {
00240         return $this->offsetGet( $this->byNavigationId[$id] );
00241     }
00242 
00251     public function removeSiteByNavigationId( $id ) {
00252         $this->offsetUnset( $this->byNavigationId[$id] );
00253     }
00254 
00263     public function setSite( Site $site ) {
00264         $this[] = $site;
00265     }
00266 
00276     public function getGroup( $groupName ) {
00277         $group = new self();
00278 
00282         foreach ( $this as $site ) {
00283             if ( $site->getGroup() === $groupName ) {
00284                 $group[] = $site;
00285             }
00286         }
00287 
00288         return $group;
00289     }
00290 
00299     const SERIAL_VERSION_ID = '2014-03-17';
00300 
00310     public static function getSerialVersionId() {
00311         return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
00312     }
00313 
00321     protected function getSerializationData() {
00322         //NOTE: When changing the structure, either implement unserialize() to handle the
00323         //      old structure too, or update SERIAL_VERSION_ID to kill any caches.
00324         return array_merge(
00325             parent::getSerializationData(),
00326             array(
00327                 'internalIds' => $this->byInternalId,
00328                 'globalIds' => $this->byGlobalId,
00329                 'navigationIds' => $this->byNavigationId
00330             )
00331         );
00332     }
00333 
00343     public function unserialize( $serialization ) {
00344         $serializationData = parent::unserialize( $serialization );
00345 
00346         $this->byInternalId = $serializationData['internalIds'];
00347         $this->byGlobalId = $serializationData['globalIds'];
00348         $this->byNavigationId = $serializationData['navigationIds'];
00349 
00350         return $serializationData;
00351     }
00352 }
00353 
00357 class SiteArray extends SiteList {
00358 }