Commit:    51faf6f6ecd278c375dfffb935b2828f00b0b43f
Author:    Sobak <[email protected]>         Wed, 6 Aug 2014 09:46:48 +0200
Parents:   c9782aa0d14f4e3648849d2314bb2284f66cf7c0
Branches:  master

Link:       
http://git.php.net/?p=web/bugs.git;a=commitdiff;h=51faf6f6ecd278c375dfffb935b2828f00b0b43f

Log:
Remove dependency on PEAR/Tree package

Changed paths:
  M  README.md
  M  include/functions.php


Diff:
diff --git a/README.md b/README.md
index 93dc3ca..7bf2d07 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,6 @@ Requirements
        - DB_DataObject
        - Text_CAPTCHA_Numeral
        - Text_Diff
-       - Tree
        - HTTP
        - HTTP_Upload
 
@@ -21,7 +20,7 @@ Installation
 ============
 1. Copy `local_config.php.sample` to `local_config.php` and modify accordingly
 2. Install all required packages:
-`pear install MDB2 MDB2#mysql MDB2#mysqli DB_DataObject Text_CAPTCHA_Numeral 
Text_Diff Tree-beta HTTP HTTP_Upload`
+`pear install MDB2 MDB2#mysql MDB2#mysqli DB_DataObject Text_CAPTCHA_Numeral 
Text_Diff HTTP HTTP_Upload`
 3. Import SQL schema from `sql/bugs.sql`
 
 TODO
diff --git a/include/functions.php b/include/functions.php
index a0ef41f..4fa0176 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -202,39 +202,39 @@ function bugs_authenticate (&$user, &$pw, &$logged_in, 
&$user_flags)
  */
 function get_pseudo_packages($project, $return_disabled = true)
 {
-       global $project_types;
-
-       require_once 'Tree/Tree.php';
+       global $dbh, $project_types;
 
+       $pseudo_pkgs = $nodes = $tree = array();
        $where = '1=1';
        $project = strtolower($project);
 
        if ($project !== false && in_array($project, $project_types)) {
-               $where .= " AND project IN ('',  '". $project ."')";
+               $where .= " AND project IN ('', '$project')";
        }
        if (!$return_disabled) {
                $where.= " AND disabled = 0";
        }
 
-       $pseudo_pkgs = array();
-       $tree = Tree::setup (
-               'Memory_MDB2simple',
-               DATABASE_DSN,
-               array (
-                       'order' => 'disabled, id',
-                       'whereAddOn' => $where,
-                       'table' => 'bugdb_pseudo_packages',
-                       'columnNameMaps' => array (
-                               'parentId' => 'parent',
-                       ),
-               )
-       );
-       $tree->setup();
+       $data = $dbh->queryAll("SELECT * FROM bugdb_pseudo_packages WHERE 
$where ORDER BY parent, disabled, id", null, MDB2_FETCHMODE_ASSOC);
 
-       foreach ($tree->data as $data)
+       // Convert flat array to nested strucutre
+       foreach ($data as &$node)
        {
-               if (isset($data['children']))
-               {
+               $node['children'] = array();
+               $id = $node['id'];
+               $parent_id = $node['parent'];
+               $nodes[$id] =& $node;
+
+               if (array_key_exists($parent_id, $nodes)) {
+                       $nodes[$parent_id]['children'][] =& $node;
+               } else {
+                       $tree[] =& $node;
+               }
+       }
+
+       foreach ($tree as $data)
+       {
+               if (isset($data['children'])) {
                        $pseudo_pkgs[$data['name']] = array($data['long_name'], 
$data['disabled']);
                        $long_names = array();
                        foreach ($data['children'] as $k => $v) {
@@ -246,8 +246,9 @@ function get_pseudo_packages($project, $return_disabled = 
true)
                                $pseudo_pkgs[$child['name']] = 
array("&nbsp;&nbsp;&nbsp;&nbsp;{$child['long_name']}", $child['disabled']);
                        }
 
-               } else if (!isset($pseudo_pkgs[$data['name']]))
+               } elseif (!isset($pseudo_pkgs[$data['name']])) {
                        $pseudo_pkgs[$data['name']] = array($data['long_name'], 
$data['disabled']);
+               }
        }
 
        return $pseudo_pkgs;


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to