help me in create $params in extended_attribute_filter

Author Message

Quynh Nguyen

Sunday 01 March 2009 11:32:19 pm

I create a class for extended_attribute_filter to fetch relative author object:

class HHAuthorFilter
{
	function HHAuthorFilter()
	{
		// Empty...
	}
 
	function createSqlParts( $params )
	{
		$sqlTables= ', ezcontentobject_attribute as myfilter_alias ';
 
		$sqlJoins = ' ezcontentobject_tree.contentobject_id = myfilter_alias.contentobject_id AND ezcontentobject_tree.contentobject_version = myfilter_alias.version AND myfilter_alias.data_type_string = "ezauthor"  AND';
 
		$sqlCondArray = array();

		foreach($params as $value)
		{
			$sqlCondArray[] = 'myfilter_alias.data_text LIKE "%' . $value[2] . '%"';
		}
 
		$sqlCond = implode( ' OR ', $sqlCondArray );
 
		$sqlCond = ' ( ' . $sqlCond . ' ) AND ' . $sqlJoins . ' ';
 
		return array( 'tables' => $sqlTables, 'joins' => $sqlCond );
	}
}

in template we got the $node.data_map.author.content.author_list as array, and this is the syntax in template:

{def $posts = fetch( 'content', 'list',
        hash( 'parent_node_id', 2,
              'sort_by', array( 'priority', false() ),
              'limit', 5,
              'extended_attribute_filter',
                            hash( 'id', 'HHAuthorFilter',
                            'params', hash( $node.data_map.author.content.author_list ) ) ) )}

{foreach $posts as $post}
{$post.name|wash()}
{/foreach}

{undef $posts}

but the sql string I got:

(  ) AND  ezcontentobject_tree.contentobject_id = myfilter_alias.contentobject_id AND ezcontentobject_tree.contentobject_version = myfilter_alias.version AND myfilter_alias.data_type_string = "ezauthor"

I known the error must be in $params I send from template or wrong in use array in my extended filter class.

Please help me!

I use this method to fetch the other object by current node's author.

Ivo Lukac

Monday 02 March 2009 12:46:07 am

Tyr it like this:

{
        function HHAuthorFilter()
        {
                // Empty...
        }
 
        function createSqlParts( $params )
        {
                $sqlTables= ', ezcontentobject_attribute as myfilter_alias ';
 
                $sqlJoins = ' ezcontentobject_tree.contentobject_id = myfilter_alias.contentobject_id AND ezcontentobject_tree.contentobject_version = myfilter_alias.version AND myfilter_alias.data_type_string = "ezauthor" AND';
 
                $sqlCondArray = array();
 
                foreach($params['authors'] as $value)
                {
                        $sqlCondArray[] = 'myfilter_alias.data_text LIKE "%' . $value . '%"';
                }
 
                $sqlCond = implode( ' OR ', $sqlCondArray );
 
                $sqlCond = ' ( ' . $sqlCond . ' ) AND ' . $sqlJoins . ' ';
 
                return array( 'tables' => $sqlTables, 'joins' => $sqlCond );
        }
}

and

{def $posts = fetch( 'content', 'list',
       hash( 'parent_node_id', 2,
             'sort_by', array( 'priority', false() ),
             'limit', 5,
             'extended_attribute_filter',
                           hash( 'id', 'HHAuthorFilter',
                           'params', hash( 'authors',$node.data_map.author.content.author_list ) ) ) )}
 
{foreach $posts as $post}
{$post.name|wash()}
{/foreach}
 
{undef $posts}

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

Quynh Nguyen

Monday 02 March 2009 4:36:10 am

wow, thank you very much!

It still does not work. But I fixed your comment code:

			$sqlCondArray[] = 'myfilter_alias.data_text LIKE "%' . $value['email'] . '%"';

and it works very well.

I use this way to find the other objects by authors from this current object. Because the data_text of of author field is and XML, so I use the syntax LIKE %author emails%.

However, I found some thing like that when debug:

Warning: PHP  	Mar 03 2009 10:56:44

Undefined index:  columns in /home/handheld/public_html/kernel/classes/ezcontentobjecttreenode.php on line 902

Maybe it is not from my class. But I wonder if my way is not good for fetch some relative object of current authors.

I hope that there are some comments will be here to help my code to run the trick.

Ivo Lukac

Monday 02 March 2009 5:31:14 am

Why don't you use owner attribute for example:

{def $nodes=fetch( 'content', 'list',
        hash( 'parent_node_id', 42,
             'attribute_filter', array( array( 'owner', '=', $current_user.contentobject_id )  )  ) )}
 
{foreach $nodes as $node}
    {$node.name|wash}<br />
{/foreach}

More here:
http://ez.no/doc/ez_publish/technical_manual/4_0/reference/modules/content/fetch_functions/list

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

Quynh Nguyen

Monday 02 March 2009 6:18:02 am

There is a little different between creator/owner and authors.

Some one can write the article very good and attractive people to read. But he can not compose or make his article display as good as others. I mean the author and editor are different people.

That's why I must use this filter to find other article from author, to make some parts when display article for readers. They can find another useful thing while reading...

I did a search but there is no extension similar, or maybe my English is not good to understand all extensions in projects & contributions.

I hope that my topic can help some-one like me... later.

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