-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeMysqliManager.php
More file actions
69 lines (59 loc) · 1.91 KB
/
TreeMysqliManager.php
File metadata and controls
69 lines (59 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Mysql fabric relate of fasade to TreeManager
* @author tvitcom
* @url github.com/tvitcom
* @package test case application
* @license https://www.apache.org/licenses/LICENSE-2.0 tvitcom
*/
class TreeMysqliManager implements HierInterface {
private static $instance = NULL;
public function __construct()
{
}
public function __clone()
{
}
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new mysqli('p:localhost','treemenu', 'pass_to_treemenu','treemenu','33306');
self::$instance->set_charset("latin1");
}
return self::$instance;
}
/*
* Return description of the element as item_id from join table
*/
public static function getNameOfElement($item_id=0, $language_id=0) {
$sql = "SELECT item_id, item_name FROM items_description WHERE item_id=" .
(int) $item_id . " AND language_id=" . (int) $language_id . ";";
if ($result = self::getInstance()->query($sql)) {
$data = $result->fetch_assoc();
$result->close();
}
return $data;
}
/*
* Return nodes of the parent_id
*/
public static function getNodesOfParentId($start_id = 0) {
$sql = "SELECT item_id from items WHERE parent_id=".(int) $start_id . ";";
if ($result = self::getInstance()->query($sql)) {
$data = $result->fetch_all(MYSQLI_ASSOC);
$result->close();
}
return $data;
}
/*
* Return number of top nodes (quantity of root nodes)
*/
public static function getTopNodes() {
$sql = "SELECT item_id FROM items WHERE parent_id = (SELECT min(parent_id) FROM items);";
if ($result = self::getInstance()->query($sql)) {
$data = $result->fetch_all(MYSQLI_ASSOC);
$result->close();
}
return $data;
}
}