|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZContentClass class 00004 // 00005 // 00006 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00007 // SOFTWARE NAME: eZ Publish 00008 // SOFTWARE RELEASE: 4.0.x 00009 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00010 // SOFTWARE LICENSE: GNU General Public License v2.0 00011 // NOTICE: > 00012 // This program is free software; you can redistribute it and/or 00013 // modify it under the terms of version 2.0 of the GNU General 00014 // Public License as published by the Free Software Foundation. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of version 2.0 of the GNU General 00022 // Public License along with this program; if not, write to the Free 00023 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00024 // MA 02110-1301, USA. 00025 // 00026 // 00027 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00028 // 00029 00030 //!! eZKernel 00031 //! The class eZContentClassClassGroup 00032 /*! 00033 00034 */ 00035 00036 //include_once( "lib/ezdb/classes/ezdb.php" ); 00037 //include_once( "kernel/classes/ezpersistentobject.php" ); 00038 //include_once( "kernel/classes/ezcontentclassgroup.php" ); 00039 00040 class eZContentClassClassGroup extends eZPersistentObject 00041 { 00042 function eZContentClassClassGroup( $row ) 00043 { 00044 $this->eZPersistentObject( $row ); 00045 } 00046 00047 static function definition() 00048 { 00049 return array( "fields" => array( "contentclass_id" => array( 'name' => "ContentClassID", 00050 'datatype' => 'integer', 00051 'default' => 0, 00052 'required' => true, 00053 'foreign_class' => 'eZContentClass', 00054 'foreign_attribute' => 'id', 00055 'multiplicity' => '1..*' ), 00056 "contentclass_version" => array( 'name' => "ContentClassVersion", 00057 'datatype' => 'integer', 00058 'default' => 0, 00059 'required' => true ), 00060 "group_id" => array( 'name' => "GroupID", 00061 'datatype' => 'integer', 00062 'default' => 0, 00063 'required' => true ), 00064 "group_name" => array( 'name' => "GroupName", 00065 'datatype' => 'string', 00066 'default' => '', 00067 'required' => true ) ), 00068 "keys" => array( "contentclass_id", "contentclass_version", "group_id" ), 00069 // "increment_key" => "id", 00070 "class_name" => "eZContentClassClassGroup", 00071 "sort" => array( "contentclass_id" => "asc" ), 00072 "name" => "ezcontentclass_classgroup" ); 00073 } 00074 00075 static function create( $contentclass_id, $contentclass_version, $group_id, $group_name ) 00076 { 00077 if( $contentclass_version == null ) 00078 { 00079 $contentclass_version = 0; 00080 } 00081 $row = array("contentclass_id" => $contentclass_id, 00082 "contentclass_version" => $contentclass_version, 00083 "group_id" => $group_id, 00084 "group_name" => $group_name); 00085 return new eZContentClassClassGroup( $row ); 00086 } 00087 00088 static function update( $contentclass_version, $group_id, $group_name ) 00089 { 00090 if( $contentclass_version == null ) 00091 { 00092 $row = array( 'group_id' => $group_id ); 00093 } 00094 else 00095 { 00096 $row = array( 'contentclass_version' => $contentclass_version, 00097 'group_id' => $group_id ); 00098 } 00099 00100 eZPersistentObject::updateObjectList( array( 'definition' => eZContentClassClassGroup::definition(), 00101 'update_fields' => array( 'group_name' => $group_name ), 00102 'conditions' => $row ) ); 00103 } 00104 00105 /*! 00106 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00107 the calls within a db transaction; thus within db->begin and db->commit. 00108 */ 00109 static function removeGroup( $contentclass_id, $contentclass_version, $group_id ) 00110 { 00111 if ( $contentclass_version == null ) 00112 { 00113 eZPersistentObject::removeObject( eZContentClassClassGroup::definition(), 00114 array("contentclass_id" => $contentclass_id, 00115 "group_id" => $group_id ) ); 00116 } 00117 else 00118 { 00119 eZPersistentObject::removeObject( eZContentClassClassGroup::definition(), 00120 array("contentclass_id" => $contentclass_id, 00121 "contentclass_version" =>$contentclass_version, 00122 "group_id" => $group_id ) ); 00123 } 00124 } 00125 00126 /*! 00127 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00128 the calls within a db transaction; thus within db->begin and db->commit. 00129 */ 00130 static function removeGroupMembers( $group_id ) 00131 { 00132 eZPersistentObject::removeObject( eZContentClassClassGroup::definition(), 00133 array( "group_id" => $group_id ) ); 00134 } 00135 00136 /*! 00137 \note Transaction unsafe. If you call several transaction unsafe methods you must enclose 00138 the calls within a db transaction; thus within db->begin and db->commit. 00139 */ 00140 static function removeClassMembers( $contentclass_id, $contentclass_version ) 00141 { 00142 eZPersistentObject::removeObject( eZContentClassClassGroup::definition(), 00143 array( "contentclass_id" =>$contentclass_id, 00144 "contentclass_version" =>$contentclass_version ) ); 00145 } 00146 00147 static function fetch( $contentclass_id, $contentclass_version, $group_id, $asObject = true ) 00148 { 00149 return eZPersistentObject::fetchObject( eZContentClassClassGroup::definition(), 00150 null, 00151 array("contentclass_id" => $contentclass_id, 00152 "contentclass_version" =>$contentclass_version, 00153 "group_id" => $group_id ), 00154 $asObject ); 00155 } 00156 00157 static function fetchClassList( $contentclass_version, $group_id, $asObject = true, $orderByArray = array( 'name' ) ) 00158 { 00159 $versionCond = ''; 00160 $orderByClause = ''; 00161 $group_id =(int) $group_id; 00162 $classNameSqlFilter = eZContentClassName::sqlEmptyFilter(); 00163 00164 if ( $contentclass_version !== null ) 00165 { 00166 $contentclass_version =(int) $contentclass_version; 00167 $versionCond = "AND class_group.contentclass_version='$contentclass_version' 00168 AND contentclass.version='$contentclass_version'\n"; 00169 } 00170 00171 if ( $orderByArray ) 00172 { 00173 foreach( array_keys( $orderByArray ) as $key ) 00174 { 00175 if ( strcasecmp( $orderByArray[$key], 'name' ) === 0 ) 00176 { 00177 $classNameSqlFilter = eZContentClassName::sqlAppendFilter( 'contentclass' ); 00178 $orderByArray[$key] = $classNameSqlFilter['orderBy']; 00179 } 00180 } 00181 00182 $orderByClause = 'ORDER BY ' . implode( ', ', $orderByArray ); 00183 } 00184 00185 $db = eZDB::instance(); 00186 $sql = "SELECT contentclass.* $classNameSqlFilter[nameField] 00187 FROM ezcontentclass contentclass, ezcontentclass_classgroup class_group $classNameSqlFilter[from] 00188 WHERE contentclass.id=class_group.contentclass_id 00189 $versionCond 00190 AND class_group.group_id='$group_id' $classNameSqlFilter[where] 00191 $orderByClause"; 00192 $rows = $db->arrayQuery( $sql ); 00193 return eZPersistentObject::handleRows( $rows, "eZContentClass", $asObject ); 00194 } 00195 00196 static function fetchClassListByGroups( $contentclassVersion, $groupIDList, $asObject = true ) 00197 { 00198 if ( is_array( $groupIDList ) ) 00199 { 00200 $groupIDList = array( $groupIDList ); 00201 } 00202 $classGroupList = eZPersistentObject::fetchObjectList( eZContentClassClassGroup::definition(), 00203 array(), 00204 array( "group_id" => $groupIDList, 00205 "contentclass_version" => $contentclassVersion ), 00206 null, 00207 null, 00208 false, 00209 false, 00210 array( array( 'operation' => "distinct contentclass_id" ) ) ); 00211 $classList = array(); 00212 if ( $asObject ) 00213 { 00214 foreach ( $classGroupList as $classGroup ) 00215 { 00216 $classList[] = eZContentClass::fetch( $classGroup['contentclass_id'] ); 00217 } 00218 } 00219 else 00220 { 00221 foreach ( $classGroupList as $classGroup ) 00222 { 00223 $classList[] = $classGroup['contentclass_id']; 00224 } 00225 } 00226 return $classList; 00227 } 00228 00229 static function fetchGroupList( $contentclass_id, $contentclass_version, $asObject = true ) 00230 { 00231 return eZPersistentObject::fetchObjectList( eZContentClassClassGroup::definition(), 00232 null, 00233 array( "contentclass_id" => $contentclass_id, 00234 "contentclass_version" => $contentclass_version ), 00235 null, 00236 null, 00237 $asObject ); 00238 } 00239 00240 static function classInGroup( $contentclassID, $contentclassVersion, $groupID ) 00241 { 00242 $rows = eZPersistentObject::fetchObjectList( eZContentClassClassGroup::definition(), 00243 null, 00244 array( 'group_id' => $groupID, 00245 "contentclass_id" => $contentclassID, 00246 "contentclass_version" => $contentclassVersion ), 00247 null, 00248 null, 00249 false ); 00250 return count( $rows ) > 0; 00251 } 00252 00253 /// \privatesection 00254 public $ContentClassID; 00255 public $ContentClassVersion; 00256 public $GroupID; 00257 public $GroupName; 00258 } 00259 00260 ?>