eZ Publish  [4.0]
ezenum.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZEnum class
00004 //
00005 // Created on: <24-ßÂ-2002 16:07:05 wy>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezenum.php
00032 */
00033 
00034 //include_once( "lib/ezdb/classes/ezdb.php" );
00035 //include_once( "kernel/classes/datatypes/ezenum/ezenumvalue.php" );
00036 //include_once( "kernel/classes/datatypes/ezenum/ezenumobjectvalue.php" );
00037 
00038 /*!
00039   \class eZEnum ezenum.php
00040   \ingroup eZDatatype
00041   \brief The class eZEnum does
00042 
00043 */
00044 
00045 class eZEnum
00046 {
00047     /*!
00048      Constructor
00049     */
00050     function eZEnum( $id, $version )
00051     {
00052         $this->ClassAttributeID = $id;
00053         $this->ClassAttributeVersion = $version;
00054         $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
00055         $this->IsmultipleEnum = null;
00056         $this->IsoptionEnum = null;
00057         $this->ObjectEnumerations = null;
00058     }
00059 
00060     function attributes()
00061     {
00062         return array( 'contentclass_attributeid',
00063                       'contentclass_attributeversion',
00064                       'enum_list',
00065                       'enumobject_list',
00066                       'enum_ismultiple',
00067                       'enum_isoption' );
00068     }
00069 
00070     function hasAttribute( $attr )
00071     {
00072         return in_array( $attr, $this->attributes() );
00073     }
00074 
00075     function attribute( $attr )
00076     {
00077         switch ( $attr )
00078         {
00079             case "contentclass_attributeid" :
00080             {
00081                 return $this->ClassAttributeID;
00082             }break;
00083             case "contentclass_attributeversion" :
00084             {
00085                 return $this->ClassAttributeVersion;
00086             }break;
00087             case "enum_list" :
00088             {
00089                 return $this->Enumerations;
00090             }break;
00091             case "enumobject_list" :
00092             {
00093                 return $this->ObjectEnumerations;
00094             }break;
00095             case "enum_ismultiple" :
00096             {
00097                 return $this->IsmultipleEnum;
00098             }break;
00099             case "enum_isoption" :
00100             {
00101                 return $this->IsoptionEnum;
00102             }break;
00103             default :
00104             {
00105                 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZEnum::attribute' );
00106                 return null;
00107             }break;
00108         }
00109     }
00110 
00111     function setObjectEnumValue( $contentObjectAttributeID, $contentObjectAttributeVersion ){
00112         $this->ObjectEnumerations = eZEnumObjectValue::fetchAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion );
00113     }
00114 
00115     static function removeObjectEnumerations( $contentObjectAttributeID, $contentObjectAttributeVersion )
00116     {
00117          eZEnumObjectValue::removeAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion );
00118     }
00119 
00120     static function storeObjectEnumeration( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue )
00121     {
00122         $enumobjectvalue = eZEnumObjectValue::create( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue );
00123         $enumobjectvalue->store();
00124     }
00125 
00126     function setIsmultipleValue( $value )
00127     {
00128         $this->IsmultipleEnum = $value;
00129     }
00130 
00131     function setIsoptionValue( $value )
00132     {
00133         $this->IsoptionEnum = $value;
00134     }
00135 
00136     function setValue( $array_enumid, $array_enumelement, $array_enumvalue, $version )
00137     {
00138         $db = eZDB::instance();
00139         $db->begin();
00140 
00141         for ($i=0;$i<count( $array_enumid );$i++ )
00142         {
00143             $enumvalue = eZEnumValue::fetch( $array_enumid[$i], $version );
00144             $enumvalue->setAttribute( "enumelement", $array_enumelement[$i] );
00145             $enumvalue->setAttribute( "enumvalue", $array_enumvalue[$i] );
00146             $enumvalue->store();
00147             $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
00148         }
00149         $db->commit();
00150     }
00151 
00152     function setVersion( $version )
00153     {
00154         if ( $version == $this->ClassAttributeVersion )
00155             return;
00156 
00157         $db = eZDB::instance();
00158         $db->begin();
00159 
00160         eZEnumValue::removeAllElements( $this->ClassAttributeID, 0 );
00161         foreach( $this->Enumerations as $enum )
00162         {
00163             $oldversion = $enum->attribute ( "contentclass_attribute_version" );
00164             $id = $enum->attribute( "id" );
00165             $contentClassAttributeID = $enum->attribute( "contentclass_attribute_id" );
00166             $element = $enum->attribute( "enumelement" );
00167             $value = $enum->attribute( "enumvalue" );
00168             $placement = $enum->attribute( "placement" );
00169             $enumCopy = eZEnumValue::createCopy( $id,
00170                                                  $contentClassAttributeID,
00171                                                  0,
00172                                                  $element,
00173                                                  $value,
00174                                                  $placement );
00175             $enumCopy->store();
00176             if ( $oldversion != $version )
00177             {
00178                 $enum->setAttribute("contentclass_attribute_version", $version );
00179                 $enum->store();
00180             }
00181         }
00182 
00183         $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
00184 
00185         $db->commit();
00186     }
00187 
00188     static function removeOldVersion( $id, $version )
00189     {
00190         eZEnumValue::removeAllElements( $id, $version );
00191     }
00192 
00193     /*!
00194      Adds an enumeration
00195     */
00196     function addEnumeration( $element )
00197     {
00198         $enumvalue = eZEnumValue::create( $this->ClassAttributeID, $this->ClassAttributeVersion, $element );
00199         $enumvalue->store();
00200         $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
00201     }
00202 
00203     /*!
00204      Adds the enumeration value object \a $enumValue to the enumeration list.
00205     */
00206     function addEnumerationValue( $enumValue )
00207     {
00208         $this->Enumerations[] = $enumValue;
00209     }
00210 
00211     function removeEnumeration( $id, $enumid, $version )
00212     {
00213        eZEnumValue::removeByID( $enumid, $version );
00214        $this->Enumerations = eZEnumValue::fetchAllElements( $id, $version );
00215     }
00216 
00217     public $Enumerations;
00218     public $ObjectEnumerations;
00219     public $ClassAttributeID;
00220     public $ClassAttributeVersion;
00221     public $IsmultipleEnum;
00222     public $IsoptionEnum;
00223 }
00224 
00225 ?>