Bucking the Query Filter!

8 posts by 3 authors in: Forums > CMS Builder
Last Post: April 29, 2010   (RSS)

Re: [Perchpole] Bucking the Query Filter!

By Dave - April 19, 2010

Perch,

There's a few options, but let's start with a few questions:

How are you specifying subcategories? Is this a multi-record section or a "category" section?

And are there multiple instances of subcategories in your list or just the provided example (if searching category 3 also include 4 and 5)?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Bucking the Query Filter!

By Perchpole - April 19, 2010

Hi, Dave -

Thanks for your prompt response.

In answer to your questions..

1) The page is a multi-record section which also incorporates a category menu. So there are instances of...

list($categoryRecords, $selectedCategory)...

...and...

list(itemRecords, itemMetaData)...

...at the top of the page


2) Let's assume there will be multiple sub-categories present. That seems to offer the most flexible approach.

:0)

Perch

Re: [Perchpole] Bucking the Query Filter!

By Perchpole - April 20, 2010

Hi, Dave -

Any joy with this one?

:0)

Perch

Re: [Perchpole] Bucking the Query Filter!

By Dave - April 23, 2010

Hi Perch,

Sorry for the delay. Anytime you start working multiple multiple sections it can get a bit tricky and start to require some custom code. I'll try to point you in the right direction.

There's two steps:

First, getting a list of category numbers that you want to select itemRecords from. Here's some sample code for that:

// get category nums of selected branch, eg: 0,3,4,6,7
$selectedCategoryNum = $_REQUEST['category'];
$selectedBranchNums = '0';
foreach ($categoryRecords as $category) {
if ($category['_isSelected'] || $category['_isAncestorSelected']) {
$selectedBranchNums .= ',' . (int) $category['num'];
}
}


Next, passing that to your item list viewer so it only returns items from those categories:

...
'allowSearch' => false,
'where' => " category IN ($selectedBranchNums) ",


And basically you should end up with a WHERE like this: category IN (0,3,4,5,6) that only shows items in those categories.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Bucking the Query Filter!

By Perchpole - April 25, 2010

Dave -

Fantastic. Yet again!

What will I do when I run out of superlatives!

Thanks,

:0)

Perch

Re: [Perchpole] Bucking the Query Filter!

By Perchpole - April 28, 2010

Dave -

Just a quick supplementary question on this issue.

Although your method is perfect for what I want, using means I loose the ability to call pages by their URL...

whereRecordNumberInUrl(1)

I've tried various ways of splicing the two strings together...

category IN ($selectedBranchNums) && whereRecordNumberInUrl(1)

...but nothing seems to work.

Can I have the best of both worlds?

:0/

Perch

Re: [Perchpole] Bucking the Query Filter!

By Jason - April 29, 2010

Hi,

You could try this:

'allowSearch' => false,
'where' => " category IN ($selectedBranchNums) AND num=".whereRecordNumberInUrl(1),


Give that a try.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/