Manually writing to Category tables

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 2, 2010   (RSS)

From past projects, I know exactly what needs to be written to standard multi-article tables, but now I have a need to write records to a category table based on what a user enters.

Can you please tell me what / how I need to write these?

I'm concerned about the _globalOrder, _siblingOrder and _lineage fields.

Thank you.
Gary.

Re: [garyhoffmann] Manually writing to Category tables

By Chris - August 2, 2010

Hi Gary,

Wow, that's a tricky one. This is outside of what we normally offer for support, but I thought I'd try to help you out! :)

We have a utility function you can call which should sort everything out. Insert your new record with the parentCategory field filled out and bogus values (see below) for the special category fields, then call updateCategoryMetadata().

When you INSERT, I think you'll want to set the category fields like this:

globalOrder = 0,
siblingOrder = 99999999,
lineage = '',
depth = 0,
breadcrumb = ''


Then, immediately after inserting, call the function to set those values. Note that you'll need to set some globals first before you call this function:

global $escapedTableName, $schema;
$escapedTableName = mysql_escape( getTableNameWithPrefix('my_category_table') );
$schema = loadSchema('my_category_table');
updateCategoryMetadata();


I've tested this out here and it seems to work. I hope it works for you too!
All the best,
Chris