Category List Control

6 posts by 2 authors in: Forums > CMS Builder
Last Post: February 25, 2010   (RSS)

By Perchpole - February 24, 2010

Here's a quickie, gang.

I'm starting to make good use of the list category controls - in particular the '_isSelectedBranch' and '_isSelected' queries.

However, what is the simplest/most efficient method to ask if a record 'has a Parent' or 'has a Child'

:0)

Perchpole

Re: [Perchpole] Category List Control

By Dave - February 24, 2010

Hi Perch,

Interesting... How are you using this? Or how do you want to use it?

The "has a parent" you could determine by checking if depth isn't 0. If that depth isn't zero it means it has a parent.

The child one I'd have to think about. Let me know some more details and I'll see what I can come up with.
Dave Edis - Senior Developer
interactivetools.com

Re: [Perchpole] Category List Control

By Dave - February 25, 2010

Hi Perch,

If I added fields for: _hasParent and _hasChild would that work? _hasParent would be the same as !$record['parent'] though since only root nodes wouldn't have parents, but it would be more readable.

Also, check out this function in /lib/viewer_functions.php for moving between records:

// Supported options: tableName (required), recordNum (optional), and
// ... orderBy (optional, defaults to schema listPageOrder)
list($prevRecord, $nextRecord, $firstRecord, $lastRecord) = getPrevAndNextRecords(array(
'tableName' => 'news',
'recordNum' => $record['num'],
'orderBy' => 'createdDate', // optional - defaults to schema listPageOrder
));

Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Category List Control

By Perchpole - February 25, 2010

Hi, Dave -

Sounds perfect. You've suggested exactly what I was hoping for!

Thanks (again!)

:0)

Perch

Re: [Perchpole] Category List Control

By Dave - February 25, 2010

Try this to add _hasChild and _hasParent:

- Open /lib/viewer_functions.php
- Search for: remove categories
- Add the code in red _above_ that line:
// get array of category nums with children
$categoryNumHasChildren = array();
foreach ($categoryRecords as $record) { $categoryNumHasChildren[ $record['parentNum'] ] = 1; }

// remove categories we aren't displaying


- Then search for: _isBreadcrumb
- And add the code in red _below_ that line:
$category['_isBreadcrumb'] = $category['_isDescendantSelected'] || $category['_isSelected'];

$category['_hasParent'] = (int) ($category['parentNum'] != 0);
$category['_hasChild'] = (int) @$categoryNumHasChildren[ $category['num'] ];


Hope that helps! Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com