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.