Code Duplication    Length = 22-25 lines in 3 locations

class/classifiedstree.php 3 locations

@@ 113-136 (lines=24) @@
110
     *
111
     * @return array
112
     */
113
    public function getAllChildId($sel_id, $order = '', $idarray = array())
114
    {
115
        $sql = 'SELECT SQL_CACHE ' . $this->id . ' FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $this->db->escape($sel_id) . '';
116
117
        $categories = adslight_MygetItemIds('adslight_view');
118
        if (is_array($categories) && count($categories) > 0) {
119
            $sql .= ' AND ' . $this->pid . ' IN (' . implode(',', $categories) . ') ';
120
        }
121
122
        if ($order != '') {
123
            $sql .= " ORDER BY {$order}";
124
        }
125
        $result = $this->db->query($sql);
126
        $count  = $this->db->getRowsNum($result);
127
        if ($count == 0) {
128
            return $idarray;
129
        }
130
        while (list($r_id) = $this->db->fetchRow($result)) {
131
            array_push($idarray, $r_id);
132
            $idarray = $this->getAllChildId($r_id, $order, $idarray);
133
        }
134
135
        return $idarray;
136
    }
137
138
    /**
139
     * @param        $sel_id
@@ 145-166 (lines=22) @@
142
     *
143
     * @return array
144
     */
145
    public function getAllParentId($sel_id, $order = '', $idarray = array())
146
    {
147
        $sql = 'SELECT ' . $this->pid . ' FROM ' . $this->table . ' WHERE ' . $this->id . '=' . $this->db->escape($sel_id) . '';
148
149
        $categories = adslight_MygetItemIds('adslight_view');
150
        if (is_array($categories) && count($categories) > 0) {
151
            $sql .= ' AND ' . $this->pid . ' IN (' . implode(',', $categories) . ') ';
152
        }
153
154
        if ($order != '') {
155
            $sql .= " ORDER BY {$order}";
156
        }
157
        $result = $this->db->query($sql);
158
        list($r_id) = $this->db->fetchRow($result);
159
        if ($r_id == 0) {
160
            return $idarray;
161
        }
162
        array_push($idarray, $r_id);
163
        $idarray = $this->getAllParentId($r_id, $order, $idarray);
164
165
        return $idarray;
166
    }
167
168
    /**
169
     * @param        $sel_id
@@ 330-354 (lines=25) @@
327
     *
328
     * @return array
329
     */
330
    public function getAllChild($sel_id = 0, $order = '', $parray = array())
331
    {
332
        $sql = 'SELECT SQL_CACHE * FROM ' . $this->table . ' WHERE ' . $this->pid . '=' . $this->db->escape($sel_id) . '';
333
334
        $categories = adslight_MygetItemIds('adslight_view');
335
        if (is_array($categories) && count($categories) > 0) {
336
            $sql .= ' AND ' . $this->pid . ' IN (' . implode(',', $categories) . ') ';
337
        }
338
339
        if ($order != '') {
340
            $sql .= " ORDER BY {$order}";
341
        }
342
343
        $result = $this->db->query($sql);
344
        $count  = $this->db->getRowsNum($result);
345
        if ($count == 0) {
346
            return $parray;
347
        }
348
        while ($row = $this->db->fetchArray($result)) {
349
            array_push($parray, $row);
350
            $parray = $this->getAllChild($row[$this->id], $order, $parray);
351
        }
352
353
        return $parray;
354
    }
355
356
    /**
357
     * @param int    $sel_id