Ignore:
Timestamp:
Dec 18, 2005 12:16:03 AM (18 years ago)
Author:
scdev
Message:

detabbed all files ;P

File:
1 edited

Legend:

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

    r41 r42  
    11<?php
    22/**
    3  * NodeHeirarchy.inc.php 
     3 * NodeHeirarchy.inc.php
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    55 */
     
    2323 * @version   1.0
    2424 */
    25  
     25
    2626class NodeHeirarchy {
    2727
     
    5050
    5151    /**
    52      * Boolean indicating whether or not we've set 
     52     * Boolean indicating whether or not we've set
    5353     * the 'active' node type and id.
    5454     * @var bool $node_init
    5555     */
    5656    var $node_init = false;
    57    
     57
    5858    /**
    5959     * Constructor
     
    6666        $this->params = $params;
    6767    }
    68    
     68
    6969    /**
    7070     * Defines the default child_type and child_id for this object.
     
    8585        return $this->toStringID($old_type, $old_id);
    8686    }
    87    
     87
    8888    /**
    8989     * Takes a node type and id and returns them as a serialized identifier like
     
    121121        }
    122122    }
    123    
     123
    124124    /**
    125125     * Takes a singlar node identifier and returns it as components of an array.
     
    156156            }
    157157        }
    158        
     158
    159159        // Make sure this is not empty and an array, even if it has only one value.
    160160        if ('' == $parents) {
     
    165165            $parents = array($parents);
    166166        }
    167        
     167
    168168        // Remove duplicates.
    169169        $parents = array_unique($parents);
    170                
     170
    171171        // Test that this node does not already exist and that the new parents
    172172        // do exist before we continue.
     
    182182                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__);
    183183                return false;
    184             }   
    185         }
    186        
     184            }
     185        }
     186
    187187        // Insert new nodes with the new parents.
    188188        foreach ($parents as $parent_string) {
     
    190190            DB::query("
    191191                INSERT INTO node_tbl (
    192                     parent_type, 
    193                     parent_id, 
    194                     child_type, 
    195                     child_id, 
     192                    parent_type,
     193                    parent_id,
     194                    child_type,
     195                    child_id,
    196196                    relationship_type,
    197197                    title
    198198                ) VALUES (
    199                     '" . addslashes($parent['node_type']) . "', 
    200                     '" . addslashes($parent['node_id']) . "', 
    201                     '" . addslashes($child_type) . "', 
    202                     '" . addslashes($child_id) . "', 
     199                    '" . addslashes($parent['node_type']) . "',
     200                    '" . addslashes($parent['node_id']) . "',
     201                    '" . addslashes($child_type) . "',
     202                    '" . addslashes($child_id) . "',
    203203                    " . (is_null($relationship_type) ? "NULL" : "'" . addslashes($relationship_type) . "'") . ",
    204204                    '" . addslashes($title) . "'
     
    267267     *
    268268     * @return bool      false on error, true otherwise.
    269      */     
     269     */
    270270    function moveNode($new_parents=null, $child_type=null, $child_id=null, $relationship_type=null, $title='')
    271271    {
     
    279279            }
    280280        }
    281        
     281
    282282        // Make sure this is not empty and an array, even if it has only one value.
    283283        if (empty($new_parents)) {
     
    288288            $new_parents = array($new_parents);
    289289        }
    290        
     290
    291291        // Remove duplicates.
    292292        $new_parents = array_unique($new_parents);
     
    299299                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__);
    300300                return false;
    301             }   
     301            }
    302302            if ($this->isAncestor($child_type, $child_id, $parent['node_type'], $parent['node_id'])) {
    303303                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__);
    304304                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__);
    305305                return false;
    306             }   
    307         }
    308        
     306            }
     307        }
     308
    309309        if (empty($title)) {
    310310            // Select the title of the node we are moving, so we can add it again with the same info.
     
    317317            list($title) = mysql_fetch_row($qid);
    318318        }
    319        
     319
    320320        // Delete the nodes with the old parents.
    321321        DB::query("
     
    326326        ");
    327327        App::logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
    328        
     328
    329329        // Insert new nodes with the new parents.
    330330        $this->insertNode($new_parents, $child_type, $child_id, $relationship_type, $title);
    331        
     331
    332332        return true;
    333333    }
     
    356356        $qid = DB::query("
    357357            SELECT parent_type, parent_id
    358             FROM node_tbl 
     358            FROM node_tbl
    359359            WHERE child_type = '" . addslashes($child_type) . "'
    360             AND child_id = '" . addslashes($child_id) . "' 
     360            AND child_id = '" . addslashes($child_id) . "'
    361361        ");
    362        
     362
    363363        $parents = array();
    364364        while ($row = mysql_fetch_assoc($qid)) {
     
    391391            }
    392392        }
    393        
     393
    394394        $qid = DB::query("
    395395            SELECT child_type, child_id, title, subnode_quantity
    396             FROM node_tbl 
     396            FROM node_tbl
    397397            WHERE child_type = '" . addslashes($child_type) . "'
    398398            AND child_id = '" . addslashes($child_id) . "'
    399399        ");
    400        
     400
    401401        $children = array();
    402402        while ($row = mysql_fetch_assoc($qid)) {
     
    432432            }
    433433        }
    434        
     434
    435435        $in_clause = '';
    436436        if (isset($type_constraint)) {
     
    440440            $in_clause = "AND child_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
    441441        }
    442        
     442
    443443        $qid = DB::query("
    444444            SELECT *
    445             FROM node_tbl 
     445            FROM node_tbl
    446446            WHERE parent_type = '" . addslashes($child_type) . "'
    447447            AND parent_id = '" . addslashes($child_id) . "'
     
    449449            " . addslashes($order) . "
    450450        ");
    451        
     451
    452452        $children = array();
    453453        while ($row = mysql_fetch_assoc($qid)) {
     
    464464     * Give the number of children a category has. We are talking about the
    465465     * direct children, on the next level.
    466      * 
     466     *
    467467     * @param string optional $parent The name of the parent from where we begin.
    468468     * @param string $type_constraint  An array of node types to restrict the search to.
     
    481481            }
    482482        }
    483        
     483
    484484        $in_clause = '';
    485485        if (isset($type_constraint)) {
     
    492492        $qid = DB::query("
    493493            SELECT COUNT(*)
    494             FROM node_tbl 
     494            FROM node_tbl
    495495            WHERE parent_type = '" . addslashes($child_type) . "'
    496496            AND parent_id = '" . addslashes($child_id) . "'
     
    519519            }
    520520        }
    521        
     521
    522522        if ($this->getNumberChildren($child_type, $child_id) <= 0) {
    523523            return true;
     
    544544        $family_tree = $this->getAllAncestors($considered_parent_type, $considered_parent_id);
    545545        $family_tree = $this->toStringID($family_tree, -1);
    546        
     546
    547547        if (in_array($this->toStringID($child_type, $child_id), $family_tree)) {
    548548            return true;
     
    571571        static $output = array();
    572572        static $return_flag;
    573        
     573
    574574        $qid = DB::query("
    575575            SELECT parent_type, parent_id, child_type, child_id, title, subnode_quantity
     
    583583                continue;
    584584            }
    585            
     585
    586586            // Build a linear path to root...no wormholes.
    587587            if ($enough_already && $go_linear) {
     
    589589            }
    590590            $enough_already = true;
    591            
     591
    592592            // To prevent duplicates, only add the new found node
    593593            // if not already in the array of ancestors.
     
    596596                $output[] = $row;
    597597            }
    598            
     598
    599599            $this->getAllAncestors($row['parent_type'], $row['parent_id'], $go_linear, false);
    600600        }
     
    630630            }
    631631        }
    632        
     632
    633633        if (isset($parent_type) && isset($parent_id)) {
    634634            $qid = DB::query("
     
    665665     * @param  string  $order            SQL to append to the query of the getChildren
    666666     *                                   call. Ex: 'ORDER BY child_id DESC'
    667      * @return array  Details of from the node table of all nodes below the 
     667     * @return array  Details of from the node table of all nodes below the
    668668     *                specified node: (type, id, title, indent level, selected status)
    669669     */
     
    672672        static $output = array();
    673673        static $is_a_leaf = array();
    674        
     674
    675675        if (!isset($child_type) || !isset($child_id)) {
    676676            if ($this->node_init) {
     
    682682            }
    683683        }
    684        
     684
    685685        if (!is_array($preselected)) {
    686686            $preselected = array($preselected);
    687687        }
    688        
     688
    689689        if ($_return_flag && $include_curr) {
    690690            $my_children = $this->getNode($child_type, $child_id);
     
    709709                $output[] = $row;
    710710                unset($row);
    711                
     711
    712712                // This is so we test if each node is a string only once. We store the result in the is_a_leaf array statically.
    713713                if (!isset($is_a_leaf[$this->toStringID($my_children[$i]['child_type'], $my_children[$i]['child_id'])])) {
     
    731731
    732732    }
    733    
    734    
     733
     734
    735735    /**
    736736     * Counts the number of items linked to each parent node
     
    744744        // Reset all the category counters to zero.
    745745        DB::query("UPDATE node_tbl SET subnode_quantity = 0");
    746        
     746
    747747        // Get all the nodes.
    748748        $qid = DB::query("SELECT DISTINCT child_type, child_id FROM node_tbl");
    749        
     749
    750750        // For each node count the number of children...
    751751        while (list($child_type, $child_id) = mysql_fetch_row($qid)) {
     
    757757        }
    758758    }
    759    
     759
    760760    /**
    761761     * Used internally by setSubnodeQty to add the quantity of subnodes to
     
    772772        $qid = DB::query("
    773773            SELECT parent_type, parent_id
    774             FROM node_tbl 
     774            FROM node_tbl
    775775            WHERE child_type = '" . addslashes($child_type) . "'
    776             AND child_id = '" . addslashes($child_id) . "' 
     776            AND child_id = '" . addslashes($child_id) . "'
    777777        ",false);
    778778        while ((list($parent_type, $parent_id) = mysql_fetch_row($qid)) && $parent_id > 0) {
Note: See TracChangeset for help on using the changeset viewer.