Passed
Push — master ( d50017...68c32a )
by Michael
02:26
created

ClassifiedObjectTree::getNicePathFromId()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 20
rs 9.7666
c 0
b 0
f 0
cc 4
nc 6
nop 4
1
<?php
2
3
namespace XoopsModules\Adslight;
4
5
/**
6
 * Class ClassifiedObjectTree
7
 * @package XoopsModules\Adslight
8
 */
9
class ClassifiedObjectTree extends \XoopsObjectTree
10
{
11
    //generates id path from the root id to a given id
12
    // the path is delimetered with "/"
13
    /**
14
     * @param        $sel_id
15
     * @param string $path
16
     *
17
     * @return string
18
     */
19
    public function getIdPathFromId($sel_id, $path = '')
20
    {
21
        global $xoopsDB;
22
        $sel_id = (int)$sel_id;
23
        $result = $xoopsDB->query('SELECT ' . $this->parentId . ' FROM ' . $this->table . ' WHERE ' . $this->myId . "=$sel_id");
0 ignored issues
show
Bug Best Practice introduced by
The property table does not exist on XoopsModules\Adslight\ClassifiedObjectTree. Since you implemented __get, consider adding a @property annotation.
Loading history...
24
        if (0 == $xoopsDB->getRowsNum($result)) {
25
            return $path;
26
        }
27
        list($parentid) = $xoopsDB->fetchRow($result);
28
        $path = '/' . $sel_id . $path . '';
29
        if (0 == $parentid) {
30
            return $path;
31
        }
32
        $path = $this->getIdPathFromId($parentid, $path);
33
34
        return $path;
35
    }
36
37
    //generates nicely formatted linked path from the root id to a given id
38
    /**
39
     * @param        $sel_id
40
     * @param        $title
41
     * @param        $funcURL
42
     * @param string $path
43
     *
44
     * @return string
45
     */
46
    public function getNicePathFromId($sel_id, $title, $funcURL, $path = '')
47
    {
48
        global $xoopsDB;
49
        $path   = !empty($path) ? '&nbsp;:&nbsp;' . $path : $path;
50
        $sel_id = (int)$sel_id;
51
        $sql    = 'SELECT ' . $this->parentId . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->myId . "=$sel_id";
0 ignored issues
show
Bug Best Practice introduced by
The property table does not exist on XoopsModules\Adslight\ClassifiedObjectTree. Since you implemented __get, consider adding a @property annotation.
Loading history...
52
        $result = $xoopsDB->query($sql);
53
        if (0 == $xoopsDB->getRowsNum($result)) {
54
            return $path;
55
        }
56
        list($parentid, $name) = $xoopsDB->fetchRow($result);
57
        $myts = \MyTextSanitizer::getInstance();
58
        $name = $myts->htmlSpecialChars($name);
59
        $path = "<a href='" . $funcURL . '&amp;' . $this->myId . '=' . $sel_id . "'>" . $name . '</a>' . $path . '';
60
        if (0 == $parentid) {
61
            return $path;
62
        }
63
        $path = $this->getNicePathFromId($parentid, $title, $funcURL, $path);
64
65
        return $path;
66
    }
67
}
68