if you want to rename all of the chapters persistently (which means to save the changes in the DB too) then you could do the following
for the Memory_* way this will work
function _walkTree($node)
{
global $tree,$levels;
$curLevel = $node['level'];
if (!isset($levels[$curLevel])) {
$levels[$curLevel] = 1;
} else {
$levels[$curLevel]++;
}
$tree->update('name'=>implode('.',$levels).$node['name']);
i forgot the first parameter, the 'id' here i think
$tree->update($node['id'],'name'=>implode('.',$levels).$node['name']);
}
$levels = array();
$tree->walk('_walkTree');
// and rebuild the internal tree structure again, might not
// be necessary since the structure has not changed
$tree->setup();
try this, it could work :-) i just hacked it down here in this mail. i have not tested it!!! if something doesnt work, let me know. but this is the way to go.
Hi Wolfram,
Well it almost worked instantly, very cool. I only had to make somes minor changes (I would have very been impressed if you had written flawless code just in your email client ;-)
Anyway the biggest problem is that I don't want to save the data to the DB. It's just for display purposes. Can I do that? I just want to change the array, not save any changes to the datasource. Or is that something I should just take care of myself, something that should not be the responsibility of the PEAR::Tree class?
Cheers
Jeroen