Changeset 91 for branches/1.1dev/lib


Ignore:
Timestamp:
Apr 9, 2006 3:39:08 AM (18 years ago)
Author:
scdev
Message:

added tree functions to print nested <li>

Location:
branches/1.1dev/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/Hierarchy.inc.php

    r90 r91  
    354354                $child_id =& $this->child_id;
    355355            } else {
    356                 logMsg(_("getParents failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     356                logMsg(_("getParents failed. Arguments not specified properly."), resource_tbl, __FILE__, __LINE__);
    357357                return false;
    358358            }
     
    402402                $child_id =& $this->child_id;
    403403            } else {
    404                 logMsg(_("getNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     404                logMsg(_("getNode failed. Arguments not specified properly."), resource_tbl, __FILE__, __LINE__);
    405405                return false;
    406406            }
     
    408408       
    409409        $qid = dbQuery("
    410             SELECT child_type, child_id, title, subnode_quantity
     410            SELECT *
    411411            FROM node_tbl
    412412            WHERE child_type = '" . mysql_real_escape_string($child_type) . "'
     
    443443                $child_id =& $this->child_id;
    444444            } else {
    445                 logMsg(_("getChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     445                logMsg(_("getChildren failed. Arguments not specified properly."), resource_tbl, __FILE__, __LINE__);
    446446                return false;
    447447            }
     
    492492                $child_id =& $this->child_id;
    493493            } else {
    494                 logMsg(_("getNumberChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     494                logMsg(_("getNumberChildren failed. Arguments not specified properly."), resource_tbl, __FILE__, __LINE__);
    495495                return false;
    496496            }
     
    530530                $child_id =& $this->child_id;
    531531            } else {
    532                 logMsg(_("isLeaf failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     532                logMsg(_("isLeaf failed. Arguments not specified properly."), resource_tbl, __FILE__, __LINE__);
    533533                return false;
    534534            }
     
    641641                $child_id =& $this->child_id;
    642642            } else {
    643                 logMsg(_("nodeExists failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     643                logMsg(_("nodeExists failed. Arguments not specified properly."), resource_tbl, __FILE__, __LINE__);
    644644                return false;
    645645            }
     
    748748    }
    749749   
    750     function convertListToTree($curr, $child_type=null, $child_id=null, $_return_flag=true)
     750    function convertListToTree($curr, $child_type=null, $child_id=null, $_indent=0)
    751751    {
    752752        if (!is_array($curr) || empty($curr)) {
     
    757757        static $children_map;
    758758        static $node_map;
    759        
     759
    760760        // The original $curr contains the full list. Save a copy of this.
    761761        if (!isset($orig)) {
     
    765765            $children_map = array();
    766766            foreach ($orig as $i => $n) {
    767                 $n_parent = $this->toStringID($n['parent_type'], $n['parent_id']);
     767                $n_parent = ('' != $n['parent_type'] && '' != $n['parent_id']) ? $this->toStringID($n['parent_type'], $n['parent_id']) : 'null__00';
    768768                $n_child = $this->toStringID($n['child_type'], $n['child_id']);
    769769                $children_map[$n_parent][] = $n_child;
     
    786786            }
    787787        }
    788        
     788
     789        if (!isset($curr['indent'])) {
     790            $curr['indent'] = $_indent;
     791        }
     792
    789793        // Get children of current node.
    790794        $curr_str_id = $this->toStringID($curr['child_type'], $curr['child_id']);
     
    794798        if (!empty($curr_children)) {
    795799            foreach ($curr_children as $child) {
    796                 $curr['children'][] = $this->convertListToTree($orig[$node_map[$child]], null, null, false);
    797             }
    798         }
    799        
    800         if ($_return_flag) {
     800                $curr['children'][] = $this->convertListToTree($orig[$node_map[$child]], null, null, $_indent + 1);
     801            }
     802        }
     803       
     804        if ($_indent === 0) {
    801805            // We must reset the static variables so that they do
    802806            // not fill up during subsequent function calls.
  • branches/1.1dev/lib/ScriptTimer.inc.php

    r90 r91  
    77class ScriptTimer {
    88
    9     var $time_format = '%.10f';
    10     var $_timing_start_times;
    11     var $_timing_stop_times;
     9    var $time_format = '%.10s';
     10    var $_timing_start_times = array();
     11    var $_timing_stop_times = array();
     12    var $_timing_cumulative_times = array();
    1213   
    13     function start ($name = 'default') {
     14    function start($name='default') {
    1415        $this->_timing_start_times[$name] = explode(' ', microtime());
    1516    }
    1617   
    17     function stop($name = 'default') {
    18         $this->_timing_stop_times[$name] = explode(' ', microtime());
     18    function stop($name='default') {
     19        $this->_timing_cumulative_times[$name] += $this->getTime($name);
    1920    }
    2021   
    21     function getTime($name = 'default') {
     22    function getTime($name='default') {
    2223        if (!isset($this->_timing_start_times[$name])) {
    2324            return 0;
     
    3132        $current = $stop_time[1] - $this->_timing_start_times[$name][1];
    3233        $current += $stop_time[0] - $this->_timing_start_times[$name][0];
    33         return sprintf($this->time_format, $current);
     34        return $current;
     35    }
     36   
     37    function printAll($sort_by_time=false)
     38    {
     39        $names = array_map('strlen', array_keys($this->_timing_start_times));
     40        sort($names);
     41        $name_len = end($names);
     42       
     43        if ($sort_by_time) {
     44           arsort($this->_timing_cumulative_times, SORT_NUMERIC);
     45        }
     46       
     47        $this->_timing_cumulative_times["TOTAL"] = array_sum($this->_timing_cumulative_times);
     48
     49        echo '<pre>';
     50        foreach ($this->_timing_cumulative_times as $name => $time) {
     51            printf("\n%-{$name_len}s $this->time_format", $name, $time);
     52        }
     53        echo '</pre>';
    3454    }
    3555}
Note: See TracChangeset for help on using the changeset viewer.