rsanchez / dynamo

Makes Dynamic Parameters behave more like the Search module.
http://devot-ee.com/add-ons/dynamo/
10 stars 2 forks source link

2 categories fields, different category groups #10

Closed bcartier closed 11 years ago

bcartier commented 12 years ago

I want to build a Dynamo form to filter entries by 2 different category groups (let's say Locations and Industries category groups).

I set up dynamo:form with 2 select fields (one for Location, on for Industry). Both select fields are named "category[]" but only the second field is filtering the entries, overriding the first (which I expected it might).

Is there a way to have more than one select field contribute to the list of filtered categories in Dynamo?

Thanks Rob!

rsanchez commented 12 years ago

Actually, if they're both named category[], then they will both submit and the second won't override the first. But, by default, categories are summed up and then pipe-delimited, which channel:entries interprets as an OR match. It sounds like you are looking for AND matching. In a future version of Dynamo, I'll be adding a separator param so you can do this:

{exp:dynamo:form separator:category="&"}
rsanchez commented 12 years ago

Added this new feature to the develop branch. Wanna try it out?

bcartier commented 12 years ago

Thanks Rob - you're right my issue was more about the AND vs OR behaviour. I'll try out the develop branch.

-Brent

Rob Sanchez mailto:notifications@github.com 9 August, 2012 8:51 AM

Added this new feature to the develop branch https://github.com/rsanchez/dynamo/tree/develop. Wanna try it out?

— Reply to this email directly or view it on GitHub https://github.com/rsanchez/dynamo/issues/10#issuecomment-7613116.

robsonsobral commented 12 years ago

May I join the chat?

Rob, and if the entries have to be in both groups of categories? Something like (1 || 4 || 6) && (3 || 5 || 7). I was thinking about this and maybe the form tag could be done using an array of arrays. Per example:

    <select name="category[1][]" multiple="multiple">
        <option value="1">Dogs</option>
        <option value="2">Cat</option>
    </select>
    <select name="category[2][]" multiple="multiple">
        <option value="1">Dogs</option>
        <option value="2">Cat</option>
    </select>

If the the post of category was a multidimensional array, the separator wouldn't matter anymore, since, I guess, this is the unique condition that needs all this stuff.

What do you think about?

Thanks for you attention!

rsanchez commented 12 years ago

Unfortunately I'm limited by what channel:entries can do natively, and it can't do (1 || 4 || 6) && (3 || 5 || 7) natively. What if you gave 1, 4, 6 a common parent and ditto for 3, 5, 7 and then use the parent category ids with an and separator?

robsonsobral commented 12 years ago

I'm doing tests on your code right now. Maybe this explain my strange results. Should I give up of this syntax?

And if, instead of parent categories, we pass the ID of the category_group? channel:entries has a category_group parameter. What do you think? Is this case, how could be the syntax of the form? category[category_group][category]?

Changing topics for just one second. What fieldtypes can I use as search? Just the same of dynamic_parameters, right?

rsanchez commented 12 years ago

You can definitely use category_group. The input would look something like:

<select name="category_group[]" multiple="multiple">
        <option value="1">Dogs</option>
        <option value="2">Cat</option>
</select>

You can use any native parameter of channel:entries. search: can work on any custom field that channel:entries works with.

robsonsobral commented 12 years ago

I did some tests. Neither your suggestion or my last one conceptually works. Neither of their cover the need of (id || id || id ) && ( id || id || id ).

Your're right about my first one. I found the issue. On line 2148 of mod.channel.php, there is:

                $csql = "SELECT exp_category_posts.entry_id, exp_category_posts.cat_id ".
                        $sql.
                        $this->EE->functions->sql_andor_string(str_replace('&', '|', $for_sql), 'exp_categories.cat_id');

Dammed, dammed! I really need this.

Thanks, Rob.