00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00040
00041
00042
00043
00044
00045 class eZEnum
00046 {
00047
00048
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 $retValue = null;
00107 return $retValue;
00108 }break;
00109 }
00110 }
00111
00112 function setObjectEnumValue( $contentObjectAttributeID, $contentObjectAttributeVersion ){
00113 $this->ObjectEnumerations = eZEnumObjectValue::fetchAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion );
00114 }
00115
00116 function removeObjectEnumerations( $contentObjectAttributeID, $contentObjectAttributeVersion )
00117 {
00118 eZEnumObjectValue::removeAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion );
00119 }
00120
00121 function storeObjectEnumeration( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue )
00122 {
00123 $enumobjectvalue = eZEnumObjectValue::create( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue );
00124 $enumobjectvalue->store();
00125 }
00126
00127 function setIsmultipleValue( $value )
00128 {
00129 $this->IsmultipleEnum = $value;
00130 }
00131
00132 function setIsoptionValue( $value )
00133 {
00134 $this->IsoptionEnum = $value;
00135 }
00136
00137 function setValue( $array_enumid, $array_enumelement, $array_enumvalue, $version )
00138 {
00139 $db =& eZDB::instance();
00140 $db->begin();
00141
00142 for ($i=0;$i<count( $array_enumid );$i++ )
00143 {
00144 $enumvalue = eZEnumValue::fetch( $array_enumid[$i], $version );
00145 $enumvalue->setAttribute( "enumelement", $array_enumelement[$i] );
00146 $enumvalue->setAttribute( "enumvalue", $array_enumvalue[$i] );
00147 $enumvalue->store();
00148 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
00149 }
00150 $db->commit();
00151 }
00152
00153 function setVersion( $version )
00154 {
00155 if ( $version == $this->ClassAttributeVersion )
00156 return;
00157
00158 $db =& eZDB::instance();
00159 $db->begin();
00160
00161 eZEnumValue::removeAllElements( $this->ClassAttributeID, 0 );
00162 for ( $i=0;$i<count( $this->Enumerations );$i++ )
00163 {
00164 $enum = $this->Enumerations[$i];
00165 $oldversion = $enum->attribute ( "contentclass_attribute_version" );
00166 $id = $enum->attribute( "id" );
00167 $contentClassAttributeID = $enum->attribute( "contentclass_attribute_id" );
00168 $element = $enum->attribute( "enumelement" );
00169 $value = $enum->attribute( "enumvalue" );
00170 $placement = $enum->attribute( "placement" );
00171 $enumCopy = eZEnumValue::createCopy( $id,
00172 $contentClassAttributeID,
00173 0,
00174 $element,
00175 $value,
00176 $placement );
00177 $enumCopy->store();
00178 if ( $oldversion != $version )
00179 {
00180 $enum->setAttribute("contentclass_attribute_version", $version );
00181 $enum->store();
00182 }
00183 }
00184
00185 $db->commit();
00186 }
00187
00188 function removeOldVersion( $id, $version )
00189 {
00190 eZEnumValue::removeAllElements( $id, $version );
00191 }
00192
00193
00194
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
00205
00206 function addEnumerationValue( &$enumValue )
00207 {
00208 $this->Enumerations[] = $enumValue;
00209 }
00210
00211 function removeEnumeration( $id, $enumid, $version )
00212 {
00213 eZEnumValue::remove( $enumid, $version );
00214 $this->Enumerations = eZEnumValue::fetchAllElements( $id, $version );
00215 }
00216
00217 var $Enumerations;
00218 var $ObjectEnumerations;
00219 var $ClassAttributeID;
00220 var $ClassAttributeVersion;
00221 var $IsmultipleEnum;
00222 var $IsoptionEnum;
00223 }
00224
00225 ?>