/** * Assign vars to Smarty var, then this var can be used as index of the resource * @param int Id of the section parent * @param int Jumps (level) * @param object Resource (owner) * @param string Smarty var to append * @param string Index number to add (eg. 1.1) * @param bool Indicates if the array will be assigned to Smarty var or not * @param array Reference to an array for fill. * @return empty */ function assignSectionTree($parent = 0, $jumps = 0, AHResource $res, $var = 'index', $number = '', $assign = true, &$array = null) { global $tpl; $db = XoopsDatabaseFactory::getDatabaseConnection(); if (get_class($res) != 'AHResource') { return; } $sql = "SELECT * FROM " . $db->prefix("pa_sections") . " WHERE " . ($res->id() > 0 ? "id_res='" . $res->id() . "' AND" : '') . "\n\t\t\tparent='{$parent}' ORDER BY `order`"; $result = $db->query($sql); $sec = new AHSection(); $i = 1; // Counter $num = 1; while ($row = $db->fetchArray($result)) { $sec->assignVars($row); $link = ah_make_link($res->nameId() . '/' . $sec->nameId()); if ($assign) { $tpl->append($var, array('title' => $sec->title(), 'nameid' => $sec->nameId(), 'jump' => $jumps, 'link' => $link, 'number' => $jumps == 0 ? $num : ($number != '' ? $number . '.' : '') . $i)); } else { $array[] = array('title' => $sec->title(), 'nameid' => $sec->nameId(), 'jump' => $jumps, 'link' => $link, 'number' => $jumps == 0 ? $num : ($number != '' ? $number . '.' : '') . $i); } assignSectionTree($sec->id(), $jumps + 1, $res, $var, ($number != '' ? $number . '.' : '') . $i, $assign, $array); $i++; if ($jumps == 0) { $num++; } } return true; }