Code Duplication    Length = 17-19 lines in 3 locations

class/xoopstree.php 3 locations

@@ 113-131 (lines=19) @@
110
     *
111
     * @return array
112
     */
113
    public function getAllChildId($sel_id, $order = '', $idarray = array())
114
    {
115
        $sel_id = (int)$sel_id;
116
        $sql    = 'SELECT ' . $this->id . ' FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $sel_id . '';
117
        if ($order != '') {
118
            $sql .= " ORDER BY $order";
119
        }
120
        $result = $this->db->query($sql);
121
        $count  = $this->db->getRowsNum($result);
122
        if ($count == 0) {
123
            return $idarray;
124
        }
125
        while (list($r_id) = $this->db->fetchRow($result)) {
126
            array_push($idarray, $r_id);
127
            $idarray = $this->getAllChildId($r_id, $order, $idarray);
128
        }
129
130
        return $idarray;
131
    }
132
133
    //returns an array of ALL parent ids for a given id($sel_id)
134
    /**
@@ 141-157 (lines=17) @@
138
     *
139
     * @return array
140
     */
141
    public function getAllParentId($sel_id, $order = '', $idarray = array())
142
    {
143
        $sel_id = (int)$sel_id;
144
        $sql    = 'SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . '=' . $sel_id . '';
145
        if ($order != '') {
146
            $sql .= " ORDER BY $order";
147
        }
148
        $result = $this->db->query($sql);
149
        list($r_id) = $this->db->fetchRow($result);
150
        if ($r_id == 0) {
151
            return $idarray;
152
        }
153
        array_push($idarray, $r_id);
154
        $idarray = $this->getAllParentId($r_id, $order, $idarray);
155
156
        return $idarray;
157
    }
158
159
    //generates path from the root id to a given id($sel_id)
160
    // the path is delimetered with "/"
@@ 302-320 (lines=19) @@
299
     *
300
     * @return unknown
301
     */
302
    public function getAllChild($sel_id = 0, $order = '', $parray = array())
303
    {
304
        $sel_id = (int)$sel_id;
305
        $sql    = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $sel_id . '';
306
        if ($order != '') {
307
            $sql .= " ORDER BY $order";
308
        }
309
        $result = $this->db->query($sql);
310
        $count  = $this->db->getRowsNum($result);
311
        if ($count == 0) {
312
            return $parray;
313
        }
314
        while ($row = $this->db->fetchArray($result)) {
315
            array_push($parray, $row);
316
            $parray = $this->getAllChild($row[$this->id], $order, $parray);
317
        }
318
319
        return $parray;
320
    }
321
322
    /**
323
     * Enter description here...