eZ Publish  [trunk]
ezcontentclassnamelist.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZContentClassNameList class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 class eZContentClassNameList extends eZSerializedObjectNameList
00012 {
00013     function eZContentClassNameList( $serializedNameList = false )
00014     {
00015         eZSerializedObjectNameList::eZSerializedObjectNameList( $serializedNameList );
00016     }
00017 
00018     function create( $serializedNamesString = false )
00019     {
00020         $object = new eZContentClassNameList( $serializedNamesString );
00021         return $object;
00022     }
00023 
00024     function store( $contentClass )
00025     {
00026         if ( $this->hasDirtyData() && is_object($contentClass ) )
00027         {
00028             $classID = $contentClass->attribute( 'id' );
00029             $classVersion = $contentClass->attribute( 'version' );
00030             $languages = $contentClass->attribute( 'languages' );
00031             $initialLanguageID = $contentClass->attribute( 'initial_language_id' );
00032 
00033             // update existing
00034             $contentClassNames = eZContentClassName::fetchList( $classID, $classVersion, array_keys( $languages ) );
00035             foreach ( $contentClassNames as $className )
00036             {
00037                 $languageLocale = $className->attribute( 'language_locale' );
00038                 $className->setAttribute( 'name', $this->nameByLanguageLocale( $languageLocale ) );
00039                 if ( $initialLanguageID == $className->attribute( 'language_id' ) )
00040                     $className->setAttribute( 'language_id', $initialLanguageID | 1 );
00041 
00042                 $className->sync(); // avoid unnecessary sql-updates if nothing changed
00043 
00044                 unset( $languages[$languageLocale] );
00045             }
00046 
00047             // create new
00048             if ( count( $languages ) > 0 )
00049             {
00050                 foreach ( $languages as $languageLocale => $language )
00051                 {
00052                     if ( !$language instanceof eZContentLanguage )
00053                     {
00054                         eZDebug::writeError( $languageLocale . ' is not a instance of eZContentLanguage', __METHOD__ );
00055                         continue;
00056                     }
00057                     $languageID = $language->attribute( 'id' );
00058                     if ( $initialLanguageID == $languageID )
00059                         $languageID = $initialLanguageID | 1;
00060 
00061                     $className = new eZContentClassName( array( 'contentclass_id' => $classID,
00062                                                                 'contentclass_version' => $classVersion,
00063                                                                 'language_locale' => $languageLocale,
00064                                                                 'language_id' => $languageID,
00065                                                                 'name' => $this->nameByLanguageLocale( $languageLocale ) ) );
00066                     $className->store();
00067                 }
00068             }
00069 
00070             $this->setHasDirtyData( false );
00071         }
00072     }
00073 
00074     static function remove( $contentClass )
00075     {
00076         eZContentClassName::removeClassName( $contentClass->attribute( 'id' ), $contentClass->attribute( 'version' ) );
00077     }
00078 }
00079 
00080 ?>