eZ Publish  [trunk]
section_edit.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00004  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00005  * @version //autogentag//
00006  * @package kernel
00007  */
00008 
00009 function sectionEditPostFetch( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, &$validation )
00010 {
00011 }
00012 
00013 function sectionEditPreCommit( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage )
00014 {
00015 }
00016 
00017 function sectionEditActionCheck( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
00018 {
00019     if ( $module->isCurrentAction( 'SectionEdit' ) )
00020     {
00021         $http = eZHTTPTool::instance();
00022         if ( $http->hasPostVariable( 'SelectedSectionId' ) )
00023         {
00024             $selectedSectionID = (int) $http->postVariable( 'SelectedSectionId' );
00025             $selectedSection = eZSection::fetch( $selectedSectionID );
00026             if ( is_object( $selectedSection ) )
00027             {
00028                 $currentUser = eZUser::currentUser();
00029                 if ( $currentUser->canAssignSectionToObject( $selectedSectionID, $object ) )
00030                 {
00031                     $db = eZDB::instance();
00032                     $db->begin();
00033                     $assignedNodes = $object->attribute( 'assigned_nodes' );
00034                     if ( count( $assignedNodes ) > 0 )
00035                     {
00036                         foreach ( $assignedNodes as $node )
00037                         {
00038                             if ( eZOperationHandler::operationIsAvailable( 'content_updatesection' ) )
00039                             {
00040                                 $operationResult = eZOperationHandler::execute( 'content',
00041                                                                                 'updatesection',
00042                                                                                 array( 'node_id'             => $node->attribute( 'node_id' ),
00043                                                                                        'selected_section_id' => $selectedSectionID ),
00044                                                                                 null,
00045                                                                                 true );
00046 
00047                             }
00048                             else
00049                             {
00050                                 eZContentOperationCollection::updateSection( $node->attribute( 'node_id' ), $selectedSectionID );
00051                             }
00052                         }
00053                     }
00054                     else
00055                     {
00056                         // If there are no assigned nodes we should update db for the current object.
00057                         $objectID = $object->attribute( 'id' );
00058                         $db->query( "UPDATE ezcontentobject SET section_id='$selectedSectionID' WHERE id = '$objectID'" );
00059                         $db->query( "UPDATE ezsearch_object_word_link SET section_id='$selectedSectionID' WHERE  contentobject_id = '$objectID'" );
00060                     }
00061                     $object->expireAllViewCache();
00062                     $db->commit();
00063                 }
00064                 else
00065                 {
00066                     eZDebug::writeError( "You do not have permissions to assign the section <" . $selectedSection->attribute( 'name' ) .
00067                                          "> to the object <" . $object->attribute( 'name' ) . ">." );
00068                 }
00069                 $module->redirectToView( 'edit', array( $object->attribute( 'id' ), $editVersion, $editLanguage, $fromLanguage ) );
00070             }
00071         }
00072     }
00073 }
00074 
00075 function sectionEditPreTemplate( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $tpl )
00076 {
00077 }
00078 
00079 function initializeSectionEdit( $module )
00080 {
00081     $module->addHook( 'post_fetch', 'sectionEditPostFetch' );
00082     $module->addHook( 'pre_commit', 'sectionEditPreCommit' );
00083     $module->addHook( 'action_check', 'sectionEditActionCheck' );
00084     $module->addHook( 'pre_template', 'sectionEditPreTemplate' );
00085 }
00086 
00087 ?>