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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 01:24:23
Script start
Timing: Jan 31 2025 01:24:23
Module start 'layout'
Timing: Jan 31 2025 01:24:23
Module start 'content'
Timing: Jan 31 2025 01:24:23
Module end 'content'
Timing: Jan 31 2025 01:24:23
Script end

Main resources:

Total runtime0.0211 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0044 588.1328151.2109
Module start 'layout' 0.00440.0045 739.3438220.6875
Module start 'content' 0.00890.0108 960.03131,001.9141
Module end 'content' 0.01970.0013 1,961.945333.9922
Script end 0.0210  1,995.9375 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002511.6995140.0002
Check MTime0.00104.9128140.0001
Mysql Total
Database connection0.00062.839710.0006
Mysqli_queries0.002813.499830.0009
Looping result0.00000.061110.0000
Template Total0.00094.310.0009
Template load0.00063.086510.0006
Template processing0.00031.214910.0003
Override
Cache load0.00052.155810.0005
General
dbfile0.00021.030380.0000
String conversion0.00000.032840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_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