jails / li3_tree

BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

childrens with levels #4

Open agborkowski opened 11 years ago

agborkowski commented 11 years ago
static function childrens($parent) {
        // $sql = "SELECT node.*, (COUNT(parent.name) - 1) AS depth ";
        // $sql .= "FROM ". self::meta('source') ." AS node, ";
        // $sql .= self::meta('source') . " AS parent ";
        // $sql .= "WHERE node.parent_id = " . $parent . " AND node.lft BETWEEN parent.lft AND parent.rght ";
        // $sql .= "GROUP BY node.name ";
        // $sql .= "ORDER BY node.lft;";
        $sql = "SELECT node.*, (COUNT(parent.id) - (sub_tree.depth + 1)) AS depth ";
        $sql .= "FROM " . self::meta('source') . " AS node, ";
        $sql .= "   " . self::meta('source') . " AS parent, ";
        $sql .= "   " . self::meta('source') . " AS sub_parent, ";
        $sql .= "   ( ";
        $sql .= "       SELECT node.*, (COUNT(parent.id) - 1) AS depth ";
        $sql .= "       FROM " . self::meta('source') . " AS node, ";
        $sql .= "       " . self::meta('source') . " AS parent ";
        $sql .= "       WHERE node.lft BETWEEN parent.lft AND parent.rght ";
        $sql .= "       AND node.id = ". $parent . " ";
        $sql .= "       GROUP BY node.name ";
        $sql .= "       ORDER BY node.lft ";
        $sql .= "   ) AS sub_tree ";
        $sql .= "WHERE node.lft BETWEEN parent.lft AND parent.rght ";
        $sql .= "   AND node.lft BETWEEN sub_parent.lft AND sub_parent.rght ";
        $sql .= "   AND sub_parent.id = sub_tree.id ";
        $sql .= "GROUP BY node.name ";
        $sql .= "ORDER BY node.lft; ";
        return static::connection()->read($sql);
    }

any idea to attach levels to childrens() behavior function ?

jails commented 11 years ago

Tests passed on travis: https://travis-ci.org/jails/li3_tree May it be related to your lithium version ?