[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/content/ -> removeassignment.php (source)

   1  <?php
   2  //
   3  //
   4  // Created on: <19-Oct-2004 18:03:49 vs>
   5  //
   6  // SOFTWARE NAME: eZ publish
   7  // SOFTWARE RELEASE: 3.9.0
   8  // BUILD VERSION: 17785
   9  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  10  // SOFTWARE LICENSE: GNU General Public License v2.0
  11  // NOTICE: >
  12  //   This program is free software; you can redistribute it and/or
  13  //   modify it under the terms of version 2.0  of the GNU General
  14  //   Public License as published by the Free Software Foundation.
  15  //
  16  //   This program is distributed in the hope that it will be useful,
  17  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  //   GNU General Public License for more details.
  20  //
  21  //   You should have received a copy of version 2.0 of the GNU General
  22  //   Public License along with this program; if not, write to the Free
  23  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24  //   MA 02110-1301, USA.
  25  //
  26  //
  27  
  28  include_once ( "lib/ezdb/classes/ezdb.php" );
  29  include_once ( "lib/ezutils/classes/ezhttptool.php" );
  30  include_once ( "kernel/common/template.php" );
  31  
  32  $module =& $Params["Module"];
  33  $http   =& eZHTTPTool::instance();
  34  
  35  if ( $http->hasSessionVariable( 'AssignmentRemoveData' ) )
  36  {
  37      $data = $http->sessionVariable( 'AssignmentRemoveData' );
  38      $removeList   = $data['remove_list'];
  39      $objectID     = $data['object_id'];
  40      $editVersion  = $data['edit_version'];
  41      $editLanguage = $data['edit_language'];
  42      $fromLanguage = $data['from_language'];
  43  
  44      $object =& eZContentObject::fetch( $objectID );
  45      if ( !$object )
  46          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
  47      if ( !$object->checkAccess( 'edit' ) )
  48          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
  49      unset( $object );
  50  }
  51  else
  52  {
  53      eZDebug::writeError( "No assignments passed to content/removeassignment" );
  54      return $module->redirectToView( 'view', array( 'full', 2 ) );
  55  }
  56  
  57  // process current action
  58  if ( $module->isCurrentAction( 'ConfirmRemoval' ) )
  59  {
  60      $http->removeSessionVariable( 'AssignmentRemoveData' );
  61  
  62      $assignments     = eZnodeAssignment::fetchListByID( $removeList );
  63      $mainNodeChanged = false;
  64  
  65      $db =& eZDB::instance();
  66      $db->begin();
  67      foreach ( $assignments as $assignment )
  68      {
  69          $assignmentID = $assignment->attribute( 'id' );
  70          if ( $assignment->attribute( 'is_main' ) )
  71              $mainNodeChanged = true;
  72          eZNodeAssignment::purgeByID( $assignmentID );
  73      }
  74      if ( $mainNodeChanged )
  75          eZNodeAssignment::setNewMainAssignment( $objectID, $editVersion );
  76  
  77      $db->commit();
  78  
  79      return $module->redirectToView( 'edit', array( $objectID, $editVersion, $editLanguage, $fromLanguage ) );
  80  }
  81  else if ( $module->isCurrentAction( 'CancelRemoval' ) )
  82  {
  83      $http->removeSessionVariable( 'AssignmentRemoveData' );
  84  
  85      return $module->redirectToView( 'edit', array( $objectID, $editVersion, $editLanguage, $fromLanguage ) );
  86  }
  87  
  88  // default action: show the confirmation dialog
  89  $assignmentsToRemove = eZNodeAssignment::fetchListByID( $removeList );
  90  $removeList = array();
  91  $canRemoveAll = true;
  92  foreach ( $assignmentsToRemove as $assignment )
  93  {
  94      $node =& $assignment->attribute( 'node' );
  95  
  96      // skip assignments which don't have associated node or node with no children
  97      if ( !$node )
  98          continue;
  99      $count = $node->subTreeCount( array( 'Limitation' => array() ) );
 100      if ( $count < 1 )
 101          continue;
 102  
 103      // Find the number of items in the subtree we are allowed to remove
 104      // if this differs from the total count it means we have items we cannot remove
 105      // We do this by fetching the limitation list for content/remove
 106      // and passing it to the subtre count function.
 107      include_once ( "kernel/classes/datatypes/ezuser/ezuser.php" );
 108      $currentUser =& eZUser::currentUser();
 109      $accessResult = $currentUser->hasAccessTo( 'content', 'remove' );
 110      $canRemoveSubtree = true;
 111      if ( $accessResult['accessWord'] == 'limited' )
 112      {
 113          $limitationList =& $accessResult['policies'];
 114          $removeableChildCount = $node->subTreeCount( array( 'Limitation' => $limitationList ) );
 115          $canRemoveSubtree = ( $removeableChildCount == $count );
 116      }
 117      if ( !$canRemoveSubtree )
 118          $canRemoveAll = false;
 119      $object =& $node->object();
 120      $class =& $object->contentClass();
 121  
 122      $removeList[] = array( 'node' => $node,
 123                             'object' => $object,
 124                             'class' => $class,
 125                             'count' => $count,
 126                             'can_remove' => $canRemoveSubtree,
 127                             'child_count' => $count );
 128  }
 129  unset( $assignmentsToRemove );
 130  
 131  $assignmentData = array( 'object_id'      => $objectID,
 132                           'object_version' => $editVersion,
 133                           'remove_list'    => $removeList );
 134  $info = array( 'can_remove_all' => $canRemoveAll );
 135  
 136  $tpl =& templateInit();
 137  $tpl->setVariable( 'assignment_data', $assignmentData );
 138  $tpl->setVariable( 'remove_info', $info );
 139  
 140  $Result = array();
 141  $Result['content'] =& $tpl->fetch( "design:content/removeassignment.tpl" );
 142  $Result['path'] = array( array( 'url' => false,
 143                                  'text' => ezi18n( 'kernel/content', 'Remove location' ) ) );
 144  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7