eZ Publish  [trunk]
ezcontentobjecttranslation.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZContentObjectTranslation 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 /*!
00012   \class eZContentObjectTranslation ezcontentobjecttranslation.php
00013   \brief eZContentObjectTranslation handles translation a translation of content objects
00014   \ingroup eZKernel
00015 
00016   \sa eZContentObject eZContentObjectVersion eZContentObjectTranslation
00017 */
00018 
00019 class eZContentObjectTranslation
00020 {
00021     function eZContentObjectTranslation( $contentObjectID, $version, $languageCode )
00022     {
00023         $this->ContentObjectID = $contentObjectID;
00024         $this->Version = $version;
00025         $this->LanguageCode = $languageCode;
00026         $this->Locale = null;
00027     }
00028 
00029     function languageCode()
00030     {
00031         return $this->LanguageCode;
00032     }
00033 
00034     function attributes()
00035     {
00036         return array( 'contentobject_id',
00037                       'version',
00038                       'language_code',
00039                       'locale' );
00040     }
00041 
00042     function hasAttribute( $attribute )
00043     {
00044         return in_array( $attribute, $this->attributes() );
00045     }
00046 
00047     function attribute( $attribute )
00048     {
00049         if ( $attribute == 'contentobject_id' )
00050             return $this->ContentObjectID;
00051         else if ( $attribute == 'version' )
00052             return $this->Version;
00053         else if ( $attribute == 'language_code' )
00054             return $this->LanguageCode;
00055         else if ( $attribute == 'locale' )
00056             return $this->locale();
00057         else
00058         {
00059             eZDebug::writeError( "Attribute '$attribute' does not exist", __METHOD__ );
00060             return null;
00061         }
00062     }
00063 
00064     function locale()
00065     {
00066         if ( $this->Locale !== null )
00067             return $this->Locale;
00068         $this->Locale = eZLocale::instance( $this->LanguageCode );
00069         return $this->Locale;
00070     }
00071 
00072     /*!
00073      Returns the attributes for the current content object translation.
00074     */
00075     function objectAttributes( $asObject = true )
00076     {
00077         return eZContentObjectVersion::fetchAttributes( $this->Version, $this->ContentObjectID, $this->LanguageCode, $asObject );
00078     }
00079 
00080     /// The content object identifier
00081     public $ContentObjectID;
00082     /// Contains the content object
00083     public $Version;
00084 
00085     /// Contains the language code for the current translation
00086     public $LanguageCode;
00087 }
00088 ?>