mgd_walk_page_tree

(Midgard 1.4.2 'Bifrost')

mgd_walk_page_tree -- Walk a page tree

Description

bool mgd_walk_page_tree (string func, int root, int maxlevel, mixed &xparam, bool [order])

Minimum version: Midgard 1.4 (Bifrost)

Walks the page tree starting at the page record with id root to a level of maxlevel deep. for each page the user defined function func is called. Parameters to this function will be: id, the id of the page currently being walked, level , the level of descendance from the root level, &xparam, a variable passed through by the user. If order is FALSE, each page will be process after all its children. If set to TRUE, each page will be processed before its children.

Returns TRUE if successful. Returns FALSE on failure.


<?php
   $TESTER_ADDRESS = "root@localhost"; /* Address of tester */
   
   function addname($id, $level, &$xparam) {
       $page = mgd_get_page($id);
       for($i=0; $i<$level; $i++) $xparam .= "   ";
       $xparam .= $page->name." [$id, $page->up]\n";
       return true;
   }

   $str1  = "Ex.1. - Imitate copying:\n";
   mgd_walk_page_tree('addname', 0, 0, &$str1);
   
   $str1 .= "\nEx.2. - Imitate deleting:\n";
   mgd_walk_page_tree('addname', 0, 0, &$str1, false);

   $str1 .= "\nEx.3. - Imitate copying no deeper second level after root:\n";
   mgd_walk_page_tree('addname', 0, 2, &$str1);

   $str1 .= "\nEx.4. - Imitate deletion of all elements deeper second level:\n";
   mgd_walk_page_tree('addname', 0, -2, &$str1, false);
   
   /* Send results to tester */
   mgd_create_mail("root",$TESTER_ADDRESS,"Test",$str1)
?>