[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   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  
  35  include_once ( "lib/ezdb/classes/ezdb.php" );
  36  include_once ( 'lib/ezutils/classes/ezhttptool.php' );
  37  
  38  include_once ( 'kernel/common/template.php' );
  39  
  40  include_once ( 'kernel/classes/ezpreferences.php' );
  41  
  42  
  43  function checkNodeAssignments( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, $FromLanguage, &$validation )
  44  {
  45      $http =& eZHTTPTool::instance();
  46  
  47      // If the object has been previously published we do not allow node assignment operations
  48      if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_DRAFT )
  49      {
  50          if ( !$module->isCurrentAction( 'AddPrimaryNodeAssignment' ) )
  51          {
  52              return;
  53          }
  54      }
  55  
  56      // If node assignment handling is diabled we return immedieately
  57      $useNodeAssigments = true;
  58      if ( $http->hasPostVariable( 'UseNodeAssigments' ) )
  59          $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' );
  60  
  61      if ( !$useNodeAssigments )
  62          return;
  63  
  64      $ObjectID = $object->attribute( 'id' );
  65      // Assign to nodes
  66      if ( $module->isCurrentAction( 'AddNodeAssignment' ) ||
  67           $module->isCurrentAction( 'AddPrimaryNodeAssignment' ) )
  68      {
  69          $selectedNodeIDArray = eZContentBrowse::result( 'AddNodeAssignment' );
  70          $assignedNodes =& $version->nodeAssignments();
  71          $assignedIDArray = array();
  72          $setMainNode = false;
  73          $hasMainNode = false;
  74          foreach ( $assignedNodes as $assignedNode )
  75          {
  76              $assignedNodeID = $assignedNode->attribute( 'parent_node' );
  77              if ( $assignedNode->attribute( 'is_main' ) )
  78                  $hasMainNode = true;
  79              $assignedIDArray[] = $assignedNodeID;
  80          }
  81          if ( !$hasMainNode )
  82              $setMainNode = true;
  83  
  84          // prevent PHP warning
  85          if ( !isset( $selectedNodeIDArray ) || !is_array( $selectedNodeIDArray ) )
  86               $selectedNodeIDArray = array();
  87  
  88          foreach ( $selectedNodeIDArray as $nodeID )
  89          {
  90              if ( !in_array( $nodeID, $assignedIDArray ) )
  91              {
  92                  $isPermitted = true;
  93                  // Check access
  94                  $newNode = eZContentObjectTreeNode::fetch( $nodeID );
  95                  $newNodeObject = $newNode->attribute( 'object' );
  96  
  97                  $canCreate = $newNodeObject->checkAccess( 'create', $class->attribute( 'id' ), $newNodeObject->attribute( 'contentclass_id' ) ) == 1;
  98                  if ( !$canCreate )
  99                      $isPermitted = false;
 100                  else
 101                  {
 102                      $canCreateClassList = $newNodeObject->attribute( 'can_create_class_list' );
 103                      $objectClassID = $object->attribute( 'contentclass_id' );
 104                      $canCreateClassIDList = array();
 105                      foreach ( array_keys( $canCreateClassList ) as $key )
 106                      {
 107                          $canCreateClassIDList[] = $canCreateClassList[$key]['id'];
 108                      }
 109                      if ( !in_array( $objectClassID, $canCreateClassIDList ) )
 110                          $isPermitted = false;
 111                  }
 112                  if ( !$isPermitted )
 113                  {
 114                      eZDebug::writeError( $newNode->attribute( 'path_identification_string' ), "You are not allowed to place this object under:" );
 115                      $validation[ 'placement' ][] = array( 'text' => ezi18n( 'kernel/content', 'You are not allowed to place this object under: %1', null, array( $newNode->attribute( 'path_identification_string' ) ) ) );
 116                      $validation[ 'processed' ] = true;
 117                      // Error message.
 118                  }
 119                  else
 120                  {
 121                      $isMain = 0;
 122                      if ( $setMainNode )
 123                          $isMain = 1;
 124                      $setMainNode = false;
 125                      $db =& eZDB::instance();
 126                      $db->begin();
 127                      $version->assignToNode( $nodeID, $isMain );
 128                      $db->commit();
 129                  }
 130              }
 131          }
 132      }
 133  }
 134  
 135  function checkNodeMovements( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, $FromLanguage, &$validation )
 136  {
 137      $http =& eZHTTPTool::instance();
 138  
 139      // If the object has been previously published we do not allow node assignment operations
 140      if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_DRAFT )
 141      {
 142          return;
 143      }
 144  
 145      // If node assignment handling is diabled we return immedieately
 146      $useNodeAssigments = true;
 147      if ( $http->hasPostVariable( 'UseNodeAssigments' ) )
 148          $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' );
 149  
 150      if ( !$useNodeAssigments )
 151          return;
 152  
 153      $ObjectID = $object->attribute( 'id' );
 154      // Move to another node
 155      if ( $module->isCurrentAction( 'MoveNodeAssignment' ) )
 156      {
 157          $selectedNodeIDArray = eZContentBrowse::result( 'MoveNodeAssignment' );
 158          $fromNodeID = $http->postVariable( "FromNodeID" );
 159          $oldAssignmentParentID = $http->postVariable( 'OldAssignmentParentID' );
 160  
 161          if ( $selectedNodeIDArray != null )
 162          {
 163              $assignedNodes =& $version->nodeAssignments();
 164              $assignedIDArray = array();
 165              foreach ( $assignedNodes as  $assignedNode )
 166              {
 167                  $assignedNodeID = $assignedNode->attribute( 'parent_node' );
 168                  $assignedIDArray[] = $assignedNodeID;
 169              }
 170              foreach ( $selectedNodeIDArray as $nodeID )
 171              {
 172                  if ( !in_array( $nodeID, $assignedIDArray ) )
 173                  {
 174                      $isPermitted = true;
 175                      // Check access
 176                      $newNode = eZContentObjectTreeNode::fetch( $nodeID );
 177                      $newNodeObject = $newNode->attribute( 'object' );
 178  
 179  //                     $canCreate = $newNodeObject->attribute( 'can_create' );
 180                      $canCreate = $newNodeObject->checkAccess( 'create', $class->attribute( 'id' ), $newNodeObject->attribute( 'contentclass_id' ) ) == 1;
 181                      eZDebug::writeDebug( $canCreate,"can create");
 182                      if ( !$canCreate )
 183                          $isPermitted = false;
 184                      else
 185                      {
 186                          $canCreateClassList = $newNodeObject->attribute( 'can_create_class_list' );
 187                          $canCreateClassIDList = array();
 188                          foreach ( array_keys( $canCreateClassList ) as $key )
 189                          {
 190                              $canCreateClassIDList[] = $canCreateClassList[$key]['id'];
 191                          }
 192                          $objectClassID = $object->attribute( 'contentclass_id' );
 193                          if ( !in_array( $objectClassID, $canCreateClassIDList ) )
 194                               $isPermitted = false;
 195                      }
 196                      if ( !$isPermitted )
 197                      {
 198                          eZDebug::writeError( $newNode->attribute( 'path_identification_string' ), "You are not allowed to place this object under:" );
 199                          $validation[ 'placement' ][] = array( 'text' => ezi18n( 'kernel/content', "You are not allowed to place this object under: %1", null, array( $newNode->attribute( 'path_identification_string' ) ) ) );
 200                          $validation[ 'processed' ] = true;
 201                          // Error message.
 202                      }
 203                      else
 204                      {
 205                          $oldAssignment = eZPersistentObject::fetchObject( eZNodeAssignment::definition(),
 206                                                                             null,
 207                                                                             array( 'contentobject_id' => $object->attribute( 'id' ),
 208                                                                                    'parent_node' => $oldAssignmentParentID,
 209                                                                                    'contentobject_version' => $version->attribute( 'version' )
 210                                                                                    ),
 211                                                                             true );
 212  
 213                          $realNode = eZContentObjectTreeNode::fetchNode( $version->attribute( 'contentobject_id' ), $oldAssignment->attribute( 'parent_node' ) );
 214  
 215                          $db =& eZDB::instance();
 216                          $db->begin();
 217                          // No longer remove then add assignment, instead change the existing one
 218                          if ( is_null( $realNode ) )
 219                          {
 220                              $fromNodeID = 0;
 221                          }
 222                          if ( $oldAssignment->attribute( 'is_main' ) == '1' )
 223                          {
 224                              $oldAssignment->setAttribute( 'parent_node', $nodeID );
 225                              $oldAssignment->setAttribute( 'is_main', 1 );
 226                              $oldAssignment->setAttribute( 'from_node_id', $fromNodeID );
 227  //                            $version->assignToNode( $nodeID, 1, $fromNodeID, $oldAssignment->attribute( 'sort_field' ), $oldAssignment->attribute( 'sort_order' ) );
 228                          }
 229                          else
 230                          {
 231                              $oldAssignment->setAttribute( 'parent_node', $nodeID );
 232                              $oldAssignment->setAttribute( 'is_main', 0 );
 233                              $oldAssignment->setAttribute( 'from_node_id', $fromNodeID );
 234  //                            $version->assignToNode( $nodeID, 0, $fromNodeID, $oldAssignment->attribute( 'sort_field' ), $oldAssignment->attribute( 'sort_order' ) );
 235                          }
 236                          $oldAssignment->setAttribute( 'op_code', EZ_NODE_ASSIGNMENT_OP_CODE_MOVE );
 237                          $oldAssignment->store();
 238                          //$version->removeAssignment( $oldAssignmentParentID );
 239                          $db->commit();
 240                      }
 241                  }
 242              }
 243          }
 244      }
 245  }
 246  
 247  function storeNodeAssignments( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage )
 248  {
 249      $http =& eZHTTPTool::instance();
 250  
 251      // If the object has been previously published we do not allow node assignment operations
 252      if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_DRAFT )
 253      {
 254          return;
 255      }
 256  
 257      // If node assignment handling is diabled we return immedieately
 258      $useNodeAssigments = true;
 259      if ( $http->hasPostVariable( 'UseNodeAssigments' ) )
 260          $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' );
 261  
 262      if ( !$useNodeAssigments )
 263          return;
 264  
 265      $setPlacementNodeIDArray = array();
 266      if ( $http->hasPostVariable( 'SetPlacementNodeIDArray' ) )
 267          $setPlacementNodeIDArray = $http->postVariable( 'SetPlacementNodeIDArray' );
 268  
 269      // We will quit if some important POST variables are missing
 270      if ( !$http->hasPostVariable( 'MainNodeID' ) and
 271           !$http->hasPostVariable( 'SortOrderMap' ) and
 272           !$http->hasPostVariable( 'SortFieldMap' ) )
 273          return;
 274  
 275      $mainNodeID = false;
 276      if ( $http->hasPostVariable( 'MainNodeID' ) )
 277      {
 278          $mainNodeID = trim( $http->postVariable( 'MainNodeID' ) );
 279          if ( strlen( $mainNodeID ) == 0 )
 280              return;
 281      }
 282  
 283      // Check if dropdown placement is used
 284      if ( $http->hasPostVariable( 'MainAssignmentElementNumber' ) )
 285      {
 286          $elementNumber = $http->postVariable( 'MainAssignmentElementNumber' );
 287  
 288          $mainNodeID = $setPlacementNodeIDArray[$elementNumber];
 289      }
 290  
 291      $nodesID = array();
 292      if ( $http->hasPostVariable( 'NodesID' ) )
 293          $nodesID = $http->postVariable( 'NodesID' );
 294  
 295      $nodeID = eZContentObjectTreeNode::findNode( $mainNodeID, $object->attribute('id') );
 296      eZDebugSetting::writeDebug( 'kernel-content-edit', $nodeID, 'nodeID' );
 297  //    $object->setAttribute( 'main_node_id', $nodeID );
 298      $nodeAssignments = eZNodeAssignment::fetchForObject( $object->attribute( 'id' ), $version->attribute( 'version' ) ) ;
 299      eZDebugSetting::writeDebug( 'kernel-content-edit', $mainNodeID, "mainNodeID" );
 300  
 301  
 302      $setPlacementNodeIDArray = array_unique( $setPlacementNodeIDArray );
 303      eZDebugSetting::writeDebug( 'kernel-content-edit', $setPlacementNodeIDArray, '$setPlacementNodeIDArray' );
 304      $remoteIDFieldMap = array();
 305      if ( $http->hasPostVariable( 'SetRemoteIDFieldMap' ) )
 306          $remoteIDFieldMap = $http->postVariable( 'SetRemoteIDFieldMap' );
 307      $remoteIDOrderMap = array();
 308      if ( $http->hasPostVariable( 'SetRemoteIDOrderMap' ) )
 309          $remoteIDOrderMap = $http->postVariable( 'SetRemoteIDOrderMap' );
 310  
 311      $db =& eZDB::instance();
 312      $db->begin();
 313      if ( count( $setPlacementNodeIDArray ) > 0 )
 314      {
 315          foreach ( $setPlacementNodeIDArray as $setPlacementRemoteID => $setPlacementNodeID )
 316          {
 317              $hasAssignment = false;
 318              foreach ( array_keys( $nodeAssignments ) as $key )
 319              {
 320                  $nodeAssignment =& $nodeAssignments[$key];
 321                  if ( $nodeAssignment->attribute( 'remote_id' ) == $setPlacementRemoteID )
 322                  {
 323                      eZDebugSetting::writeDebug( 'kernel-content-edit', "Remote ID $setPlacementRemoteID already in use for node " . $nodeAssignment->attribute( 'parent_node' ), 'node_edit' );
 324                      if ( isset( $remoteIDFieldMap[$setPlacementRemoteID] ) )
 325                          $nodeAssignment->setAttribute( 'sort_field',  $remoteIDFieldMap[$setPlacementRemoteID] );
 326                      if ( isset( $remoteIDOrderMap[$setPlacementRemoteID] ) )
 327                          $nodeAssignment->setAttribute( 'sort_order', $remoteIDOrderMap[$setPlacementRemoteID] );
 328                      $nodeAssignment->setAttribute( 'parent_node', $setPlacementNodeID );
 329                      $nodeAssignment->sync();
 330                      $hasAssignment = true;
 331                      break;
 332                  }
 333              }
 334              if ( !$hasAssignment )
 335              {
 336                  eZDebugSetting::writeDebug( 'kernel-content-edit', "Adding to node $setPlacementNodeID", 'node_edit' );
 337                  $sortField = null;
 338                  $sortOrder = null;
 339                  if ( isset( $remoteIDFieldMap[$setPlacementRemoteID] ) )
 340                      $sortField = $remoteIDFieldMap[$setPlacementRemoteID];
 341                  if ( isset( $remoteIDOrderMap[$setPlacementRemoteID] ) )
 342                      $sortOrder = $remoteIDOrderMap[$setPlacementRemoteID];
 343                  $version->assignToNode( $setPlacementNodeID, 0, 0, $sortField, $sortOrder, $setPlacementRemoteID );
 344              }
 345          }
 346          $nodeAssignments = eZNodeAssignment::fetchForObject( $object->attribute( 'id' ), $version->attribute( 'version' ) );
 347      }
 348  
 349      $sortOrderMap = false;
 350      if ( $http->hasPostVariable( 'SortOrderMap' ) )
 351          $sortOrderMap = $http->postVariable( 'SortOrderMap' );
 352      $sortFieldMap = false;
 353      if ( $http->hasPostVariable( 'SortFieldMap' ) )
 354          $sortFieldMap = $http->postVariable( 'SortFieldMap' );
 355  
 356  //     $assigedNodes = eZContentObjectTreeNode::fetchByContentObjectID( $object->attribute('id') );
 357      foreach ( array_keys( $nodeAssignments ) as $key )
 358      {
 359          $nodeAssignment =& $nodeAssignments[$key];
 360          eZDebugSetting::writeDebug( 'kernel-content-edit', $nodeAssignment, "nodeAssignment" );
 361          if ( $sortFieldMap !== false )
 362          {
 363              if ( isset( $sortFieldMap[$nodeAssignment->attribute( 'id' )] ) )
 364                  $nodeAssignment->setAttribute( 'sort_field', $sortFieldMap[$nodeAssignment->attribute( 'id' )] );
 365          }
 366  
 367          if ( $sortOrderMap !== false )
 368          {
 369              $sortOrder = 1;
 370              if ( isset( $sortOrderMap[$nodeAssignment->attribute( 'id' )] ) and
 371                   $sortOrderMap[$nodeAssignment->attribute( 'id' )] == 1 )
 372                  $sortOrder = $sortOrderMap[$nodeAssignment->attribute( 'id' )];
 373              else
 374                  $sortOrder = 0;
 375  
 376              $nodeAssignment->setAttribute( 'sort_order', $sortOrder );
 377          }
 378  
 379  
 380          if ( $nodeAssignment->attribute( 'is_main' ) == 1 and
 381               $nodeAssignment->attribute( 'parent_node' ) != $mainNodeID )
 382          {
 383              $nodeAssignment->setAttribute( 'is_main', 0 );
 384          }
 385          else if ( $nodeAssignment->attribute( 'is_main' ) == 0 and
 386                    $nodeAssignment->attribute( 'parent_node' ) == $mainNodeID )
 387          {
 388              $nodeAssignment->setAttribute( 'is_main', 1 );
 389          }
 390          $nodeAssignment->store();
 391      }
 392      $db->commit();
 393  }
 394  
 395  function checkNodeActions( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
 396  {
 397      // If the object has been previously published we do not allow node assignment operations
 398      if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_DRAFT )
 399      {
 400          if ( !$module->isCurrentAction( 'BrowseForPrimaryNodes' ) )
 401          {
 402              return;
 403          }
 404      }
 405  
 406      $http =& eZHTTPTool::instance();
 407  
 408      if ( $module->isCurrentAction( 'BrowseForNodes' ) ||
 409           $module->isCurrentAction( 'BrowseForPrimaryNodes' ) )
 410      {
 411          // Remove custom actions from attribute editing.
 412          $http->removeSessionVariable( 'BrowseCustomAction' );
 413  
 414          $ignoreNodesSelect = array();
 415          $ignoreNodesClick  = array();
 416          $assigned = $version->nodeAssignments();
 417          $publishedAssigned =& $object->assignedNodes( false );
 418          $isTopLevel = false;
 419          foreach ( $publishedAssigned as $element )
 420          {
 421              $append = false;
 422              if ( $element['parent_node_id'] == 1 )
 423                  $isTopLevel = true;
 424              foreach ( $assigned as $ass )
 425              {
 426                  if ( $ass->attribute( 'parent_node' ) == $element['parent_node_id'] )
 427                      $append = true;
 428              }
 429  
 430              /* If the current version (draft) has no assigned nodes then
 431               * we should disallow adding assignments under nodes
 432               * the previous published version is assignned to.
 433               * Thus we avoid fatal errors in eZ Publish.
 434               */
 435              if ( count($assigned) == 0 )
 436              {
 437                  $ignoreNodesSelect[] = $element['node_id'];
 438                  $ignoreNodesClick[]  = $element['node_id'];
 439              }
 440  
 441              if ( $append )
 442              {
 443                  $ignoreNodesSelect[] = $element['node_id'];
 444                  $ignoreNodesClick[]  = $element['node_id'];
 445                  $ignoreNodesSelect[] = $element['parent_node_id'];
 446              }
 447          }
 448          if ( !$isTopLevel )
 449          {
 450              $ignoreNodesSelect = array_unique( $ignoreNodesSelect );
 451              $objectID = $object->attribute( 'id' );
 452              $action = 'AddNodeAssignment';
 453              if ( $module->isCurrentAction( 'BrowseForPrimaryNodes' ) )
 454              {
 455                  $action = 'AddPrimaryNodeAssignment';
 456              }
 457              eZContentBrowse::browse( array( 'action_name' => $action,
 458                                              'description_template' => 'design:content/browse_placement.tpl',
 459                                              'keys' => array( 'class' => $class->attribute( 'id' ),
 460                                                               'class_id' => $class->attribute( 'identifier' ),
 461                                                               'classgroup' => $class->attribute( 'ingroup_id_list' ),
 462                                                               'section' => $object->attribute( 'section_id' ) ),
 463                                              'ignore_nodes_select' => $ignoreNodesSelect,
 464                                              'ignore_nodes_click'  => $ignoreNodesClick,
 465                                              'content' => array( 'object_id' => $objectID,
 466                                                                  'object_version' => $editVersion,
 467                                                                  'object_language' => $editLanguage ),
 468                                              'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage/$fromLanguage" ),
 469                                       $module );
 470  
 471              return EZ_MODULE_HOOK_STATUS_CANCEL_RUN;
 472          }
 473      }
 474  
 475      // If node assignment handling is diabled we return
 476      $useNodeAssigments = true;
 477      if ( $http->hasPostVariable( 'UseNodeAssigments' ) )
 478          $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' );
 479  
 480      if ( !$useNodeAssigments )
 481          return;
 482  
 483      // Remove custom actions from attribute editing.
 484      $http->removeSessionVariable( 'BrowseCustomAction' );
 485  
 486      if ( $module->isCurrentAction( 'ConfirmAssignmentDelete' ) && $http->hasPostVariable( 'RemoveNodeID' ) )
 487      {
 488          $nodeID = $http->postVariable( 'RemoveNodeID' );
 489          $db =& eZDB::instance();
 490          $db->begin();
 491          $version->removeAssignment( $nodeID );
 492          $db->commit();
 493      }
 494  
 495      if ( $module->isCurrentAction( 'DeleteNode' ) )
 496      {
 497  
 498          if ( $http->hasPostVariable( 'RemoveNodeID' ) )
 499          {
 500              $nodeID = $http->postVariable( 'RemoveNodeID' );
 501          }
 502  
 503          $mainNodeID = $http->postVariable( 'MainNodeID' );
 504  
 505  //         if ( $nodeID != $mainNodeID )
 506          {
 507              $objectID = $object->attribute( 'id' );
 508              $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeID );
 509              if ( $publishedNode != null )
 510              {
 511                  $publishParentNodeID = $publishedNode->attribute( 'parent_node_id' );
 512                  if ( $publishParentNodeID > 1 )
 513                  {
 514                      $childrenCount =& $publishedNode->childrenCount();
 515                      if ( $childrenCount != 0 )
 516                      {
 517                          $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) );
 518                          return EZ_MODULE_HOOK_STATUS_CANCEL_RUN;
 519                      }
 520                      else
 521                      {
 522                          $db =& eZDB::instance();
 523                          $db->begin();
 524                          $version->removeAssignment( $nodeID );
 525                          $db->commit();
 526                      }
 527                  }
 528              }
 529              else
 530              {
 531                  $nodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $nodeID );
 532                  if ( $nodeAssignment->attribute( 'from_node_id' ) != 0 )
 533                  {
 534                      $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeAssignment->attribute( 'from_node_id' ) );
 535                      $childrenCount = 0;
 536                      if ( $publishedNode !== null )
 537                          $childrenCount =& $publishedNode->childrenCount();
 538                      if ( $childrenCount != 0 )
 539                      {
 540                          $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) );
 541                          return EZ_MODULE_HOOK_STATUS_CANCEL_RUN;
 542                      }
 543                  }
 544                  $db =& eZDB::instance();
 545                  $db->begin();
 546                  $version->removeAssignment( $nodeID );
 547                  $db->commit();
 548              }
 549          }
 550      }
 551  
 552      if ( $module->isCurrentAction( 'RemoveAssignments' ) )
 553      {
 554          if( $http->hasPostVariable( 'AssignmentIDSelection' ) )
 555          {
 556              $selected       = $http->postVariable( 'AssignmentIDSelection' );
 557              $objectID       = $object->attribute( 'id' );
 558              $versionInt     = $version->attribute( 'version' );
 559              $hasChildren    = false;
 560              $assignmentsIDs = array();
 561              $assignments    = array();
 562  
 563              // Determine if at least one node of ones we remove assignments for has children.
 564              foreach ( $selected as $parentNodeID )
 565              {
 566                  $assignment = eZNodeAssignment::fetch( $objectID, $versionInt, $parentNodeID );
 567                  if( !$assignment )
 568                  {
 569                      eZDebug::writeWarning( "No assignment found for object $objectID version $versionInt, parent node $parentNodeID" );
 570                      continue;
 571                  }
 572  
 573                  $assignmentID     =  $assignment->attribute( 'id' );
 574                  $assignmentsIDs[] =  $assignmentID;
 575                  $assignments[]    =& $assignment;
 576                  $node             =& $assignment->attribute( 'node' );
 577  
 578                  if( !$node )
 579                      continue;
 580  
 581                  if( $node->childrenCount( false ) > 0 )
 582                      $hasChildren = true;
 583  
 584                  unset( $assignment );
 585              }
 586  
 587              if ( $hasChildren )
 588              {
 589                  // We need user confirmation if at least one node we want to remove assignment for contains children.
 590                  // Aactual removal is done in content/removeassignment in this case.
 591                  $http->setSessionVariable( 'AssignmentRemoveData',
 592                                             array( 'remove_list'   => $assignmentsIDs,
 593                                                    'object_id'     => $objectID,
 594                                                    'edit_version'  => $versionInt,
 595                                                    'edit_language' => $editLanguage,
 596                                                    'from_language' => $fromLanguage ) );
 597                  $module->redirectToView( 'removeassignment' );
 598                  return EZ_MODULE_HOOK_STATUS_CANCEL_RUN;
 599  
 600              }
 601              else
 602              {
 603                  // Just remove all the selected locations.
 604                  $mainNodeChanged = false;
 605                  $db =& eZDB::instance();
 606                  $db->begin();
 607                  foreach ( $assignments as $assignment )
 608                  {
 609                      $assignmentID = $assignment->attribute( 'id' );
 610                      if ( $assignment->attribute( 'is_main' ) )
 611                          $mainNodeChanged = true;
 612                      eZNodeAssignment::removeByID( $assignmentID );
 613                  }
 614                  if ( $mainNodeChanged )
 615                      eZNodeAssignment::setNewMainAssignment( $objectID, $versionInt );
 616                  $db->commit();
 617                  unset( $mainNodeChanged );
 618              }
 619              unset( $assignmentsIDs, $assignments );
 620  
 621          }
 622          else
 623              eZDebug::writeNotice( 'No nodes to remove selected' );
 624      }
 625  
 626      if ( $module->isCurrentAction( 'MoveNode' ) )
 627      {
 628          $objectID = $object->attribute( 'id' );
 629          if ( $http->hasPostVariable( 'MoveNodeID' ) )
 630          {
 631              $fromNodeID = $http->postVariable( 'MoveNodeID' ); //$sourceNodeID[0];
 632              $oldAssignmentParentID = $fromNodeID;
 633              $fromNodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $fromNodeID );
 634              $publishParentNodeID = $fromNodeAssignment->attribute( 'parent_node' );
 635              if ( $publishParentNodeID > 1 )
 636              {
 637                  if( $fromNodeAssignment->attribute( 'from_node_id' ) != 0 )
 638                  {
 639                      $fromNodeID = $fromNodeAssignment->attribute( 'from_node_id' );
 640                      $oldAssignmentParentID = $fromNodeAssignment->attribute( 'parent_node' );
 641                  }
 642  
 643                  // we don't allow moving object to itself, to its descendants or parent object(s)
 644                  $objectAssignedNodes =& $object->attribute( 'assigned_nodes' );
 645  
 646                  // nodes that are not allowed to select (via checkbox or radiobutton) when browsing
 647                  $ignoreNodesSelectArray = array();
 648  
 649                  // nodes that are not allowed to click on
 650                  $ignoreNodesClickArray  = array();
 651                  foreach( $objectAssignedNodes as $curAN )
 652                  {
 653                      // current node should be neihter selectable, nor clickable
 654                      $ignoreNodesClickArray[]  = $curAN->NodeID;
 655                      $ignoreNodesSelectArray[] = $curAN->NodeID;
 656  
 657                      // parent node should be only clickable, but not selectable
 658                      $ignoreNodesSelectArray[] = $curAN->ParentNodeID;
 659                  }
 660  
 661                  eZContentBrowse::browse( array( 'action_name' => 'MoveNodeAssignment',
 662                                                  'description_template' => 'design:content/browse_move_placement.tpl',
 663                                                  'keys' => array( 'class' => $class->attribute( 'id' ),
 664                                                                   'class_id' => $class->attribute( 'identifier' ),
 665                                                                   'classgroup' => $class->attribute( 'ingroup_id_list' ),
 666                                                                   'section' => $object->attribute( 'section_id' ) ),
 667                                                  'start_node' => $fromNodeID,
 668                                                  'persistent_data' => array( 'FromNodeID' => $fromNodeID,
 669                                                                              'OldAssignmentParentID' => $oldAssignmentParentID ),
 670                          'ignore_nodes_select' => $ignoreNodesSelectArray,
 671                          'ignore_nodes_click'  => $ignoreNodesClickArray,
 672                                                  'content' => array( 'object_id' => $objectID,
 673                                                                      'previous_node_id' => $fromNodeID,
 674                                                                      'object_version' => $editVersion,
 675                                                                      'object_language' => $editLanguage ),
 676                                                  'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage" ),
 677                                           $module );
 678  
 679                  return EZ_MODULE_HOOK_STATUS_CANCEL_RUN;
 680              }
 681          }
 682      }
 683  }
 684  
 685  function handleNodeTemplate( &$module, &$class, &$object, &$version, &$contentObjectAttributes, $editVersion, $editLanguage, &$tpl )
 686  {
 687      // When the object has been published we will use the nodes as
 688      // node-assignments by faking the list, this is required since new
 689      // version of the object does not have node-assignments/
 690      // When the object is a draft we use the normal node-assignment list
 691      $assignedNodeArray = array();
 692      $versionedAssignedNodeArray =& $version->attribute( 'parent_nodes' );
 693      $parentNodeIDMap = array();
 694      $nodes = $object->assignedNodes();
 695      $i = 0;
 696      foreach ( $nodes as $node )
 697      {
 698          $data = array( 'id' => null,
 699                         'contentobject_id' => $object->attribute( 'id' ),
 700                         'contentobject_version' => $version->attribute( 'version' ),
 701                         'parent_node' => $node->attribute( 'parent_node_id' ),
 702                         'sort_field' => $node->attribute( 'sort_field' ),
 703                         'sort_order' => $node->attribute( 'sort_order' ),
 704                         'is_main' => ( $node->attribute( 'main_node_id' ) == $node->attribute( 'node_id' ) ? 1 : 0 ),
 705                         'parent_remote_id' => $node->attribute( 'remote_id' ),
 706                         'op_code' => EZ_NODE_ASSIGNMENT_OP_CODE_NOP );
 707          $assignment = eZNodeAssignment::create( $data );
 708          $assignedNodeArray[$i] = $assignment;
 709          $parentNodeIDMap[$node->attribute( 'parent_node_id' )] = $i;
 710          ++$i;
 711      }
 712      foreach ( $versionedAssignedNodeArray as $nodeAssignment )
 713      {
 714          $opCode = $nodeAssignment->attribute( 'op_code' );
 715          if ( ( $opCode & 1 ) == EZ_NODE_ASSIGNMENT_OP_CODE_NOP ) // If the execute bit is not set it will be ignored.
 716          {
 717              continue;
 718          }
 719          // Only add assignments whose parent is not present in the published nodes.
 720          if ( isset( $parentNodeIDMap[$nodeAssignment->attribute( 'parent_node' )] ) )
 721          {
 722              if ( $opCode == EZ_NODE_ASSIGNMENT_OP_CODE_CREATE ) // CREATE entries are just skipped
 723              {
 724                  continue;
 725              }
 726              // Or if they have an op_code (move,remove) set, in which case they overwrite the entry
 727              $index = $parentNodeIDMap[$nodeAssignment->attribute( 'parent_node' )];
 728              $assignedNodeArray[$index]->setAttribute( 'id', $nodeAssignment->attribute( 'id' ) );
 729              $assignedNodeArray[$index]->setAttribute( 'from_node_id', $nodeAssignment->attribute( 'from_node_id' ) );
 730              $assignedNodeArray[$index]->setAttribute( 'remote_id', $nodeAssignment->attribute( 'remote_id' ) );
 731              $assignedNodeArray[$index]->setAttribute( 'op_code', $nodeAssignment->attribute( 'op_code' ) );
 732              continue;
 733          }
 734          if ( $opCode == EZ_NODE_ASSIGNMENT_OP_CODE_REMOVE ||
 735               $opCode == EZ_NODE_ASSIGNMENT_OP_CODE_MOVE )
 736          {
 737              // The node-assignment has a remove/move operation but the node does not exist.
 738              // We will not show it in this case.
 739              continue;
 740          }
 741          $assignedNodeArray[$i] = $nodeAssignment;
 742          ++$i;
 743      }
 744      eZDebugSetting::writeDebug( 'kernel-content-edit', $assignedNodeArray, "assigned nodes array" );
 745      $remoteMap = array();
 746  
 747      $db =& eZDB::instance();
 748      $db->begin();
 749      foreach ( array_keys( $assignedNodeArray ) as $assignedNodeKey )
 750      {
 751          $assignedNode =& $assignedNodeArray[$assignedNodeKey];
 752          $node =& $assignedNode->getParentNode();
 753          if ( $node !== null )
 754          {
 755              $remoteID = $assignedNode->attribute( 'remote_id' );
 756              if ( $remoteID > 0 )
 757              {
 758                  if ( isset( $remoteMap[$remoteID] ) )
 759                  {
 760                      if ( is_array( $remoteMap[$remoteID] ) )
 761                          $remoteMap[$remoteID][] =& $assignedNode;
 762                      else
 763                      {
 764                          $currentRemote =& $remoteMap[$remoteID];
 765                          unset( $remoteMap[$remoteID] );
 766                          $remoteMap[$remoteID] = array();
 767                          $remoteMap[$remoteID][] =& $currentRemote;
 768                          $remoteMap[$remoteID][] =& $assignedNode;
 769                      }
 770                  }
 771                  else
 772                      $remoteMap[$remoteID] =& $assignedNode;
 773              }
 774          }
 775          else
 776          {
 777              $assignedNode->purge();
 778              unset( $assignedNodeArray[$assignedNodeKey] );
 779          }
 780      }
 781      $db->commit();
 782      eZDebugSetting::writeDebug( 'kernel-content-edit', $assignedNodeArray, "assigned nodes array" );
 783  
 784      $currentVersion =& $object->version( $editVersion );
 785      $publishedNodeArray = array();
 786      if ( $currentVersion )
 787          $publishedNodeArray =& $currentVersion->attribute( 'parent_nodes' );
 788      $mainParentNodeID = $version->attribute( 'main_parent_node_id' );
 789  
 790      $tpl->setVariable( 'assigned_node_array', $assignedNodeArray );
 791      $tpl->setVariable( 'assigned_remote_map', $remoteMap );
 792      $tpl->setVariable( 'published_node_array', $publishedNodeArray );
 793      $tpl->setVariable( 'main_node_id', $mainParentNodeID );
 794  }
 795  
 796  function initializeNodeEdit( &$module )
 797  {
 798      $module->addHook( 'post_fetch', 'checkNodeAssignments' );
 799      $module->addHook( 'post_fetch', 'checkNodeMovements' );
 800      $module->addHook( 'pre_commit', 'storeNodeAssignments' );
 801      $module->addHook( 'action_check', 'checkNodeActions' );
 802      $module->addHook( 'pre_template', 'handleNodeTemplate' );
 803  }
 804  
 805  ?>


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