[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/classes/ -> ezcontentobjecttreenodeoperations.php (source)

   1  <?php
   2  //
   3  // Definition of eZContentObjectTreeNodeOperations class
   4  //
   5  // Created on: <12-Sep-2005 12:02:22 dl>
   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 ezcontentobjecttreenodeoperations.php
  30  */
  31  
  32  /*!
  33    \class eZContentObjectTreeNodeOperations ezcontentobjecttreenodeoperations.php
  34    \brief The class eZContentObjectTreeNodeOperations is a wrapper for node's
  35    core-operations. It takes care about interface stuff.
  36    Example: there is a 'move' core-operation that moves a node from one location
  37    to another. But, for example, before and after moving we have to clear
  38    view caches for old and new placements. Clearing of the cache is handled by
  39    this class.
  40  */
  41  
  42  class eZContentObjectTreeNodeOperations
  43  {
  44      /*!
  45       Constructor
  46      */
  47      function eZContentObjectTreeNodeOperations()
  48      {
  49      }
  50  
  51      /*!
  52       \static
  53       A wrapper for eZContentObjectTreeNode's 'move' operation.
  54       It does:
  55        - clears caches for old placement;
  56        - performs actual move( calls eZContentObjectTreeNode->move() );
  57        - updates subtree path;
  58        - updates node's section;
  59        - updates assignment( setting new 'parent_node' );
  60        - clears caches for new placement;
  61  
  62       \param $nodeID The id of a node to move.
  63       \param $newParentNodeID The id of a new parent.
  64       \return \c true if 'move' was done successfully, otherwise \c false;
  65      */
  66      function move( $nodeID, $newParentNodeID )
  67      {
  68          $result = false;
  69  
  70          if ( !is_numeric( $nodeID ) || !is_numeric( $newParentNodeID ) )
  71              return false;
  72  
  73          include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
  74  
  75          $node = eZContentObjectTreeNode::fetch( $nodeID );
  76          if ( !$node )
  77              return false;
  78  
  79          $object =& $node->object();
  80          if ( !$object )
  81              return false;
  82  
  83          $objectID = $object->attribute( 'id' );
  84          $oldParentNode =& $node->fetchParent();
  85          $oldParentObject =& $oldParentNode->object();
  86  
  87          // clear user policy cache if this was a user object
  88          include_once ( "lib/ezutils/classes/ezini.php" );
  89          $ini =& eZINI::instance();
  90          $userClassID = $ini->variable( "UserSettings", "UserClassID" );
  91          if ( $object->attribute( 'contentclass_id' ) == $userClassID )
  92          {
  93              include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
  94              eZUser::cleanupCache();
  95          }
  96  
  97          // clear cache for old placement.
  98          include_once ( 'kernel/classes/ezcontentcachemanager.php' );
  99          eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
 100  
 101          include_once ( "lib/ezdb/classes/ezdb.php" );
 102          $db =& eZDB::instance();
 103          $db->begin();
 104  
 105          $node->move( $newParentNodeID );
 106  
 107          $newNode = eZContentObjectTreeNode::fetchNode( $objectID, $newParentNodeID );
 108  
 109          if ( $newNode )
 110          {
 111              $newNode->updateSubTreePath();
 112              if ( $newNode->attribute( 'main_node_id' ) == $newNode->attribute( 'node_id' ) )
 113              {
 114                  // If the main node is moved we need to check if the section ID must change
 115                  $newParentNode =& $newNode->fetchParent();
 116                  $newParentObject =& $newParentNode->object();
 117                  if ( $object->attribute( 'section_id' ) != $newParentObject->attribute( 'section_id' ) )
 118                  {
 119  
 120                      eZContentObjectTreeNode::assignSectionToSubTree( $newNode->attribute( 'main_node_id' ),
 121                                                                       $newParentObject->attribute( 'section_id' ),
 122                                                                       $oldParentObject->attribute( 'section_id' ) );
 123                  }
 124              }
 125  
 126              // modify assignment
 127              include_once ( "kernel/classes/eznodeassignment.php" );
 128              $curVersion     =& $object->attribute( 'current_version' );
 129              $nodeAssignment = eZNodeAssignment::fetch( $objectID, $curVersion, $oldParentNode->attribute( 'node_id' ) );
 130  
 131              if ( $nodeAssignment )
 132              {
 133                  $nodeAssignment->setAttribute( 'parent_node', $newParentNodeID );
 134                  $nodeAssignment->setAttribute( 'op_code', EZ_NODE_ASSIGNMENT_OP_CODE_MOVE );
 135                  $nodeAssignment->store();
 136              }
 137  
 138              $result = true;
 139          }
 140  
 141          $db->commit();
 142  
 143          // clear cache for new placement.
 144          eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
 145  
 146          return $result;
 147      }
 148  }
 149  
 150  
 151  ?>


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