|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZEnum 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 eZEnum ezenum.php 00013 \ingroup eZDatatype 00014 \brief The class eZEnum does 00015 00016 */ 00017 00018 class eZEnum 00019 { 00020 /*! 00021 Constructor 00022 */ 00023 function eZEnum( $id, $version ) 00024 { 00025 $this->ClassAttributeID = $id; 00026 $this->ClassAttributeVersion = $version; 00027 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion ); 00028 $this->IsmultipleEnum = null; 00029 $this->IsoptionEnum = null; 00030 $this->ObjectEnumerations = null; 00031 } 00032 00033 function attributes() 00034 { 00035 return array( 'contentclass_attributeid', 00036 'contentclass_attributeversion', 00037 'enum_list', 00038 'enumobject_list', 00039 'enum_ismultiple', 00040 'enum_isoption' ); 00041 } 00042 00043 function hasAttribute( $attr ) 00044 { 00045 return in_array( $attr, $this->attributes() ); 00046 } 00047 00048 function attribute( $attr ) 00049 { 00050 switch ( $attr ) 00051 { 00052 case "contentclass_attributeid" : 00053 { 00054 return $this->ClassAttributeID; 00055 }break; 00056 case "contentclass_attributeversion" : 00057 { 00058 return $this->ClassAttributeVersion; 00059 }break; 00060 case "enum_list" : 00061 { 00062 return $this->Enumerations; 00063 }break; 00064 case "enumobject_list" : 00065 { 00066 return $this->ObjectEnumerations; 00067 }break; 00068 case "enum_ismultiple" : 00069 { 00070 return $this->IsmultipleEnum; 00071 }break; 00072 case "enum_isoption" : 00073 { 00074 return $this->IsoptionEnum; 00075 }break; 00076 default : 00077 { 00078 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ ); 00079 return null; 00080 }break; 00081 } 00082 } 00083 00084 function setObjectEnumValue( $contentObjectAttributeID, $contentObjectAttributeVersion ){ 00085 $this->ObjectEnumerations = eZEnumObjectValue::fetchAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion ); 00086 } 00087 00088 static function removeObjectEnumerations( $contentObjectAttributeID, $contentObjectAttributeVersion ) 00089 { 00090 eZEnumObjectValue::removeAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion ); 00091 } 00092 00093 static function storeObjectEnumeration( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue ) 00094 { 00095 $enumobjectvalue = eZEnumObjectValue::create( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue ); 00096 $enumobjectvalue->store(); 00097 } 00098 00099 function setIsmultipleValue( $value ) 00100 { 00101 $this->IsmultipleEnum = $value; 00102 } 00103 00104 function setIsoptionValue( $value ) 00105 { 00106 $this->IsoptionEnum = $value; 00107 } 00108 00109 function setValue( $array_enumid, $array_enumelement, $array_enumvalue, $version ) 00110 { 00111 $db = eZDB::instance(); 00112 $db->begin(); 00113 00114 for ($i=0;$i<count( $array_enumid );$i++ ) 00115 { 00116 $enumvalue = eZEnumValue::fetch( $array_enumid[$i], $version ); 00117 $enumvalue->setAttribute( "enumelement", $array_enumelement[$i] ); 00118 $enumvalue->setAttribute( "enumvalue", $array_enumvalue[$i] ); 00119 $enumvalue->store(); 00120 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion ); 00121 } 00122 $db->commit(); 00123 } 00124 00125 function setVersion( $version ) 00126 { 00127 if ( $version == $this->ClassAttributeVersion ) 00128 return; 00129 00130 $db = eZDB::instance(); 00131 $db->begin(); 00132 00133 eZEnumValue::removeAllElements( $this->ClassAttributeID, 0 ); 00134 foreach( $this->Enumerations as $enum ) 00135 { 00136 $oldversion = $enum->attribute ( "contentclass_attribute_version" ); 00137 $id = $enum->attribute( "id" ); 00138 $contentClassAttributeID = $enum->attribute( "contentclass_attribute_id" ); 00139 $element = $enum->attribute( "enumelement" ); 00140 $value = $enum->attribute( "enumvalue" ); 00141 $placement = $enum->attribute( "placement" ); 00142 $enumCopy = eZEnumValue::createCopy( $id, 00143 $contentClassAttributeID, 00144 0, 00145 $element, 00146 $value, 00147 $placement ); 00148 $enumCopy->store(); 00149 if ( $oldversion != $version ) 00150 { 00151 $enum->setAttribute("contentclass_attribute_version", $version ); 00152 $enum->store(); 00153 } 00154 } 00155 00156 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion ); 00157 00158 $db->commit(); 00159 } 00160 00161 static function removeOldVersion( $id, $version ) 00162 { 00163 eZEnumValue::removeAllElements( $id, $version ); 00164 } 00165 00166 /*! 00167 Adds an enumeration 00168 */ 00169 function addEnumeration( $element ) 00170 { 00171 $enumvalue = eZEnumValue::create( $this->ClassAttributeID, $this->ClassAttributeVersion, $element ); 00172 $enumvalue->store(); 00173 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion ); 00174 } 00175 00176 /*! 00177 Adds the enumeration value object \a $enumValue to the enumeration list. 00178 */ 00179 function addEnumerationValue( $enumValue ) 00180 { 00181 $this->Enumerations[] = $enumValue; 00182 } 00183 00184 function removeEnumeration( $id, $enumid, $version ) 00185 { 00186 eZEnumValue::removeByID( $enumid, $version ); 00187 $this->Enumerations = eZEnumValue::fetchAllElements( $id, $version ); 00188 } 00189 00190 public $Enumerations; 00191 public $ObjectEnumerations; 00192 public $ClassAttributeID; 00193 public $ClassAttributeVersion; 00194 public $IsmultipleEnum; 00195 public $IsoptionEnum; 00196 } 00197 00198 ?>