Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezenum.php
Go to the documentation of this file.
1 <?php
18 class eZEnum
19 {
26 public function __construct( $id, $version )
27 {
28 $this->ClassAttributeID = $id;
29 $this->ClassAttributeVersion = $version;
30 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
31 $this->IsmultipleEnum = null;
32 $this->IsoptionEnum = null;
33 $this->ObjectEnumerations = null;
34 }
35
36 function attributes()
37 {
38 return array( 'contentclass_attributeid',
39 'contentclass_attributeversion',
40 'enum_list',
41 'enumobject_list',
42 'enum_ismultiple',
43 'enum_isoption' );
44 }
45
46 function hasAttribute( $attr )
47 {
48 return in_array( $attr, $this->attributes() );
49 }
50
51 function attribute( $attr )
52 {
53 switch ( $attr )
54 {
55 case "contentclass_attributeid" :
56 {
57 return $this->ClassAttributeID;
58 }break;
59 case "contentclass_attributeversion" :
60 {
61 return $this->ClassAttributeVersion;
62 }break;
63 case "enum_list" :
64 {
65 return $this->Enumerations;
66 }break;
67 case "enumobject_list" :
68 {
69 return $this->ObjectEnumerations;
70 }break;
71 case "enum_ismultiple" :
72 {
73 return $this->IsmultipleEnum;
74 }break;
75 case "enum_isoption" :
76 {
77 return $this->IsoptionEnum;
78 }break;
79 default :
80 {
81 eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
82 return null;
83 }break;
84 }
85 }
86
87 function setObjectEnumValue( $contentObjectAttributeID, $contentObjectAttributeVersion ){
88 $this->ObjectEnumerations = eZEnumObjectValue::fetchAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion );
89 }
90
91 static function removeObjectEnumerations( $contentObjectAttributeID, $contentObjectAttributeVersion )
92 {
93 eZEnumObjectValue::removeAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion );
94 }
95
96 static function storeObjectEnumeration( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue )
97 {
98 $enumobjectvalue = eZEnumObjectValue::create( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue );
99 $enumobjectvalue->store();
100 }
101
102 function setIsmultipleValue( $value )
103 {
104 $this->IsmultipleEnum = $value;
105 }
106
107 function setIsoptionValue( $value )
108 {
109 $this->IsoptionEnum = $value;
110 }
111
112 function setValue( $array_enumid, $array_enumelement, $array_enumvalue, $version )
113 {
114 $db = eZDB::instance();
115 $db->begin();
116
117 for ($i=0;$i<count( $array_enumid );$i++ )
118 {
119 $enumvalue = eZEnumValue::fetch( $array_enumid[$i], $version );
120 if ( $enumvalue === null )
121 continue;
122 $enumvalue->setAttribute( "enumelement", $array_enumelement[$i] );
123 $enumvalue->setAttribute( "enumvalue", $array_enumvalue[$i] );
124 $enumvalue->store();
125 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
126 }
127 $db->commit();
128 }
129
130 function setVersion( $version )
131 {
132 if ( $version == $this->ClassAttributeVersion )
133 return;
134
135 $db = eZDB::instance();
136 $db->begin();
137
138 eZEnumValue::removeAllElements( $this->ClassAttributeID, 0 );
139 foreach( $this->Enumerations as $enum )
140 {
141 $oldversion = $enum->attribute ( "contentclass_attribute_version" );
142 $id = $enum->attribute( "id" );
143 $contentClassAttributeID = $enum->attribute( "contentclass_attribute_id" );
144 $element = $enum->attribute( "enumelement" );
145 $value = $enum->attribute( "enumvalue" );
146 $placement = $enum->attribute( "placement" );
147 $enumCopy = eZEnumValue::createCopy( $id,
148 $contentClassAttributeID,
149 0,
150 $element,
151 $value,
152 $placement );
153 $enumCopy->store();
154 if ( $oldversion != $version )
155 {
156 $enum->setAttribute("contentclass_attribute_version", $version );
157 $enum->store();
158 }
159 }
160
161 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
162
163 $db->commit();
164 }
165
166 static function removeOldVersion( $id, $version )
167 {
168 eZEnumValue::removeAllElements( $id, $version );
169 }
170
174 function addEnumeration( $element )
175 {
176 $enumvalue = eZEnumValue::create( $this->ClassAttributeID, $this->ClassAttributeVersion, $element );
177 $enumvalue->store();
178 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion );
179 }
180
184 function addEnumerationValue( $enumValue )
185 {
186 $this->Enumerations[] = $enumValue;
187 }
188
189 function removeEnumeration( $id, $enumid, $version )
190 {
191 eZEnumValue::removeByID( $enumid, $version );
192 $this->Enumerations = eZEnumValue::fetchAllElements( $id, $version );
193 }
194
195 public $Enumerations;
196 public $ObjectEnumerations;
197 public $ClassAttributeID;
198 public $ClassAttributeVersion;
199 public $IsmultipleEnum;
200 public $IsoptionEnum;
201 }
202
203 ?>
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZEnumObjectValue\fetchAllElements
static fetchAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion, $asObject=true)
Definition: ezenumobjectvalue.php:94
eZEnumObjectValue\removeAllElements
static removeAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion)
Definition: ezenumobjectvalue.php:61
eZEnumObjectValue\create
static create( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue)
Definition: ezenumobjectvalue.php:51
eZEnumValue\removeByID
static removeByID( $id, $version)
Definition: ezenumvalue.php:93
eZEnumValue\removeAllElements
static removeAllElements( $contentClassAttributeID, $version)
Definition: ezenumvalue.php:86
eZEnumValue\fetchAllElements
static fetchAllElements( $classAttributeID, $version, $asObject=true)
Definition: ezenumvalue.php:109
eZEnumValue\fetch
static fetch( $id, $version, $asObject=true)
Definition: ezenumvalue.php:100
eZEnumValue\createCopy
static createCopy( $id, $contentClassAttributeID, $contentClassAttributeVersion, $element, $value, $placement)
Definition: ezenumvalue.php:75
eZEnumValue\create
static create( $contentClassAttributeID, $contentClassAttributeVersion, $element)
Definition: ezenumvalue.php:61
eZEnum
The class eZEnum does.
Definition: ezenum.php:19
eZEnum\setVersion
setVersion( $version)
Definition: ezenum.php:130
eZEnum\removeOldVersion
static removeOldVersion( $id, $version)
Definition: ezenum.php:166
eZEnum\setValue
setValue( $array_enumid, $array_enumelement, $array_enumvalue, $version)
Definition: ezenum.php:112
eZEnum\setIsmultipleValue
setIsmultipleValue( $value)
Definition: ezenum.php:102
eZEnum\hasAttribute
hasAttribute( $attr)
Definition: ezenum.php:46
eZEnum\removeObjectEnumerations
static removeObjectEnumerations( $contentObjectAttributeID, $contentObjectAttributeVersion)
Definition: ezenum.php:91
eZEnum\setObjectEnumValue
setObjectEnumValue( $contentObjectAttributeID, $contentObjectAttributeVersion)
Definition: ezenum.php:87
eZEnum\$IsmultipleEnum
$IsmultipleEnum
Definition: ezenum.php:199
eZEnum\addEnumerationValue
addEnumerationValue( $enumValue)
Definition: ezenum.php:184
eZEnum\storeObjectEnumeration
static storeObjectEnumeration( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue)
Definition: ezenum.php:96
eZEnum\$ClassAttributeID
$ClassAttributeID
Definition: ezenum.php:197
eZEnum\attributes
attributes()
Definition: ezenum.php:36
eZEnum\setIsoptionValue
setIsoptionValue( $value)
Definition: ezenum.php:107
eZEnum\__construct
__construct( $id, $version)
Definition: ezenum.php:26
eZEnum\addEnumeration
addEnumeration( $element)
Definition: ezenum.php:174
eZEnum\$ObjectEnumerations
$ObjectEnumerations
Definition: ezenum.php:196
eZEnum\$IsoptionEnum
$IsoptionEnum
Definition: ezenum.php:200
eZEnum\removeEnumeration
removeEnumeration( $id, $enumid, $version)
Definition: ezenum.php:189
eZEnum\$ClassAttributeVersion
$ClassAttributeVersion
Definition: ezenum.php:198
eZEnum\attribute
attribute( $attr)
Definition: ezenum.php:51
eZEnum\$Enumerations
$Enumerations
Definition: ezenum.php:195
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.