To fetch article class which has image attribute

Author Message

Romeo Antony

Friday 02 July 2010 5:28:26 am

In some templates need to fetch the article class which has image attribute.Means do not need to fetch article class without image attribute.

In some templates need to fetch all artciles with and without image attribute.

So where do I make chnages .

Someone told me that I need to set the attribute filter in the php class.

If I set the attribute filer , I can't fetch article class without images

Ivo Lukac

Friday 02 July 2010 5:57:22 am

I am not quite sure what you need, but if you need to distinguish article objects which actually have an image uploaded you can use this extended_attribute_filter in your extension:

<?php
class eZExtendedImageFilter{ 
 function eZExtendedImageFilter(){  
  // Empty... 
 }
 function createSqlParts( $params ) {  
  $result = array( 'tables' => '', 'joins'  => '' );  
  if ( isset( $params['classes'] ) ) {   
   $classes = $params['classes'];  
  } else return;
  $attr = 'image';  
  if ( isset( $params['attr'] ) ) {   
   $attr = $params['attr'];  
  } 
  $attribute_ids = array();  
  foreach ($classes as $class) {   
   array_push($attribute_ids,eZContentObjectTreeNode::classAttributeIDByIdentifier( $class . '/' . $attr ));  
  }
  $class_cond = array();  
  foreach ($attribute_ids as $aid) {   
   if ($aid) {    
   array_push($class_cond, 'i1.contentclassattribute_id = '.$aid);   
   }  
  }
  $string_class_cond = implode(" OR ",$class_cond);  
  $filterSQL = array();  
  $filterSQL['from']  = ", ezcontentobject_attribute i1 ";  
  $filterSQL['where'] = " (i1.contentobject_id = ezcontentobject.id AND (" . $string_class_cond . ") 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'] ); 
 }
}
?>

Add this into extendedattributefilter.ini.append.php:

[ExtendedImageFilter]
#The name of the extension where the filtering code is defined.
ExtensionName=your_extension
#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

To learn more about extended_attribute_filter look here: http://ez.no/doc/ez_publish/technical_manual/4_x/reference/modules/content/fetch_functions/list

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

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 18 2025 16:09:18
Script start
Timing: Jan 18 2025 16:09:18
Module start 'layout'
Timing: Jan 18 2025 16:09:18
Module start 'content'
Timing: Jan 18 2025 16:09:19
Module end 'content'
Timing: Jan 18 2025 16:09:19
Script end

Main resources:

Total runtime0.6959 sec
Peak memory usage4,096.0000 KB
Database Queries55

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0088 588.0469152.6406
Module start 'layout' 0.00880.0030 740.687539.4766
Module start 'content' 0.01180.6829 780.1641537.9063
Module end 'content' 0.69470.0012 1,318.070312.1250
Script end 0.6959  1,330.1953 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.4907160.0002
Check MTime0.00140.1995160.0001
Mysql Total
Database connection0.00210.295910.0021
Mysqli_queries0.644192.5491550.0117
Looping result0.00110.1523530.0000
Template Total0.653593.920.3267
Template load0.00260.374620.0013
Template processing0.650893.518720.3254
Template load and register function0.00010.016810.0001
states
state_id_array0.00390.556310.0039
state_identifier_array0.00120.170720.0006
Override
Cache load0.00210.3073170.0001
Sytem overhead
Fetch class attribute can translate value0.00080.117420.0004
Fetch class attribute name0.00140.194640.0003
XML
Image XML parsing0.00110.154020.0005
class_abstraction
Instantiating content class attribute0.00000.001240.0000
General
dbfile0.00090.1360230.0000
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 13
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs