Ignore:
Timestamp:
Jun 3, 2006 7:47:48 PM (18 years ago)
Author:
scdev
Message:

Q - Merged branches/2.0singleton into trunk. Completed updating classes to use singleton methods. Implemented tests. Fixed some bugs. Changed some interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Hierarchy.inc.php

    r111 r136  
    22/**
    33 * Hierarchy.inc.php
    4  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    5  */
    6 
    7 /**
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    86 * Objective: This class provides the tools to organize pieces of data into a
    97 * hierarchy of nodes. Any form of data (article, product, image) can be
     
    9795    function toStringID($child_type=null, $child_id=null)
    9896    {
    99         if (!isset($child_type) || !isset($child_id)) {
    100             if ($this->node_init) {
    101                 $child_type =& $this->child_type;
    102                 $child_id =& $this->child_id;
    103             } else {
    104                 App::logMsg(_("toStringID failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     97            $app =& App::getInstance();
     98   
     99            if (!isset($child_type) || !isset($child_id)) {
     100            if ($this->node_init) {
     101                $child_type =& $this->child_type;
     102                $child_id =& $this->child_id;
     103            } else {
     104                $app->logMsg(_("toStringID failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    105105                return false;
    106106            }
     
    129129    function toArrayID(&$node)
    130130    {
    131         if (preg_match('/^([[:alnum:]]+)__-?([[:digit:]]+)$/', $node, $node_parts)) {
     131            $app =& App::getInstance();
     132   
     133            if (preg_match('/^([[:alnum:]]+)__-?([[:digit:]]+)$/', $node, $node_parts)) {
    132134            return array('node_type' => $node_parts[1], 'node_id' => $node_parts[2]);
    133135        } else {
    134             App::logMsg(_("Cannot parse node identifier, not formated correctly."), LOG_ERR, __FILE__, __LINE__);
     136            $app->logMsg(_("Cannot parse node identifier, not formated correctly."), LOG_ERR, __FILE__, __LINE__);
    135137            return false;
    136138        }
     
    147149    function insertNode($parents, $child_type=null, $child_id=null, $relationship_type=null, $title='')
    148150    {
     151        $app =& App::getInstance();
     152        $db =& DB::getInstance();
     153   
    149154        if (!isset($child_type) || !isset($child_id)) {
    150155            if ($this->node_init) {
     
    152157                $child_id =& $this->child_id;
    153158            } else {
    154                 App::logMsg(_("insertNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     159                $app->logMsg(_("insertNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    155160                return false;
    156161            }
     
    159164        // Make sure this is not empty and an array, even if it has only one value.
    160165        if ('' == $parents) {
    161             App::raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__);
    162             App::logMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__);
     166            $app->raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__);
     167            $app->logMsg(sprintf(_("Cannot add node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__);
    163168            return false;
    164169        } else if (!is_array($parents)) {
     
    174179            $parent = $this->toArrayID($parent_string);
    175180            if ($this->nodeExists($child_type, $child_id, $parent['node_type'], $parent['node_id'], $relationship_type)) {
    176                 App::raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
    177                 App::logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
     181                $app->raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
     182                $app->logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to parent <strong>%s %s</strong>. It already exists there"), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
    178183                return false;
    179184            }
    180185            if (!$this->nodeExists($parent['node_type'], $parent['node_id'])) {
    181                 App::raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
    182                 App::logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
     186                $app->raiseMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
     187                $app->logMsg(sprintf(_("Cannot add node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
    183188                return false;
    184189            }
     
    188193        foreach ($parents as $parent_string) {
    189194            $parent = $this->toArrayID($parent_string);
    190             DB::query("
     195            $db->query("
    191196                INSERT INTO node_tbl (
    192197                    parent_type,
     
    197202                    title
    198203                ) VALUES (
    199                     '" . DB::escapeString($parent['node_type']) . "',
    200                     '" . DB::escapeString($parent['node_id']) . "',
    201                     '" . DB::escapeString($child_type) . "',
    202                     '" . DB::escapeString($child_id) . "',
    203                     " . (is_null($relationship_type) ? "NULL" : "'" . DB::escapeString($relationship_type) . "'") . ",
    204                     '" . DB::escapeString($title) . "'
     204                    '" . $db->escapeString($parent['node_type']) . "',
     205                    '" . $db->escapeString($parent['node_id']) . "',
     206                    '" . $db->escapeString($child_type) . "',
     207                    '" . $db->escapeString($child_id) . "',
     208                    " . (is_null($relationship_type) ? "NULL" : "'" . $db->escapeString($relationship_type) . "'") . ",
     209                    '" . $db->escapeString($title) . "'
    205210                )
    206211            ");
    207             App::logMsg(sprintf('insertNode: Added node %s %s with parent %s %s.', $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_DEBUG, __FILE__, __LINE__);
     212            $app->logMsg(sprintf('insertNode: Added node %s %s with parent %s %s.', $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_DEBUG, __FILE__, __LINE__);
    208213        }
    209214        return true;
     
    223228    function deleteNode($child_type=null, $child_id=null)
    224229    {
     230        $app =& App::getInstance();
     231        $db =& DB::getInstance();
     232   
    225233        if (!isset($child_type) || !isset($child_id)) {
    226234            if ($this->node_init) {
     
    228236                $child_id =& $this->child_id;
    229237            } else {
    230                 App::logMsg(_("deleteNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     238                $app->logMsg(_("deleteNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    231239                return false;
    232240            }
     
    243251        }
    244252
    245         DB::query("
     253        $db->query("
    246254            DELETE FROM node_tbl
    247             WHERE child_type = '" . DB::escapeString($child_type) . "'
    248             AND child_id = '" . DB::escapeString($child_id) . "'
     255            WHERE child_type = '" . $db->escapeString($child_type) . "'
     256            AND child_id = '" . $db->escapeString($child_id) . "'
    249257        ");
    250         App::logMsg(sprintf('deleteNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     258        $app->logMsg(sprintf('deleteNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
    251259
    252260        return true;
     
    270278    function moveNode($new_parents=null, $child_type=null, $child_id=null, $relationship_type=null, $title='')
    271279    {
    272         if (!isset($child_type) || !isset($child_id)) {
    273             if ($this->node_init) {
    274                 $child_type =& $this->child_type;
    275                 $child_id =& $this->child_id;
    276             } else {
    277                 App::logMsg(_("moveNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     280            $app =& App::getInstance();
     281            $db =& DB::getInstance();
     282
     283            if (!isset($child_type) || !isset($child_id)) {
     284            if ($this->node_init) {
     285                $child_type =& $this->child_type;
     286                $child_id =& $this->child_id;
     287            } else {
     288                $app->logMsg(_("moveNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    278289                return false;
    279290            }
     
    282293        // Make sure this is not empty and an array, even if it has only one value.
    283294        if (empty($new_parents)) {
    284             App::raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__);
    285             App::logMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__);
     295            $app->raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), MSG_ERR, __FILE__, __LINE__);
     296            $app->logMsg(sprintf(_("Cannot move node <strong>%s %s</strong>, no parent was specified."), $child_type, $child_id), LOG_ERR, __FILE__, __LINE__);
    286297            return false;
    287298        } else if (!is_array($new_parents)) {
     
    296307            $parent = $this->toArrayID($parent_string);
    297308            if (!$this->nodeExists($parent['node_type'], $parent['node_id'])) {
    298                 App::raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
    299                 App::logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
     309                $app->raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
     310                $app->logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to nonexistent parent <strong>%s %s</strong>."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
    300311                return false;
    301312            }
    302313            if ($this->isAncestor($child_type, $child_id, $parent['node_type'], $parent['node_id'])) {
    303                 App::raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
    304                 App::logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
     314                $app->raiseMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), MSG_ERR, __FILE__, __LINE__);
     315                $app->logMsg(sprintf(_("Cannot move node <strong>%s %s</strong> to parent <strong>%s %s</strong> because a node cannot have itself as a parent."), $child_type, $child_id, $parent['node_type'], $parent['node_id']), LOG_ERR, __FILE__, __LINE__);
    305316                return false;
    306317            }
     
    309320        if (empty($title)) {
    310321            // Select the title of the node we are moving, so we can add it again with the same info.
    311             $qid = DB::query("
     322            $qid = $db->query("
    312323                SELECT title FROM node_tbl
    313                 WHERE child_type = '" . DB::escapeString($child_type) . "'
    314                 AND child_id = '" . DB::escapeString($child_id) . "'
    315                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
     324                WHERE child_type = '" . $db->escapeString($child_type) . "'
     325                AND child_id = '" . $db->escapeString($child_id) . "'
     326                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . "
    316327            ");
    317328            list($title) = mysql_fetch_row($qid);
     
    319330
    320331        // Delete the nodes with the old parents.
    321         DB::query("
     332        $db->query("
    322333            DELETE FROM node_tbl
    323             WHERE child_type = '" . DB::escapeString($child_type) . "'
    324             AND child_id = '" . DB::escapeString($child_id) . "'
    325             AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
     334            WHERE child_type = '" . $db->escapeString($child_type) . "'
     335            AND child_id = '" . $db->escapeString($child_id) . "'
     336            AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . "
    326337        ");
    327         App::logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     338        $app->logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
    328339
    329340        // Insert new nodes with the new parents.
     
    344355    function getParents($child_type=null, $child_id=null, $type_constraint=null, $order='')
    345356    {
     357        $app =& App::getInstance();
     358        $db =& DB::getInstance();
     359   
    346360        if (!isset($child_type) || !isset($child_id)) {
    347361            if ($this->node_init) {
     
    349363                $child_id =& $this->child_id;
    350364            } else {
    351                 App::logMsg(_("getParents failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     365                $app->logMsg(_("getParents failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    352366                return false;
    353367            }
     
    359373                $type_constraint = array($type_constraint);
    360374            }
    361             $in_clause = "AND parent_type IN ('" . join("','", array_map(array('DB', 'escapeString'), $type_constraint)) . "')";
    362         }
    363 
    364         $qid = DB::query("
     375            $in_clause = "AND parent_type IN ('" . join("','", array_map(array($db, 'escapeString'), $type_constraint)) . "')";
     376        }
     377
     378        $qid = $db->query("
    365379            SELECT parent_type, parent_id
    366380            FROM node_tbl
    367             WHERE child_type = '" . DB::escapeString($child_type) . "'
    368             AND child_id = '" . DB::escapeString($child_id) . "'
     381            WHERE child_type = '" . $db->escapeString($child_type) . "'
     382            AND child_id = '" . $db->escapeString($child_id) . "'
    369383            $in_clause
    370             " . DB::escapeString($order) . "
     384            " . $db->escapeString($order) . "
    371385        ");
    372386
     
    392406    function getNode($child_type=null, $child_id=null)
    393407    {
     408        $app =& App::getInstance();
     409        $db =& DB::getInstance();
     410   
    394411        if (!isset($child_type) || !isset($child_id)) {
    395412            if ($this->node_init) {
     
    397414                $child_id =& $this->child_id;
    398415            } else {
    399                 App::logMsg(_("getNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    400                 return false;
    401             }
    402         }
    403 
    404         $qid = DB::query("
     416                $app->logMsg(_("getNode failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     417                return false;
     418            }
     419        }
     420
     421        $qid = $db->query("
    405422            SELECT child_type, child_id, title, subnode_quantity
    406423            FROM node_tbl
    407             WHERE child_type = '" . DB::escapeString($child_type) . "'
    408             AND child_id = '" . DB::escapeString($child_id) . "'
     424            WHERE child_type = '" . $db->escapeString($child_type) . "'
     425            AND child_id = '" . $db->escapeString($child_id) . "'
    409426        ");
    410427
     
    433450    function getChildren($child_type=null, $child_id=null, $type_constraint=null, $order='')
    434451    {
     452        $app =& App::getInstance();
     453        $db =& DB::getInstance();
     454   
    435455        if (!isset($child_type) || !isset($child_id)) {
    436456            if ($this->node_init) {
     
    438458                $child_id =& $this->child_id;
    439459            } else {
    440                 App::logMsg(_("getChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     460                $app->logMsg(_("getChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    441461                return false;
    442462            }
     
    448468                $type_constraint = array($type_constraint);
    449469            }
    450             $in_clause = "AND child_type IN ('" . join("','", array_map(array('DB', 'escapeString'), $type_constraint)) . "')";
    451         }
    452 
    453         $qid = DB::query("
     470            $in_clause = "AND child_type IN ('" . join("','", array_map(array($db, 'escapeString'), $type_constraint)) . "')";
     471        }
     472
     473        $qid = $db->query("
    454474            SELECT *
    455475            FROM node_tbl
    456             WHERE parent_type = '" . DB::escapeString($child_type) . "'
    457             AND parent_id = '" . DB::escapeString($child_id) . "'
     476            WHERE parent_type = '" . $db->escapeString($child_type) . "'
     477            AND parent_id = '" . $db->escapeString($child_id) . "'
    458478            $in_clause
    459             " . DB::escapeString($order) . "
     479            " . $db->escapeString($order) . "
    460480        ");
    461481
     
    482502    function getNumberChildren($child_type=null, $child_id=null, $type_constraint=null)
    483503    {
     504        $app =& App::getInstance();
     505        $db =& DB::getInstance();
     506
    484507        if (!isset($child_type) || !isset($child_id)) {
    485508            if ($this->node_init) {
     
    487510                $child_id =& $this->child_id;
    488511            } else {
    489                 App::logMsg(_("getNumberChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     512                $app->logMsg(_("getNumberChildren failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    490513                return false;
    491514            }
     
    497520                $type_constraint = array($type_constraint);
    498521            }
    499             $in_clause = "AND child_type IN ('" . join("','", array_map(array('DB', 'escapeString'), $type_constraint)) . "')";
    500         }
    501 
    502         $qid = DB::query("
     522            $in_clause = "AND child_type IN ('" . join("','", array_map(array($db, 'escapeString'), $type_constraint)) . "')";
     523        }
     524
     525        $qid = $db->query("
    503526            SELECT COUNT(*)
    504527            FROM node_tbl
    505             WHERE parent_type = '" . DB::escapeString($child_type) . "'
    506             AND parent_id = '" . DB::escapeString($child_id) . "'
     528            WHERE parent_type = '" . $db->escapeString($child_type) . "'
     529            AND parent_id = '" . $db->escapeString($child_id) . "'
    507530            $in_clause
    508531        ");
     
    520543    function isLeaf($child_type=null, $child_id=null)
    521544    {
     545        $app =& App::getInstance();
     546   
    522547        if (!isset($child_type) || !isset($child_id)) {
    523548            if ($this->node_init) {
     
    525550                $child_id =& $this->child_id;
    526551            } else {
    527                 App::logMsg(_("isLeaf failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     552                $app->logMsg(_("isLeaf failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    528553                return false;
    529554            }
     
    579604    function getAllAncestors($child_type, $child_id, $go_linear=false, $_return_flag=true)
    580605    {
     606        $db =& DB::getInstance();
     607   
    581608        static $output = array();
    582609        static $return_flag;
    583610
    584         $qid = DB::query("
     611        $qid = $db->query("
    585612            SELECT parent_type, parent_id, child_type, child_id, title, subnode_quantity
    586613            FROM node_tbl
    587             WHERE child_type = '" . DB::escapeString($child_type) . "'
    588             AND child_id = '" . DB::escapeString($child_id) . "'
     614            WHERE child_type = '" . $db->escapeString($child_type) . "'
     615            AND child_id = '" . $db->escapeString($child_id) . "'
    589616        ");
    590617        while ($row = mysql_fetch_assoc($qid)) {
     
    631658    function nodeExists($child_type=null, $child_id=null, $parent_type=null, $parent_id=null, $relationship_type=null)
    632659    {
     660        $app =& App::getInstance();
     661        $db =& DB::getInstance();
     662   
    633663        if (!isset($child_type) || !isset($child_id)) {
    634664            if ($this->node_init) {
     
    636666                $child_id =& $this->child_id;
    637667            } else {
    638                 App::logMsg(_("nodeExists failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     668                $app->logMsg(_("nodeExists failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    639669                return false;
    640670            }
     
    642672
    643673        if (isset($parent_type) && isset($parent_id)) {
    644             $qid = DB::query("
     674            $qid = $db->query("
    645675                SELECT 1 FROM node_tbl
    646                 WHERE parent_type = '" . DB::escapeString($parent_type) . "'
    647                 AND parent_id = '" . DB::escapeString($parent_id) . "'
    648                 AND child_type = '" . DB::escapeString($child_type) . "'
    649                 AND child_id = '" . DB::escapeString($child_id) . "'
    650                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
     676                WHERE parent_type = '" . $db->escapeString($parent_type) . "'
     677                AND parent_id = '" . $db->escapeString($parent_id) . "'
     678                AND child_type = '" . $db->escapeString($child_type) . "'
     679                AND child_id = '" . $db->escapeString($child_id) . "'
     680                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . $db->escapeString($relationship_type) . "'") . "
    651681            ");
    652682        } else {
    653             $qid = DB::query("
     683            $qid = $db->query("
    654684                SELECT 1 FROM node_tbl
    655                 WHERE child_type = '" . DB::escapeString($child_type) . "'
    656                 AND child_id = '" . DB::escapeString($child_id) . "'
     685                WHERE child_type = '" . $db->escapeString($child_type) . "'
     686                AND child_id = '" . $db->escapeString($child_id) . "'
    657687            ");
    658688        }
     
    680710    function &getNodeList($preselected=null, $child_type=null, $child_id=null, $type_constraint=null, $include_curr=false, $order='', $_indent=0, $_return_flag=true)
    681711    {
     712        $app =& App::getInstance();
     713   
    682714        static $output = array();
    683715        static $is_a_leaf = array();
     
    688720                $child_id =& $this->child_id;
    689721            } else {
    690                 App::logMsg(_("getNodeList failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
     722                $app->logMsg(_("getNodeList failed. Arguments not specified properly."), LOG_ERR, __FILE__, __LINE__);
    691723                return false;
    692724            }
     
    709741                // Preventing circular references.
    710742                if ($my_children[$i]['child_type'] == $child_type && $my_children[$i]['child_id'] == $child_id && !($_return_flag && $include_curr)) {
    711                     App::logMsg(sprintf(_("Circular reference detected: %s has itself as a parent."), $this->toStringID($my_children[$i]['child_type'], $my_children[$i]['child_id'])), LOG_ERR, __FILE__, __LINE__);
     743                    $app->logMsg(sprintf(_("Circular reference detected: %s has itself as a parent."), $this->toStringID($my_children[$i]['child_type'], $my_children[$i]['child_id'])), LOG_ERR, __FILE__, __LINE__);
    712744                    continue;
    713745                }
     
    751783    function rebuildSubnodeQty($type_constraint=null)
    752784    {
     785        $db =& DB::getInstance();
     786   
    753787        // Reset all the category counters to zero.
    754         DB::query("UPDATE node_tbl SET subnode_quantity = 0");
     788        $db->query("UPDATE node_tbl SET subnode_quantity = 0");
    755789
    756790        // Get all the nodes.
    757         $qid = DB::query("SELECT DISTINCT child_type, child_id FROM node_tbl");
     791        $qid = $db->query("SELECT DISTINCT child_type, child_id FROM node_tbl");
    758792
    759793        // For each node count the number of children...
     
    773807    function setSubnodeQtyToParents($child_type, $child_id, $num_children)
    774808    {
    775         DB::query("
     809        $db =& DB::getInstance();
     810   
     811        $db->query("
    776812            UPDATE node_tbl
    777             SET subnode_quantity = subnode_quantity + '" . DB::escapeString($num_children) . "'
    778             WHERE child_type = '" . DB::escapeString($child_type) . "'
    779             AND child_id = '" . DB::escapeString($child_id) . "'
     813            SET subnode_quantity = subnode_quantity + '" . $db->escapeString($num_children) . "'
     814            WHERE child_type = '" . $db->escapeString($child_type) . "'
     815            AND child_id = '" . $db->escapeString($child_id) . "'
    780816        ",false);
    781         $qid = DB::query("
     817        $qid = $db->query("
    782818            SELECT parent_type, parent_id
    783819            FROM node_tbl
    784             WHERE child_type = '" . DB::escapeString($child_type) . "'
    785             AND child_id = '" . DB::escapeString($child_id) . "'
     820            WHERE child_type = '" . $db->escapeString($child_type) . "'
     821            AND child_id = '" . $db->escapeString($child_id) . "'
    786822        ",false);
    787823        while ((list($parent_type, $parent_id) = mysql_fetch_row($qid)) && $parent_id > 0) {
Note: See TracChangeset for help on using the changeset viewer.