[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/common/ -> eztreemenuoperator.php (source)

   1  <?php
   2  //
   3  // Definition of eZTreeMenuOperator class
   4  //
   5  // Created on: <12-Feb-2003 09:17:07 bf>
   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  include_once ( "kernel/classes/ezcontentobjecttreenode.php" );
  30  
  31  class eZTreeMenuOperator
  32  {
  33      /*!
  34       */
  35      function eZTreeMenuOperator( $name = 'treemenu' )
  36      {
  37          $this->Operators = array( $name );
  38      }
  39  
  40      /*!
  41       Returns the operators in this class.
  42      */
  43      function &operatorList()
  44      {
  45          return $this->Operators;
  46      }
  47  
  48      /*!
  49       See eZTemplateOperator::namedParameterList()
  50      */
  51      function namedParameterList()
  52      {
  53          return array( 'path' => array( 'type' => 'array',
  54                                         'required' => true,
  55                                         'default' => false ),
  56                        'node_id' => array( 'type' => 'int',
  57                                            'required' => false,
  58                                            'default' => false ),
  59                        'class_filter' => array( 'type' => 'array',
  60                                                 'required' => false,
  61                                                 'default' => false ),
  62                        'depth_skip' => array( 'type' => 'int',
  63                                               'required' => false,
  64                                               'default' => false ),
  65                        'max_level' => array( 'type' => 'int',
  66                                              'required' => false,
  67                                              'default' => false ),
  68                        'is_selected_method' => array( 'type' => 'string',
  69                                                       'required' => false,
  70                                                       'default' => 'tree' ),
  71                        'indentation_level' => array( 'type' => 'int',
  72                                                      'required' => false,
  73                                                      'default' => 15 ),
  74                        'language' => array( 'type' => 'string|array',
  75                                             'required' => false,
  76                                             'default' => false ) );
  77      }
  78  
  79      /*!
  80       \reimp
  81      */
  82      function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
  83      {
  84          $level = 0;
  85          $done = false;
  86          $i = 0;
  87          $pathArray = array();
  88          $tmpModulePath = $namedParameters['path'];
  89          $classFilter = $namedParameters['class_filter'];
  90          $language = $namedParameters['language'];
  91          // node_id is not used anymore
  92          if ( isset( $namedParameters['node_id'] ) )
  93              eZDebug::writeNotice( 'Deprecated parameter "node_id" in treemenu template operator' );
  94  
  95          if ( $classFilter === false )
  96          {
  97              $classFilter = array();
  98          }
  99          else if ( count( $classFilter ) == 0 )
 100          {
 101              $classFilter = array( 1 );
 102          }
 103          $classFilter = ( count( $classFilter ) == 1 and !isset( $classFilter[0] ) ) ? array( 1 ) : $classFilter;
 104          if ( !$tmpModulePath[count($tmpModulePath)-1]['url'] and isset( $tmpModulePath[count($tmpModulePath)-1]['node_id'] ) )
 105              $tmpModulePath[count($tmpModulePath)-1]['url'] = "/content/view/full/" . $tmpModulePath[count($tmpModulePath)-1]['node_id'];
 106  
 107          $depthSkip = $namedParameters['depth_skip'];
 108          $indentationLevel = $namedParameters['indentation_level'];
 109  
 110          $maxLevel = $namedParameters['max_level'];
 111          $isSelectedMethod = $namedParameters['is_selected_method'];
 112          if ( $maxLevel === false )
 113              $maxLevel = 2;
 114  
 115          while ( !$done && isset( $tmpModulePath[$i+$depthSkip] ) )
 116          {
 117              // get node id
 118              $elements = explode( "/", $tmpModulePath[$i+$depthSkip]['url'] );
 119              $nodeID = false;
 120              if ( isset( $elements[4] ) )
 121                  $nodeID = $elements[4];
 122  
 123              $excludeNode = false;
 124  
 125              if ( isset( $elements[1] ) &&
 126                   isset( $elements[2] ) &&
 127                  $elements[1] == 'content' &&
 128                  $elements[2] == 'view' &&
 129                  is_numeric( $nodeID ) &&
 130                  $excludeNode == false &&
 131                  $level < $maxLevel )
 132              {
 133                  $node = eZContentObjectTreeNode::fetch( $nodeID );
 134                  if ( !isset( $node ) ) { $operatorValue = $pathArray; return; }
 135                  if ( isset( $tmpModulePath[$i+$depthSkip+1] ) )
 136                  {
 137                      $nextElements = explode( "/", $tmpModulePath[$i+$depthSkip+1]['url'] );
 138                      if ( isset( $nextElements[4] ) )
 139                      {
 140                          $nextNodeID = $nextElements[4];
 141                      }
 142                      else
 143                      {
 144                          $nextNodeID = false;
 145                      }
 146                  }
 147                  else
 148                      $nextNodeID = false;
 149  
 150                  $menuChildren = eZContentObjectTreeNode::subTree( array( 'Depth' => 1,
 151                                                                           'Offset' => 0,
 152                                                                           'SortBy' => $node->sortArray(),
 153                                                                           'Language' => $language,
 154                                                                           'ClassFilterType' => 'include',
 155                                                                           'ClassFilterArray' => $classFilter ),
 156                                                                    $nodeID );
 157  
 158                  /// Fill objects with attributes, speed boost
 159                  eZContentObject::fillNodeListAttributes( $menuChildren );
 160  
 161                  $tmpPathArray = array();
 162                  foreach ( $menuChildren as $child )
 163                  {
 164                      $name = $child->attribute( 'name' );
 165                      $tmpNodeID = $child->attribute( 'node_id' );
 166  
 167                      $url = "/content/view/full/$tmpNodeID/";
 168                      $urlAlias = "/" . $child->attribute( 'url_alias' );
 169  
 170                      $mainNode = $child->attribute( 'main_node_id' );
 171                      $dataMap = $child->attribute( 'data_map' );
 172                      $childrenCount = $child->attribute( 'children_count' );
 173                      $contentObject = $child->attribute( 'object' );
 174                      $isMain = false;
 175                      if ( $mainNode == $tmpNodeID )
 176                          $isMain = true;
 177  
 178                      $hasChildren = false;
 179                      if ( $childrenCount > 0 )
 180                          $hasChildren = true;
 181  
 182                      $indent = ($i - 1) * $indentationLevel;
 183  
 184                      $isSelected = false;
 185                      $nextNextElements = ( $isSelectedMethod == 'node' and isset( $tmpModulePath[$i+$depthSkip+2]['url'] ) ) ? explode( "/", $tmpModulePath[$i+$depthSkip+2]['url'] ) : null;
 186                      if ( $nextNodeID === $tmpNodeID and !isset( $nextNextElements[4] ) )
 187                      {
 188                          $isSelected = true;
 189                      }
 190  
 191                      $tmpPathArray[] = array( 'id' => $tmpNodeID,
 192                                               'level' => $i,
 193                                               'data_map' => $dataMap,
 194                                               'class_name' => $contentObject->classname(),
 195                                               'is_main_node' => $isMain,
 196                                               'has_children' => $hasChildren,
 197                                               'indent' => $indent,
 198                                               'url_alias' => $urlAlias,
 199                                               'url' => $url,
 200                                               'text' => $name,
 201                                               'is_selected' => $isSelected,
 202                                               'node' => $child );
 203                  }
 204  
 205                  // find insert pos
 206                  $j = 0;
 207                  $insertPos = 0;
 208                  foreach ( $pathArray as $path )
 209                  {
 210                      if ( $path['id'] == $nodeID )
 211                          $insertPos = $j;
 212                      $j++;
 213                  }
 214                  $restArray = array_splice( $pathArray, $insertPos + 1 );
 215  
 216                  $pathArray = array_merge( $pathArray, $tmpPathArray );
 217                  $pathArray = array_merge( $pathArray, $restArray );
 218              }
 219              else
 220              {
 221                  if ( $level == 0 )
 222                  {
 223                      $node = eZContentObjectTreeNode::fetch( 2 );
 224                      if ( !isset( $node ) ) { $operatorValue = $pathArray; return; }
 225                      $menuChildren = eZContentObjectTreeNode::subTree( array( 'Depth' => 1,
 226                                                                               'Offset' => 0,
 227                                                                               'SortBy' => $node->sortArray(),
 228                                                                               'Language' => $language,
 229                                                                               'ClassFilterType' => 'include',
 230                                                                               'ClassFilterArray' => $classFilter ),
 231                                                                        2 );
 232  
 233                      /// Fill objects with attributes, speed boost
 234                      eZContentObject::fillNodeListAttributes( $menuChildren );
 235  
 236                      $pathArray = array();
 237                      foreach ( $menuChildren as $child )
 238                      {
 239                          $name = $child->attribute( 'name' );
 240                          $tmpNodeID = $child->attribute( 'node_id' );
 241  
 242                          $url = "/content/view/full/$tmpNodeID/";
 243                          $urlAlias = "/" . $child->attribute( 'url_alias' );
 244  
 245                          $pathArray[] = array( 'id' => $tmpNodeID,
 246                                                'level' => $i,
 247                                                'url_alias' => $urlAlias,
 248                                                'url' => $url,
 249                                                'text' => $name,
 250                                                'is_selected' => false,
 251                                                'node' => $child );
 252                      }
 253                  }
 254                  $done = true;
 255              }
 256              ++$level;
 257              ++$i;
 258          }
 259  
 260          $operatorValue = $pathArray;
 261      }
 262  
 263      /// \privatesection
 264      var $Operators;
 265  };
 266  
 267  ?>


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