eZ Publish  [4.0]
ezcontentclassnamelist.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Created on: <02-Oct-2006 13:37:23 dl>
00004 //
00005 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00006 // SOFTWARE NAME: eZ Publish
00007 // SOFTWARE RELEASE: 4.0.x
00008 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00009 // SOFTWARE LICENSE: GNU General Public License v2.0
00010 // NOTICE: >
00011 //   This program is free software; you can redistribute it and/or
00012 //   modify it under the terms of version 2.0  of the GNU General
00013 //   Public License as published by the Free Software Foundation.
00014 //
00015 //   This program is distributed in the hope that it will be useful,
00016 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //   GNU General Public License for more details.
00019 //
00020 //   You should have received a copy of version 2.0 of the GNU General
00021 //   Public License along with this program; if not, write to the Free
00022 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 //   MA 02110-1301, USA.
00024 //
00025 //
00026 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00027 //
00028 
00029 //include_once( 'kernel/classes/ezserializedobjectnamelist.php' );
00030 //include_once( 'kernel/classes/ezcontentclassname.php' );
00031 
00032 class eZContentClassNameList extends eZSerializedObjectNameList
00033 {
00034     function eZContentClassNameList( $serializedNameList = false )
00035     {
00036         eZSerializedObjectNameList::eZSerializedObjectNameList( $serializedNameList );
00037     }
00038 
00039     function create( $serializedNamesString = false )
00040     {
00041         $object = new eZContentClassNameList( $serializedNamesString );
00042         return $object;
00043     }
00044 
00045     function store( $contentClass )
00046     {
00047         if ( $this->hasDirtyData() && is_object($contentClass ) )
00048         {
00049             $classID = $contentClass->attribute( 'id' );
00050             $classVersion = $contentClass->attribute( 'version' );
00051             $languages = $contentClass->attribute( 'languages' );
00052             $initialLanguageID = $contentClass->attribute( 'initial_language_id' );
00053 
00054             // update existing
00055             $contentClassNames = eZContentClassName::fetchList( $classID, $classVersion, array_keys( $languages ) );
00056             foreach ( $contentClassNames as $className )
00057             {
00058                 $languageLocale = $className->attribute( 'language_locale' );
00059                 $className->setAttribute( 'name', $this->nameByLanguageLocale( $languageLocale ) );
00060                 if ( $initialLanguageID == $className->attribute( 'language_id' ) )
00061                     $className->setAttribute( 'language_id', $initialLanguageID | 1 );
00062 
00063                 $className->sync(); // avoid unnecessary sql-updates if nothing changed
00064 
00065                 unset( $languages[$languageLocale] );
00066             }
00067 
00068             // create new
00069             if ( count( $languages ) > 0 )
00070             {
00071                 foreach ( $languages as $languageLocale => $language )
00072                 {
00073                     $languageID = $language->attribute( 'id' );
00074                     if ( $initialLanguageID == $languageID )
00075                         $languageID = $initialLanguageID | 1;
00076 
00077                     $className = new eZContentClassName( array( 'contentclass_id' => $classID,
00078                                                                 'contentclass_version' => $classVersion,
00079                                                                 'language_locale' => $languageLocale,
00080                                                                 'language_id' => $languageID,
00081                                                                 'name' => $this->nameByLanguageLocale( $languageLocale ) ) );
00082                     $className->store();
00083                 }
00084             }
00085 
00086             $this->setHasDirtyData( false );
00087         }
00088     }
00089 
00090     static function remove( $contentClass )
00091     {
00092         eZContentClassName::removeClassName( $contentClass->attribute( 'id' ), $contentClass->attribute( 'version' ) );
00093     }
00094 };
00095 
00096 ?>