00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
00049
00050 function eZRSSExportItem( $row )
00051 {
00052 $this->eZPersistentObject( $row );
00053 }
00054
00055
00056
00057
00058 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
00112
00113
00114
00115
00116
00117 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
00192
00193
00194
00195
00196 function fetch( $id, $asObject = true, $status = EZ_RSSEXPORT_STATUS_VALID )
00197 {
00198 return eZPersistentObject::fetchObject( eZRSSExportItem::definition(),
00199 null,
00200 array( "id" => $id,
00201 'status' => $status ),
00202 $asObject );
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 function fetchFilteredList( $cond, $asObject = true, $status = EZ_RSSEXPORT_STATUS_VALID )
00214 {
00215 return eZPersistentObject::fetchObjectList( eZRSSExportItem::definition(),
00216 null, $cond, array( 'id' => 'asc',
00217 'status' => $status ), null,
00218 $asObject );
00219 }
00220
00221 function getAttributeMappings( $rssSources )
00222 {
00223 if( is_array( $rssSources ) && count( $rssSources ) )
00224 {
00225 foreach( $rssSources as $rssSource )
00226 {
00227
00228 $node = eZContentObjectTreeNode::fetch( $rssSource->SourceNodeID );
00229 if ( is_object( $node ) )
00230 {
00231 $attributeMappings[] = array( $rssSource, $node );
00232 }
00233 }
00234
00235
00236
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
00249
00250
00251
00252
00253
00254 function fetchNodeList( $rssSources, $objectListFilter )
00255 {
00256
00257 if( is_array( $rssSources ) && count( $rssSources ) )
00258 {
00259 foreach( $rssSources as $rssSource )
00260 {
00261
00262 if ( !intval( $rssSource->Subnodes ) )
00263 {
00264 $depth = 1;
00265 }
00266 else
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 ?>