[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZEnum class 4 // 5 // Created on: <24-ßÂ-2002 16:07:05 wy> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezenum.php 30 */ 31 32 include_once ( "lib/ezdb/classes/ezdb.php" ); 33 include_once ( "kernel/classes/datatypes/ezenum/ezenumvalue.php" ); 34 include_once ( "kernel/classes/datatypes/ezenum/ezenumobjectvalue.php" ); 35 36 /*! 37 \class eZEnum ezenum.php 38 \ingroup eZDatatype 39 \brief The class eZEnum does 40 41 */ 42 43 class eZEnum 44 { 45 /*! 46 Constructor 47 */ 48 function eZEnum( $id, $version ) 49 { 50 $this->ClassAttributeID = $id; 51 $this->ClassAttributeVersion = $version; 52 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion ); 53 $this->IsmultipleEnum = null; 54 $this->IsoptionEnum = null; 55 $this->ObjectEnumerations = null; 56 } 57 58 function attributes() 59 { 60 return array( 'contentclass_attributeid', 61 'contentclass_attributeversion', 62 'enum_list', 63 'enumobject_list', 64 'enum_ismultiple', 65 'enum_isoption' ); 66 } 67 68 function hasAttribute( $attr ) 69 { 70 return in_array( $attr, $this->attributes() ); 71 } 72 73 function &attribute( $attr ) 74 { 75 switch ( $attr ) 76 { 77 case "contentclass_attributeid" : 78 { 79 return $this->ClassAttributeID; 80 }break; 81 case "contentclass_attributeversion" : 82 { 83 return $this->ClassAttributeVersion; 84 }break; 85 case "enum_list" : 86 { 87 return $this->Enumerations; 88 }break; 89 case "enumobject_list" : 90 { 91 return $this->ObjectEnumerations; 92 }break; 93 case "enum_ismultiple" : 94 { 95 return $this->IsmultipleEnum; 96 }break; 97 case "enum_isoption" : 98 { 99 return $this->IsoptionEnum; 100 }break; 101 default : 102 { 103 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZEnum::attribute' ); 104 $retValue = null; 105 return $retValue; 106 }break; 107 } 108 } 109 110 function setObjectEnumValue( $contentObjectAttributeID, $contentObjectAttributeVersion ){ 111 $this->ObjectEnumerations = eZEnumObjectValue::fetchAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion ); 112 } 113 114 function removeObjectEnumerations( $contentObjectAttributeID, $contentObjectAttributeVersion ) 115 { 116 eZEnumObjectValue::removeAllElements( $contentObjectAttributeID, $contentObjectAttributeVersion ); 117 } 118 119 function storeObjectEnumeration( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue ) 120 { 121 $enumobjectvalue = eZEnumObjectValue::create( $contentObjectAttributeID, $contentObjectAttributeVersion, $enumID, $enumElement, $enumValue ); 122 $enumobjectvalue->store(); 123 } 124 125 function setIsmultipleValue( $value ) 126 { 127 $this->IsmultipleEnum = $value; 128 } 129 130 function setIsoptionValue( $value ) 131 { 132 $this->IsoptionEnum = $value; 133 } 134 135 function setValue( $array_enumid, $array_enumelement, $array_enumvalue, $version ) 136 { 137 $db =& eZDB::instance(); 138 $db->begin(); 139 140 for ($i=0;$i<count( $array_enumid );$i++ ) 141 { 142 $enumvalue = eZEnumValue::fetch( $array_enumid[$i], $version ); 143 $enumvalue->setAttribute( "enumelement", $array_enumelement[$i] ); 144 $enumvalue->setAttribute( "enumvalue", $array_enumvalue[$i] ); 145 $enumvalue->store(); 146 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion ); 147 } 148 $db->commit(); 149 } 150 151 function setVersion( $version ) 152 { 153 if ( $version == $this->ClassAttributeVersion ) 154 return; 155 156 $db =& eZDB::instance(); 157 $db->begin(); 158 159 eZEnumValue::removeAllElements( $this->ClassAttributeID, 0 ); 160 for ( $i=0;$i<count( $this->Enumerations );$i++ ) 161 { 162 $enum = $this->Enumerations[$i]; 163 $oldversion = $enum->attribute ( "contentclass_attribute_version" ); 164 $id = $enum->attribute( "id" ); 165 $contentClassAttributeID = $enum->attribute( "contentclass_attribute_id" ); 166 $element = $enum->attribute( "enumelement" ); 167 $value = $enum->attribute( "enumvalue" ); 168 $placement = $enum->attribute( "placement" ); 169 $enumCopy = eZEnumValue::createCopy( $id, 170 $contentClassAttributeID, 171 0, 172 $element, 173 $value, 174 $placement ); 175 $enumCopy->store(); 176 if ( $oldversion != $version ) 177 { 178 $enum->setAttribute("contentclass_attribute_version", $version ); 179 $enum->store(); 180 } 181 } 182 183 $db->commit(); 184 } 185 186 function removeOldVersion( $id, $version ) 187 { 188 eZEnumValue::removeAllElements( $id, $version ); 189 } 190 191 /*! 192 Adds an enumeration 193 */ 194 function addEnumeration( $element ) 195 { 196 $enumvalue = eZEnumValue::create( $this->ClassAttributeID, $this->ClassAttributeVersion, $element ); 197 $enumvalue->store(); 198 $this->Enumerations = eZEnumValue::fetchAllElements( $this->ClassAttributeID, $this->ClassAttributeVersion ); 199 } 200 201 /*! 202 Adds the enumeration value object \a $enumValue to the enumeration list. 203 */ 204 function addEnumerationValue( &$enumValue ) 205 { 206 $this->Enumerations[] = $enumValue; 207 } 208 209 function removeEnumeration( $id, $enumid, $version ) 210 { 211 eZEnumValue::remove( $enumid, $version ); 212 $this->Enumerations = eZEnumValue::fetchAllElements( $id, $version ); 213 } 214 215 var $Enumerations; 216 var $ObjectEnumerations; 217 var $ClassAttributeID; 218 var $ClassAttributeVersion; 219 var $IsmultipleEnum; 220 var $IsoptionEnum; 221 } 222 223 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |