1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Adslight; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ObjectTree |
9
|
|
|
* @package XoopsModules\Adslight |
10
|
|
|
*/ |
11
|
|
|
class ObjectTree extends \XoopsObjectTree |
12
|
|
|
{ |
13
|
|
|
//generates id path from the root id to a given id |
14
|
|
|
// the path is delimetered with "/" |
15
|
|
|
/** |
16
|
|
|
* @param $sel_id |
17
|
|
|
* @param string $path |
18
|
|
|
* |
19
|
|
|
* @return string |
20
|
|
|
*/ |
21
|
|
|
public function getIdPathFromId($sel_id, $path = ''): string |
22
|
|
|
{ |
23
|
|
|
global $xoopsDB; |
24
|
|
|
$sel_id = (int)$sel_id; |
25
|
|
|
$result = $xoopsDB->query('SELECT ' . $this->parentId . ' FROM ' . $this->table . ' WHERE ' . $this->myId . "=$sel_id"); |
|
|
|
|
26
|
|
|
if (0 == $xoopsDB->getRowsNum($result)) { |
27
|
|
|
return $path; |
28
|
|
|
} |
29
|
|
|
[$parentid] = $xoopsDB->fetchRow($result); |
30
|
|
|
$path = '/' . $sel_id . $path . ''; |
31
|
|
|
if (0 == $parentid) { |
32
|
|
|
return $path; |
33
|
|
|
} |
34
|
|
|
$path = $this->getIdPathFromId($parentid, $path); |
35
|
|
|
|
36
|
|
|
return $path; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
//generates nicely formatted linked path from the root id to a given id |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $sel_id |
43
|
|
|
* @param $title |
44
|
|
|
* @param $funcURL |
45
|
|
|
* @param string $path |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function getNicePathFromId($sel_id, $title, $funcURL, $path = ''): string |
50
|
|
|
{ |
51
|
|
|
global $xoopsDB; |
52
|
|
|
$path = !empty($path) ? ' : ' . $path : $path; |
53
|
|
|
$sel_id = (int)$sel_id; |
54
|
|
|
$sql = 'SELECT ' . $this->parentId . ', ' . $title . ' FROM ' . $this->table . ' WHERE ' . $this->myId . "=$sel_id"; |
|
|
|
|
55
|
|
|
$result = $xoopsDB->query($sql); |
56
|
|
|
if (0 == $xoopsDB->getRowsNum($result)) { |
57
|
|
|
return $path; |
58
|
|
|
} |
59
|
|
|
[$parentid, $name] = $xoopsDB->fetchRow($result); |
60
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
61
|
|
|
$name = \htmlspecialchars($name, \ENT_QUOTES | \ENT_HTML5); |
62
|
|
|
$path = "<a href='" . $funcURL . '&' . $this->myId . '=' . $sel_id . "'>" . $name . '</a>' . $path . ''; |
63
|
|
|
if (0 == $parentid) { |
64
|
|
|
return $path; |
65
|
|
|
} |
66
|
|
|
$path = $this->getNicePathFromId($parentid, $title, $funcURL, $path); |
67
|
|
|
|
68
|
|
|
return $path; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|