Best way to multi-filter

Best way to multi-filter

Friday 01 September 2006 2:09:18 am - 6 replies

Author Message

Norman Leutner

Friday 01 September 2006 6:38:15 am

I'm having the same problem on some sites.

Take a look at http://ez.no/partner/worldwide_ez_publish_partners

<form action="/ezposttoview/action" method="post">

Maybe someone from ez can share his information and tell us something about that function and how ez solved this ;)

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Claudia Kosny

Saturday 02 September 2006 7:03:11 am

Hello Norman/Brendan

I am not exactly sure what you mean. The way I understand you the problem is to build the attribute filter in a way that it includes all attributes that are set to certain values in the posted form. So why don't you just go through each of the posted data, create the proper hash out of it and append it to the attribute filter?
Something like
set my_filter = array('and')
go through all items in post data
filter the ones wie are interested in, if necessary
if the posted item has a value (which means it was set to 'all' in the form)
my_filter|append(hash('class/attribute', '=', 'value of posted item'))

Then check whether the my_filter contains more data than the initial 'and' and use it in the fetch function.

So if that is not exactly what you want to do, please explain a bit more.

Greetings from Luxembourg

Claudia

Brendan Pike

Saturday 02 September 2006 8:19:05 am

Hi Claudia

Thanks for your response, I have searched ez.no and nothing really touches on this need so it will be a valuable forum post for myself Norman and others too I'm sure. I think your response will work for most of my filters but not all. I'll provide more detail so you can correct me if I am taking an incorrect approach.

So far I am filtering on the following:
1. (staff) The objects I'm fetching have added locations into "staff folders", so to view only specific staff objects I replace the fetch parent_node_id with (staff) as I'm not aware of any other way to filter on locations since its not a class attribute.
2. (jobstate) an enhanced selection attribute. array( 'job/job_status', '=', $#:view_parameters.jobstate)
3. (client) I can use the owner attribute for this, array( array( 'owner', '=', $#:view_parameters.client )
4. I also have 3 permanent filters set in order to hide certain owners from thet fetch, ie. array( 'owner', '!=', '522')

Please show me how the code should look. greatly appreciated :)

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.

Claudia Kosny

Saturday 02 September 2006 2:07:38 pm

Hello Brendan

Regarding the location I have no idea what to do. Maybe an extended attribute filter
could do the job, but I wouldn't know how to do it. Therefore I added just some code
of what I assume you are doing with the node ids.
In my example I did not use view parameters as I do not have such a page available
right now. But there should be no problem replacing the declared dummy variables
with view parameters.

Please note I checked for each variable whether it has any content, which means that variables that exist but hold a value of 0 (zero) will be filtered here.You might want to change that.

 
{* dummy variables which stand in for view parameters *}
{def $staff='3'
     $jobstate='foo'
     $owner='bar'
     $otherAttrib=''}

{* this will be our attribute filter *}
{def $my_filter=array()}

{* put each single attribute which you want to filter in array, 
here you can also add additional checks (e.g check for integer or so)*}
{if and(is_set($jobstate), $jobstate)}
 {set $my_filter=$my_filter|append(array('job/job_status', '=', $jobstate))}
{/if}
{if and(is_set($owner), $owner)}
 {set $my_filter=$my_filter|append(array('owner', '=', $owner))}
{/if}
{if and(is_set($otherAttrib), $otherAttrib)}
 {set $my_filter=$my_filter|append(array('job/otherAttrib', '=', $otherAttrib))}
{/if}

{* add your preset filters here the same way *}


{* prepend 'and' if necessary *}
{if $my_filter|count()|gt(1)}
 {set $my_filter=$my_filter|prepend('and')}
{/if}


{* I am not sure whether this is what you do with staff nodes *}
{def $fetch_parent_id=''}
{if and(is_set($staff), is_integer($staff), $staff|gt(2))}
 {set $fetch_parent_id = $staff}
{else}
 {set $fetch_parent_id = 2}
{/if}

{if $my_filter|count()|gt(0)}
 {* fetch with attribute filter *}
 {def $nodeArr = fetch('content', 'tree', hash('parent_node_id', $fetch_parent_id,
                                              'attribute_filter', $my_filter))}
{else}
 {* fetch without attribute filter *}
 {def $nodeArr = fetch('content', 'tree', hash('parent_node_id', $fetch_parent_id))}
{/if}

Hope that this is what you were trying to achieve

Greetings from Luxembourg

Claudia

Norman Leutner

Sunday 03 September 2006 5:01:36 am

Thanks Claudia for the idea of creating a filter array.
I think this helps shortening the code very well...

 

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Brendan Pike

Sunday 03 September 2006 7:27:59 pm

Thank you for taking the time Claudia, that certainly helped me create a far cleaner / faster and more flexible code. I noticed your other thread on specific date fetching too, I'll be trying to implement that for a show all from August type thing soon. Very valuable posts :)

www.dbinformatics.com.au

We are always interested in hearing from experienced eZ PHP programmers and eZ template designers interested in contract work.

You must be logged in to post messages in this topic!

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