Forums / Developer / Fetching nodes with images

Fetching nodes with images

Author Message

Georg Franz

Tuesday 06 December 2005 7:39:42 am

Hi folks,

I've a folder with articles. The article class has an image datatype. Is it possible to fetch only articles which has a valid image? Maybe with an extended attribute filter?

Thanx in advance!

Best wishes,
Georg.

--
http://www.schicksal.com Horoskop website which uses eZ Publish since 2004

Georg Franz

Wednesday 07 December 2005 6:54:09 am

Hi,

to answer myself:

An extended attribute filter does the trick.
Info about them:
http://ez.no/doc/ez_publish/technical_manual/3_6/reference/modules/content/fetch_functions/list

settings/override/extendedattributefilter.ini.append.php

<?php /* #?ini charset="iso-8859-1"?
# eZ publish extended attribute filter configuration file.

#The name of the filter.
[ExtendedImageFilter]

#The name of the extension where the filtering code is defined.
ExtensionName=gwfutils

#The name of the filter class.
ClassName=eZExtendedImageFilter

#The name of the method which is called to generate the SQL parts.
MethodName=createSqlParts

#The file which should be included (extension/myextension will automatically be prepended).
FileName=kernel/classes/ezimagefilter.php


*/ ?>

and the filter class:
ezimagefilter.php

<?php

class eZExtendedImageFilter
{
    /*!
     Constructor
    */
    function eZExtendedImageFilter()
    {
        // Empty...
    }

    function createSqlParts( $params )
    {
        $result = array( 'tables' => '', 'joins'  => '' );
        if ( isset( $params['attribute'] ) )
        {
             $filterAttributeID = $params['attribute'];
        }
        else
        	return $result;
        
        if ( !is_numeric( $filterAttributeID ) )
        	$filterAttributeID = eZContentObjectTreeNode::classAttributeIDByIdentifier( $filterAttributeID );
        
        $filterSQL = array();
        $filterSQL['from']  = ", ezcontentobject_attribute i1 ";
        $filterSQL['where'] = " (
		       i1.contentobject_id = ezcontentobject.id AND
		       i1.contentclassattribute_id = $filterAttributeID AND
		       i1.version = ezcontentobject_name.content_version AND
		       i1.language_code = ezcontentobject_name.real_translation AND 
		       i1.data_text LIKE '%is_valid=\"1\"%' ) AND
		       ";

        return array( 'tables' => $filterSQL['from'], 'joins'  => $filterSQL['where'] );

    }
}

?>

sample fetch in template:

{let news_children = fetch(content,list,
	                   hash( parent_node_id,85,
			                 offset,0,
			                 limit,1,
			                 sort_by,array(published,false()),
			                 class_filter_type,include, 
	                         class_filter_array,array(article),
	                         main_node_only,true(),
	                         extended_attribute_filter, hash( 'id', 'ExtendedImageFilter',
                                                 'params', hash( 'attribute', 'article/image' ) )
}

Hope that helps someone ...

Contribution: http://ez.no/community/contribs/hacks/extended_attribute_filter_fetch_nodes_with_valid_images

PS.: To eZ programer: Is there a better way to get the info, if a valid image is attached?

Best wishes,
Georg.

--
http://www.schicksal.com Horoskop website which uses eZ Publish since 2004

eZ debug

Timing: Jan 18 2025 11:10:24
Script start
Timing: Jan 18 2025 11:10:24
Module start 'content'
Timing: Jan 18 2025 11:10:24
Module end 'content'
Timing: Jan 18 2025 11:10:24
Script end

Main resources:

Total runtime0.1870 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0074 588.8438180.8359
Module start 'content' 0.00740.0059 769.679797.9922
Module end 'content' 0.01320.1737 867.6719521.8984
Script end 0.1869  1,389.5703 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00402.1187200.0002
Check MTime0.00160.8336200.0001
Mysql Total
Database connection0.00090.501110.0009
Mysqli_queries0.129269.09231410.0009
Looping result0.00140.77541390.0000
Template Total0.173392.710.1733
Template load0.00080.438510.0008
Template processing0.172492.212310.1724
Override
Cache load0.00060.309110.0006
Sytem overhead
Fetch class attribute can translate value0.00100.510810.0010
XML
Image XML parsing0.00040.208610.0004
General
dbfile0.00442.3790200.0002
String conversion0.00000.002730.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs