| [ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Created on: <17-Apr-2002 10:34:48 bf> 4 // 5 // SOFTWARE NAME: eZ publish 6 // SOFTWARE RELEASE: 3.9.0 7 // BUILD VERSION: 17785 8 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 9 // SOFTWARE LICENSE: GNU General Public License v2.0 10 // NOTICE: > 11 // This program is free software; you can redistribute it and/or 12 // modify it under the terms of version 2.0 of the GNU General 13 // Public License as published by the Free Software Foundation. 14 // 15 // This program is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of version 2.0 of the GNU General 21 // Public License along with this program; if not, write to the Free 22 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 // MA 02110-1301, USA. 24 // 25 // 26 27 include_once ( 'kernel/classes/ezcontentclass.php' ); 28 include_once ( 'kernel/classes/ezcontentclassattribute.php' ); 29 30 include_once ( 'kernel/classes/ezcontentobject.php' ); 31 include_once ( 'kernel/classes/ezcontentobjectversion.php' ); 32 include_once ( 'kernel/classes/ezcontentobjectattribute.php' ); 33 include_once ( 'kernel/classes/ezcontentobjecttreenode.php' ); 34 include_once ( 'kernel/classes/ezcontentbrowse.php' ); 35 36 include_once ( "lib/ezdb/classes/ezdb.php" ); 37 include_once ( 'lib/ezutils/classes/ezhttptool.php' ); 38 39 include_once ( 'kernel/common/template.php' ); 40 41 function checkRelationAssignments( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, &$validation ) 42 { 43 $http =& eZHTTPTool::instance(); 44 // Add object relations 45 if ( $module->isCurrentAction( 'AddRelatedObject' ) ) 46 { 47 $selectedObjectIDArray = eZContentBrowse::result( 'AddRelatedObject' ); 48 $relatedObjects =& $object->relatedContentObjectArray( $editVersion, false, 0, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_COMMON ) ); 49 $relatedObjectIDArray = array(); 50 $objectID = $object->attribute( 'id' ); 51 52 foreach ( $relatedObjects as $relatedObject ) 53 $relatedObjectIDArray[] = $relatedObject->attribute( 'id' ); 54 55 if ( is_array( $selectedObjectIDArray ) ) 56 { 57 $db =& eZDB::instance(); 58 $db->begin(); 59 foreach ( $selectedObjectIDArray as $selectedObjectID ) 60 { 61 if ( $selectedObjectID != $objectID && !in_array( $selectedObjectID, $relatedObjectIDArray ) ) 62 $object->addContentObjectRelation( $selectedObjectID, $editVersion ); 63 } 64 $db->commit(); 65 } 66 67 $module->redirectToView( 'edit', array( $object->attribute( 'id' ), $editVersion, $editLanguage, $fromLanguage ), 68 null, false, 'content-relation-items' ); 69 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 70 } 71 if ( $module->isCurrentAction( 'UploadedFileRelation' ) ) 72 { 73 include_once ( 'kernel/classes/ezcontentupload.php' ); 74 $relatedObjectID = eZContentUpload::result( 'RelatedObjectUpload' ); 75 if ( $relatedObjectID ) 76 { 77 $db =& eZDB::instance(); 78 $db->begin(); 79 $object->addContentObjectRelation( $relatedObjectID, $editVersion ); 80 $db->commit(); 81 } 82 // We redirect to the edit page to get the correct url, 83 // also we use the anchor 'content-relation-items' to make sure the 84 // browser scrolls down the relation list (if the anchor exists). 85 $module->redirectToView( 'edit', array( $object->attribute( 'id' ), $editVersion, $editLanguage, $fromLanguage ), 86 null, false, 'content-relation-items' ); 87 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 88 } 89 } 90 91 function storeRelationAssignments( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage ) 92 { 93 } 94 95 function checkRelationActions( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) 96 { 97 $http =& eZHTTPTool::instance(); 98 if ( $module->isCurrentAction( 'BrowseForObjects' ) ) 99 { 100 $objectID = $object->attribute( 'id' ); 101 102 $assignedNodes =& $object->attribute( 'assigned_nodes' ); 103 $assignedNodesIDs = array(); 104 foreach ( $assignedNodes as $node ) 105 $assignedNodesIDs = $node->attribute( 'node_id' ); 106 unset( $assignedNodes ); 107 108 eZContentBrowse::browse( array( 'action_name' => 'AddRelatedObject', 109 'description_template' => 'design:content/browse_related.tpl', 110 'content' => array( 'object_id' => $objectID, 111 'object_version' => $editVersion, 112 'object_language' => $editLanguage ), 113 'keys' => array( 'class' => $class->attribute( 'id' ), 114 'class_id' => $class->attribute( 'identifier' ), 115 'classgroup' => $class->attribute( 'ingroup_id_list' ), 116 'section' => $object->attribute( 'section_id' ) ), 117 'ignore_nodes_select' => $assignedNodesIDs, 118 'from_page' => $module->redirectionURI( 'content', 'edit', array( $objectID, $editVersion, $editLanguage, $fromLanguage ) ) ), 119 $module ); 120 121 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 122 } 123 if ( $module->isCurrentAction( 'UploadFileRelation' ) ) 124 { 125 $objectID = $object->attribute( 'id' ); 126 127 include_once ( 'kernel/classes/ezsection.php' ); 128 $section = eZSection::fetch( $object->attribute( 'section_id' ) ); 129 $navigationPart = false; 130 if ( $section ) 131 $navigationPart = $section->attribute( 'navigation_part_identifier' ); 132 133 include_once ( 'kernel/classes/ezcontentupload.php' ); 134 $location = false; 135 if ( $module->hasActionParameter( 'UploadRelationLocation' ) ) 136 { 137 $location = $module->actionParameter( 'UploadRelationLocation' ); 138 } 139 140 include_once ( 'lib/ezutils/classes/ezhttpfile.php' ); 141 // We only do direct uploading if we have the uploaded HTTP file 142 // if not we need to go to the content/upload page. 143 if ( eZHTTPFile::canFetch( 'UploadRelationFile' ) ) 144 { 145 $upload = new eZContentUpload(); 146 if ( $upload->handleUpload( $result, 'UploadRelationFile', $location, false ) ) 147 { 148 $relatedObjectID = $result['contentobject_id']; 149 if ( $relatedObjectID ) 150 { 151 $db =& eZDB::instance(); 152 $db->begin(); 153 $object->addContentObjectRelation( $relatedObjectID, $editVersion ); 154 $db->commit(); 155 } 156 } 157 } 158 else 159 { 160 eZContentUpload::upload( array( 'action_name' => 'RelatedObjectUpload', 161 'description_template' => 'design:content/upload_related.tpl', 162 'navigation_part_identifier' => $navigationPart, 163 'content' => array( 'object_id' => $objectID, 164 'object_version' => $editVersion, 165 'object_language' => $editLanguage ), 166 'keys' => array( 'class' => $class->attribute( 'id' ), 167 'class_id' => $class->attribute( 'identifier' ), 168 'classgroup' => $class->attribute( 'ingroup_id_list' ), 169 'section' => $object->attribute( 'section_id' ) ), 170 'result_action_name' => 'UploadedFileRelation', 171 'ui_context' => 'edit', 172 'result_module' => array( 'content', 'edit', 173 array( $objectID, $editVersion, $editLanguage, $fromLanguage ) ) ), 174 $module ); 175 return EZ_MODULE_HOOK_STATUS_CANCEL_RUN; 176 } 177 } 178 if ( $module->isCurrentAction( 'DeleteRelation' ) ) 179 { 180 $objectID = $object->attribute( 'id' ); 181 if ( $http->hasPostVariable( 'DeleteRelationIDArray' ) ) 182 { 183 $relationObjectIDs = $http->postVariable( 'DeleteRelationIDArray' ); 184 } 185 else 186 { 187 $relationObjectIDs = array(); 188 } 189 190 $db =& eZDB::instance(); 191 $db->begin(); 192 foreach ( $relationObjectIDs as $relationObjectID ) 193 { 194 $object->removeContentObjectRelation( $relationObjectID, $editVersion ); 195 } 196 $db->commit(); 197 198 } 199 if ( $module->isCurrentAction( 'NewObject' ) ) 200 { 201 if ( $http->hasPostVariable( 'ClassID' ) ) 202 { 203 include_once ( 'kernel/classes/ezcontentobjectassignmenthandler.php' ); 204 $user =& eZUser::currentUser(); 205 $userID =& $user->attribute( 'contentobject_id' ); 206 if ( $http->hasPostVariable( 'SectionID' ) ) 207 { 208 $sectionID = $http->postVariable( 'SectionID' ); 209 } 210 else 211 { 212 $sectionID = 0; /* Will be changed later */ 213 } 214 $contentClassID = $http->postVariable( 'ClassID' ); 215 $class = eZContentClass::fetch( $contentClassID ); 216 $db =& eZDB::instance(); 217 $db->begin(); 218 $relatedContentObject = $class->instantiate( $userID, $sectionID ); 219 $db->commit(); 220 $newObjectID = $relatedContentObject->attribute( 'id' ); 221 $relatedContentVersion =& $relatedContentObject->attribute( 'current' ); 222 223 if ( $relatedContentObject->attribute( 'can_edit' ) ) 224 { 225 $db =& eZDB::instance(); 226 $db->begin(); 227 $assignmentHandler = new eZContentObjectAssignmentHandler( $relatedContentObject, $relatedContentVersion ); 228 $sectionID = (int) $assignmentHandler->setupAssignments( array( 'group-name' => 'RelationAssignmentSettings', 229 'default-variable-name' => 'DefaultAssignment', 230 'specific-variable-name' => 'ClassSpecificAssignment', 231 'section-id-wanted' => true, 232 'fallback-node-id' => $object->attribute( 'main_node_id' ) ) ); 233 234 $http->setSessionVariable( 'ParentObject', array( $object->attribute( 'id' ), $editVersion, $editLanguage ) ); 235 $http->setSessionVariable( 'NewObjectID', $newObjectID ); 236 237 /* Change section ID to the same one as the main node placement */ 238 $db->query("UPDATE ezcontentobject SET section_id = {$sectionID} WHERE id = {$newObjectID}"); 239 $db->commit(); 240 $module->redirectToView( 'edit', array( $relatedContentObject->attribute( 'id' ), 241 $relatedContentObject->attribute( 'current_version' ), 242 false ) ); 243 } 244 else 245 { 246 $db =& eZDB::instance(); 247 $db->begin(); 248 $relatedContentObject->purge(); 249 $db->commit(); 250 } 251 252 return; 253 } 254 } 255 } 256 257 function handleRelationTemplate( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, &$tpl ) 258 { 259 $relatedObjects =& $object->relatedContentObjectArray( $editVersion ); 260 $tpl->setVariable( 'related_contentobjects', $relatedObjects ); 261 262 $relatedObjectsTyped = array(); 263 $relatedObjectsTyped['common'] =& $object->relatedContentObjectArray( $editVersion, false, 0, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_COMMON ) ); 264 $relatedObjectsTyped['xml_embed'] =& $object->relatedContentObjectArray( $editVersion, false, 0, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_EMBED ) ); 265 if ( eZContentObject::isObjectRelationTyped() ) 266 { 267 $relatedObjectsTyped['xml_link'] =& $object->relatedContentObjectArray( $editVersion, false, 0, array( 'AllRelations' => EZ_CONTENT_OBJECT_RELATION_LINK ) ); 268 } 269 270 $relatedObjectsTypedIDArray = array(); 271 foreach ( $relatedObjectsTyped as $relationTypeName => $relatedObjectsByType ) 272 { 273 $relatedObjectsTypedIDArray[$relationTypeName] = array(); 274 foreach ( $relatedObjectsByType as $relatedObjectByType ) 275 { 276 $relatedObjectsTypedIDArray[$relationTypeName][] = $relatedObjectByType->ID; 277 } 278 } 279 unset( $relatedObjectsTyped ); 280 281 $ini =& eZINI::instance( 'content.ini' ); 282 283 $groups = $ini->variable( 'RelationGroupSettings', 'Groups' ); 284 $defaultGroup = $ini->variable( 'RelationGroupSettings', 'DefaultGroup' ); 285 286 $groupedRelatedObjects = array(); 287 $groupClassLists = array(); 288 $classGroupMap = array(); 289 foreach ( $groups as $groupName ) 290 { 291 $groupedRelatedObjects[$groupName] = array(); 292 $setting = strtoupper( $groupName[0] ) . substr( $groupName, 1 ) . 'ClassList'; 293 $groupClassLists[$groupName] = $ini->variable( 'RelationGroupSettings', $setting ); 294 foreach ( $groupClassLists[$groupName] as $classIdentifier ) 295 { 296 $classGroupMap[$classIdentifier] = $groupName; 297 } 298 } 299 $groupedRelatedObjects[$defaultGroup] = array(); 300 301 foreach ( $relatedObjects as $relatedObjectKey => $relatedObject ) 302 { 303 $classIdentifier = $relatedObject->attribute( 'class_identifier' ); 304 if ( isset( $classGroupMap[$classIdentifier] ) ) 305 { 306 $groupName = $classGroupMap[$classIdentifier]; 307 $groupedRelatedObjects[$groupName][] =& $relatedObjects[$relatedObjectKey]; 308 } 309 else 310 { 311 $groupedRelatedObjects[$defaultGroup][] =& $relatedObjects[$relatedObjectKey]; 312 } 313 } 314 $tpl->setVariable( 'related_contentobjects', $relatedObjects ); 315 $tpl->setVariable( 'related_contentobjects_id', $relatedObjectsTypedIDArray ); 316 $tpl->setVariable( 'grouped_related_contentobjects', $groupedRelatedObjects ); 317 } 318 319 function initializeRelationEdit( &$module ) 320 { 321 $module->addHook( 'post_fetch', 'checkRelationAssignments' ); 322 $module->addHook( 'pre_commit', 'storeRelationAssignments' ); 323 $module->addHook( 'action_check', 'checkRelationActions' ); 324 $module->addHook( 'pre_template', 'handleRelationTemplate' ); 325 } 326 327 ?>
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 |