[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Definition of eZRSSExportItem class
   4  //
   5  // Created on: <18-Sep-2003 13:13:56 kk>
   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 ezrssexportitem.php
  30  */
  31  
  32  /*!
  33    \class eZRSSExportItem ezrssexportitem.php
  34    \brief Handles RSS Export Item in eZ publish
  35  
  36    RSSExportItem is used to create RSS feeds from published content. See kernel/rss for more files.
  37  */
  38  
  39  include_once ( 'kernel/classes/ezpersistentobject.php' );
  40  include_once ( 'kernel/classes/ezrssexport.php' );
  41  
  42  class eZRSSExportItem extends eZPersistentObject
  43  {
  44  
  45      /*!
  46       Initializes a new RSSExportItem.
  47      */
  48      function eZRSSExportItem( $row )
  49      {
  50          $this->eZPersistentObject( $row );
  51      }
  52  
  53      /*!
  54       \reimp
  55      */
  56      function definition()
  57      {
  58          return array( "fields" => array( "id" => array( 'name' => 'ID',
  59                                                          'datatype' => 'integer',
  60                                                          'default' => 0,
  61                                                          'required' => true ),
  62                                           'rssexport_id' => array( 'name' => 'RSSExportID',
  63                                                                    'datatype' => 'integer',
  64                                                                    'default' => '',
  65                                                                    'required' => true,
  66                                                                    'foreign_class' => 'eZRSSExport',
  67                                                                    'foreign_attribute' => 'id',
  68                                                                    'multiplicity' => '1..*' ),
  69                                           'source_node_id' => array( 'name' => 'SourceNodeID',
  70                                                                      'datatype' => 'integer',
  71                                                                      'default' => '',
  72                                                                      'required' => true,
  73                                                                      'foreign_class' => 'eZContentObjectTreeNode',
  74                                                                      'foreign_attribute' => 'node_id',
  75                                                                      'multiplicity' => '1..*' ),
  76                                           'class_id' => array( 'name' => 'ClassID',
  77                                                                'datatype' => 'integer',
  78                                                                'default' => '',
  79                                                                'required' => true,
  80                                                                'foreign_class' => 'eZContentClass',
  81                                                                'foreign_attribute' => 'id',
  82                                                                'multiplicity' => '1..*' ),
  83                                           'description' => array( 'name' => 'Description',
  84                                                                   'datatype' => 'string',
  85                                                                   'default' => '',
  86                                                                   'required' => true ),
  87                                           'title' => array( 'name' => 'Title',
  88                                                             'datatype' => 'string',
  89                                                             'default' => '',
  90                                                             'required' => true ),
  91                                           'status' => array( 'name' => 'Status',
  92                                                              'datatype' => 'integer',
  93                                                              'default' => 0,
  94                                                              'required' => true ),
  95                                           'subnodes' => array( 'name' => 'Subnodes',
  96                                                                'datatype' => 'integer',
  97                                                                'default' => 0,
  98                                                                'required' => true ) ),
  99                        "keys" => array( "id", 'status' ),
 100                        'function_attributes' => array( 'class_attributes' => 'classAttributes',
 101                                                        'source_node' => 'sourceNode',
 102                                                        'source_path' => 'sourcePath' ),
 103                        "increment_key" => "id",
 104                        "class_name" => "eZRSSExportItem",
 105                        "name" => "ezrss_export_item" );
 106      }
 107  
 108      /*!
 109       \static
 110       Creates a new RSS Export Item
 111       \param EZRSSExport objcted id. (The RSSExport this item belongs to)
 112  
 113       \return the URL alias object
 114      */
 115      function create( $rssexport_id )
 116      {
 117          $row = array( 'id' => null,
 118                        'rssexport_id' => $rssexport_id,
 119                        'source_node_id' => 0,
 120                        'class_id' => 1,
 121                        'url_id' => '',
 122                        'description' => '',
 123                        'title' => '',
 124                        'status' => 0,
 125                        'subnodes' => 0);
 126          return new eZRSSExportItem( $row );
 127      }
 128  
 129      function &classAttributes()
 130      {
 131          if ( isset( $this->ClassID ) and $this->ClassID )
 132          {
 133              include_once ( 'kernel/classes/ezcontentclass.php' );
 134              $contentClass = eZContentClass::fetch( $this->ClassID );
 135              if ( $contentClass )
 136                  $attributes =& $contentClass->fetchAttributes();
 137              else
 138                  $attributes = null;
 139          }
 140          else
 141              $attributes = null;
 142          return $attributes;
 143      }
 144  
 145      function &sourcePath()
 146      {
 147          if ( isset( $this->SourceNodeID ) and $this->SourceNodeID )
 148          {
 149              include_once ( "kernel/classes/ezcontentobjecttreenode.php" );
 150              $objectNode = eZContentObjectTreeNode::fetch( $this->SourceNodeID );
 151              if ( isset( $objectNode ) )
 152              {
 153                  $path_array = $objectNode->attribute( 'path_array' );
 154                  for ( $i = 0; $i < count( $path_array ); $i++ )
 155                  {
 156                      $treenode = eZContentObjectTreeNode::fetch( $path_array[$i] );
 157                      if( $i == 0 )
 158                          $retValue = $treenode->attribute( 'name' );
 159                      else
 160                          $retValue .= '/'.$treenode->attribute( 'name' );
 161                  }
 162              }
 163              else
 164                  $retValue = null;
 165          }
 166          else
 167              $retValue = null;
 168          return $retValue;
 169      }
 170  
 171      function &sourceNode()
 172      {
 173          if ( isset( $this->SourceNodeID ) and $this->SourceNodeID )
 174          {
 175              include_once ( "kernel/classes/ezcontentobjecttreenode.php" );
 176              $sourceNode = eZContentObjectTreeNode::fetch( $this->SourceNodeID );
 177          }
 178          else
 179              $sourceNode = null;
 180          return $sourceNode;
 181      }
 182  
 183      /*!
 184       \static
 185        Fetches the RSS Export by ID.
 186  
 187       \param RSS Export ID
 188      */
 189      function fetch( $id, $asObject = true, $status = EZ_RSSEXPORT_STATUS_VALID )
 190      {
 191          return eZPersistentObject::fetchObject( eZRSSExportItem::definition(),
 192                                                  null,
 193                                                  array( "id" => $id,
 194                                                         'status' => $status ),
 195                                                  $asObject );
 196      }
 197  
 198      /*
 199       Fetches the items belonging to the specified RSSExport
 200       example: fetchFilteredList( array( 'rssexport_id' => 24 ) )
 201  
 202       \param array, example: array( 'rssexport_id' => 24 )
 203  
 204       \return array containing RSSExport Items
 205      */
 206      function fetchFilteredList( $cond, $asObject = true, $status = EZ_RSSEXPORT_STATUS_VALID )
 207      {
 208          return eZPersistentObject::fetchObjectList( eZRSSExportItem::definition(),
 209                                                      null, $cond, array( 'id' => 'asc',
 210                                                                          'status' => $status ), null,
 211                                                      $asObject );
 212      }
 213  
 214      function getAttributeMappings( $rssSources )
 215      {
 216          if( is_array( $rssSources ) && count( $rssSources ) )
 217          {
 218              foreach( $rssSources as $rssSource )
 219              {
 220                  // fetch path for class attribute to RSS field mapping
 221                  $node = eZContentObjectTreeNode::fetch( $rssSource->SourceNodeID );
 222                  if ( is_object( $node ) )
 223                  {
 224                      $attributeMappings[] = array( $rssSource, $node );
 225                  }
 226              }
 227  
 228              // sort the array so nodes with deeper path are first
 229              // for class attribute to RSS field mapping
 230              usort( $attributeMappings,
 231                     create_function( '$a, $b',
 232                                      '$a_cnt = count( $a[1]->attribute( \'path_array\' ) );' .
 233                                      '$b_cnt = count( $b[1]->attribute( \'path_array\' ) );' .
 234                                      'return ( $a_cnt == $b_cnt ) ? 0 : ( ( $a_cnt > $b_cnt ) ? 1 : -1 );' ) );
 235          }
 236  
 237          return $attributeMappings;
 238      }
 239  
 240      /*!
 241       Get the N last published nodes matching the specifications of this RSS Export item
 242  
 243       \param number of objects to fetch
 244  
 245       \return list of Nodes
 246      */
 247      function fetchNodeList( $rssSources, $objectListFilter )
 248      {
 249          // compose parameters for several subtrees
 250          if( is_array( $rssSources ) && count( $rssSources ) )
 251          {
 252              foreach( $rssSources as $rssSource )
 253              {
 254                  // Do not include subnodes
 255                  if ( !intval( $rssSource->Subnodes ) )
 256                  {
 257                      $depth = 1;
 258                  }
 259                  else // Fetch objects even from subnodes
 260                  {
 261                      $depth = 0;
 262                  }
 263  
 264                  $nodesParams[] = array( 'ParentNodeID' => $rssSource->SourceNodeID,
 265                                          'ResultID' => $rssSource->ID,
 266                                          'Depth' => $depth,
 267                                          'DepthOperator' => 'eq',
 268                                          'MainNodeOnly' => $objectListFilter['main_node_only'],
 269                                          'ClassFilterType' => 'include',
 270                                          'ClassFilterArray' => array( intval( $rssSource->ClassID ) )
 271                                         );
 272              }
 273  
 274              $listParams = array( 'Limit' => $objectListFilter['number_of_objects'],
 275                                   'SortBy' => array( 'published', false )
 276                                  );
 277  
 278              include_once ( "kernel/classes/ezcontentobjecttreenode.php" );
 279              $nodeList = eZContentObjectTreeNode::subTreeMultiPaths( $nodesParams, $listParams );
 280          }
 281          else
 282              $nodeList = null;
 283          return $nodeList;
 284      }
 285  
 286  }
 287  
 288  ?>


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