|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZRSSExportItem class 00004 // 00005 // Created on: <18-Sep-2003 13:13:56 kk> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezrssexportitem.php 00032 */ 00033 00034 /*! 00035 \class eZRSSExportItem ezrssexportitem.php 00036 \brief Handles RSS Export Item in eZ Publish 00037 00038 RSSExportItem is used to create RSS feeds from published content. See kernel/rss for more files. 00039 */ 00040 00041 //include_once( 'kernel/classes/ezpersistentobject.php' ); 00042 //include_once( 'kernel/classes/ezrssexport.php' ); 00043 00044 class eZRSSExportItem extends eZPersistentObject 00045 { 00046 00047 /*! 00048 Initializes a new RSSExportItem. 00049 */ 00050 function eZRSSExportItem( $row ) 00051 { 00052 $this->eZPersistentObject( $row ); 00053 } 00054 00055 /*! 00056 \reimp 00057 */ 00058 static function definition() 00059 { 00060 return array( "fields" => array( "id" => array( 'name' => 'ID', 00061 'datatype' => 'integer', 00062 'default' => 0, 00063 'required' => true ), 00064 'rssexport_id' => array( 'name' => 'RSSExportID', 00065 'datatype' => 'integer', 00066 'default' => '', 00067 'required' => true, 00068 'foreign_class' => 'eZRSSExport', 00069 'foreign_attribute' => 'id', 00070 'multiplicity' => '1..*' ), 00071 'source_node_id' => array( 'name' => 'SourceNodeID', 00072 'datatype' => 'integer', 00073 'default' => '', 00074 'required' => true, 00075 'foreign_class' => 'eZContentObjectTreeNode', 00076 'foreign_attribute' => 'node_id', 00077 'multiplicity' => '1..*' ), 00078 'class_id' => array( 'name' => 'ClassID', 00079 'datatype' => 'integer', 00080 'default' => '', 00081 'required' => true, 00082 'foreign_class' => 'eZContentClass', 00083 'foreign_attribute' => 'id', 00084 'multiplicity' => '1..*' ), 00085 'description' => array( 'name' => 'Description', 00086 'datatype' => 'string', 00087 'default' => '', 00088 'required' => true ), 00089 'title' => array( 'name' => 'Title', 00090 'datatype' => 'string', 00091 'default' => '', 00092 'required' => true ), 00093 'status' => array( 'name' => 'Status', 00094 'datatype' => 'integer', 00095 'default' => 0, 00096 'required' => true ), 00097 'subnodes' => array( 'name' => 'Subnodes', 00098 'datatype' => 'integer', 00099 'default' => 0, 00100 'required' => true ) ), 00101 "keys" => array( "id", 'status' ), 00102 'function_attributes' => array( 'class_attributes' => 'classAttributes', 00103 'source_node' => 'sourceNode', 00104 'source_path' => 'sourcePath' ), 00105 "increment_key" => "id", 00106 "class_name" => "eZRSSExportItem", 00107 "name" => "ezrss_export_item" ); 00108 } 00109 00110 /*! 00111 \static 00112 Creates a new RSS Export Item 00113 \param eZRSSExport objcted id. (The RSSExport this item belongs to) 00114 00115 \return the URL alias object 00116 */ 00117 static function create( $rssexport_id ) 00118 { 00119 $row = array( 'id' => null, 00120 'rssexport_id' => $rssexport_id, 00121 'source_node_id' => 0, 00122 'class_id' => 1, 00123 'url_id' => '', 00124 'description' => '', 00125 'title' => '', 00126 'status' => 0, 00127 'subnodes' => 0); 00128 return new eZRSSExportItem( $row ); 00129 } 00130 00131 function &classAttributes() 00132 { 00133 if ( isset( $this->ClassID ) and $this->ClassID ) 00134 { 00135 //include_once( 'kernel/classes/ezcontentclass.php' ); 00136 $contentClass = eZContentClass::fetch( $this->ClassID ); 00137 if ( $contentClass ) 00138 $attributes = $contentClass->fetchAttributes(); 00139 else 00140 $attributes = null; 00141 } 00142 else 00143 $attributes = null; 00144 return $attributes; 00145 } 00146 00147 function &sourcePath() 00148 { 00149 $retValue = null; 00150 if ( isset( $this->SourceNodeID ) and $this->SourceNodeID ) 00151 { 00152 //include_once( "kernel/classes/ezcontentobjecttreenode.php" ); 00153 $objectNode = eZContentObjectTreeNode::fetch( $this->SourceNodeID ); 00154 if ( isset( $objectNode ) ) 00155 { 00156 $path_array = $objectNode->attribute( 'path_array' ); 00157 $path_array_count = count( $path_array ); 00158 for ( $i = 0; $i < $path_array_count; ++$i ) 00159 { 00160 $treenode = eZContentObjectTreeNode::fetch( $path_array[$i], false, false ); 00161 if ( is_array( $treenode ) && array_key_exists( 'name', $treenode ) ) 00162 { 00163 if ( $i == 0 ) 00164 { 00165 $retValue = $treenode['name']; 00166 } 00167 else 00168 { 00169 $retValue .= '/' . $treenode['name']; 00170 } 00171 } 00172 } 00173 } 00174 } 00175 return $retValue; 00176 } 00177 00178 function &sourceNode() 00179 { 00180 if ( isset( $this->SourceNodeID ) and $this->SourceNodeID ) 00181 { 00182 //include_once( "kernel/classes/ezcontentobjecttreenode.php" ); 00183 $sourceNode = eZContentObjectTreeNode::fetch( $this->SourceNodeID ); 00184 } 00185 else 00186 $sourceNode = null; 00187 return $sourceNode; 00188 } 00189 00190 /*! 00191 \static 00192 Fetches the RSS Export by ID. 00193 00194 \param RSS Export ID 00195 */ 00196 static function fetch( $id, $asObject = true, $status = eZRSSExport::STATUS_VALID ) 00197 { 00198 return eZPersistentObject::fetchObject( eZRSSExportItem::definition(), 00199 null, 00200 array( "id" => $id, 00201 'status' => $status ), 00202 $asObject ); 00203 } 00204 00205 /* 00206 Fetches the items belonging to the specified RSSExport 00207 example: fetchFilteredList( array( 'rssexport_id' => 24 ) ) 00208 00209 \param array, example: array( 'rssexport_id' => 24 ) 00210 00211 \return array containing RSSExport Items 00212 */ 00213 static function fetchFilteredList( $cond, $asObject = true, $status = eZRSSExport::STATUS_VALID ) 00214 { 00215 return eZPersistentObject::fetchObjectList( eZRSSExportItem::definition(), 00216 null, $cond, array( 'id' => 'asc', 00217 'status' => $status ), null, 00218 $asObject ); 00219 } 00220 00221 static function getAttributeMappings( $rssSources ) 00222 { 00223 if( is_array( $rssSources ) && count( $rssSources ) ) 00224 { 00225 foreach( $rssSources as $rssSource ) 00226 { 00227 // fetch path for class attribute to RSS field mapping 00228 $node = eZContentObjectTreeNode::fetch( $rssSource->SourceNodeID ); 00229 if ( is_object( $node ) ) 00230 { 00231 $attributeMappings[] = array( $rssSource, $node ); 00232 } 00233 } 00234 00235 // sort the array so nodes with deeper path are first 00236 // for class attribute to RSS field mapping 00237 usort( $attributeMappings, 00238 create_function( '$a, $b', 00239 '$a_cnt = count( $a[1]->attribute( \'path_array\' ) );' . 00240 '$b_cnt = count( $b[1]->attribute( \'path_array\' ) );' . 00241 'return ( $a_cnt == $b_cnt ) ? 0 : ( ( $a_cnt > $b_cnt ) ? 1 : -1 );' ) ); 00242 } 00243 00244 return $attributeMappings; 00245 } 00246 00247 /*! 00248 Get the N last published nodes matching the specifications of this RSS Export item 00249 00250 \param number of objects to fetch 00251 00252 \return list of Nodes 00253 */ 00254 static function fetchNodeList( $rssSources, $objectListFilter ) 00255 { 00256 // compose parameters for several subtrees 00257 if( is_array( $rssSources ) && count( $rssSources ) ) 00258 { 00259 foreach( $rssSources as $rssSource ) 00260 { 00261 // Do not include subnodes 00262 if ( !intval( $rssSource->Subnodes ) ) 00263 { 00264 $depth = 1; 00265 } 00266 else // Fetch objects even from subnodes 00267 { 00268 $depth = 0; 00269 } 00270 00271 $nodesParams[] = array( 'ParentNodeID' => $rssSource->SourceNodeID, 00272 'ResultID' => $rssSource->ID, 00273 'Depth' => $depth, 00274 'DepthOperator' => 'eq', 00275 'MainNodeOnly' => $objectListFilter['main_node_only'], 00276 'ClassFilterType' => 'include', 00277 'ClassFilterArray' => array( intval( $rssSource->ClassID ) ) 00278 ); 00279 } 00280 00281 $listParams = array( 'Limit' => $objectListFilter['number_of_objects'], 00282 'SortBy' => array( 'published', false ) 00283 ); 00284 00285 //include_once( "kernel/classes/ezcontentobjecttreenode.php" ); 00286 $nodeList = eZContentObjectTreeNode::subTreeMultiPaths( $nodesParams, $listParams ); 00287 } 00288 else 00289 $nodeList = null; 00290 return $nodeList; 00291 } 00292 00293 } 00294 00295 ?>