Forums / Developer / help me in create $params in extended_attribute_filter

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.

eZ debug

Timing: Jan 30 2025 22:22:34
Script start
Timing: Jan 30 2025 22:22:34
Module start 'content'
Timing: Jan 30 2025 22:22:34
Module end 'content'
Timing: Jan 30 2025 22:22:34
Script end

Main resources:

Total runtime0.1841 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0071 588.0781370.2734
Module start 'content' 0.00710.0131 958.35161,009.7031
Module end 'content' 0.02020.1639 1,968.05473,899.5391
Script end 0.1841  5,867.5938 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00452.4181200.0002
Check MTime0.00140.7451200.0001
Mysql Total
Database connection0.00070.380210.0007
Mysqli_queries0.087947.73991410.0006
Looping result0.00120.66351390.0000
Template Total0.163588.810.1635
Template load0.00090.480010.0009
Template processing0.162688.321810.1626
Override
Cache load0.00060.323710.0006
Sytem overhead
Fetch class attribute can translate value0.00160.892410.0016
XML
Image XML parsing0.00030.141710.0003
General
dbfile0.00834.5251200.0004
String conversion0.00000.003430.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