1 | <?php |
||
7 | abstract class Listview extends Collection { |
||
8 | |||
9 | # Get default select query |
||
10 | |||
11 | private function getDefaultSelectQuery(array $config, array $order_by, int $index, int $display) { |
||
23 | |||
24 | # Get nesting select query |
||
25 | |||
26 | private function getNestingSelectQuery(int $parent_id, array $config, array $order_by, int $index, int $display) { |
||
44 | |||
45 | # Get default count query |
||
46 | |||
47 | private function getDefaultCountQuery(array $config) { |
||
53 | |||
54 | # Get nesting count query |
||
55 | |||
56 | private function getNestingCountQuery(int $parent_id, array $config) { |
||
66 | |||
67 | # Select entries from DB |
||
68 | |||
69 | private function select(int $parent_id = null, array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
||
70 | |||
71 | if (!((null === $parent_id) || ($parent_id >= 0))) return false; |
||
72 | |||
73 | if (!(($index >= 0) && ($display >= 0))) return false; |
||
74 | |||
75 | # Select entities |
||
76 | |||
77 | $query = ((null === $parent_id) ? $this->getDefaultSelectQuery($config, $order_by, $index, $display) : |
||
78 | |||
79 | $this->getNestingSelectQuery($parent_id, $config, $order_by, $index, $display)); |
||
80 | |||
81 | if (!(DB::send($query) && DB::last()->status)) return false; |
||
82 | |||
83 | # Process results |
||
84 | |||
85 | $items = ['list' => [], 'total' => 0]; |
||
86 | |||
87 | while (null !== ($data = DB::last()->row())) { |
||
88 | |||
89 | $dataset = Entitizer::dataset(static::$table, $data); |
||
90 | |||
91 | $items['list'][$dataset->id]['dataset'] = $dataset; |
||
92 | |||
93 | if (null !== $parent_id) $items['list'][$dataset->id]['children'] = intval($data['children']); |
||
94 | } |
||
95 | |||
96 | # Count total |
||
97 | |||
98 | if (DB::send("SELECT FOUND_ROWS() as total") && (DB::last()->rows === 1)) { |
||
99 | |||
100 | $items['total'] = intval(DB::last()->row()['total']); |
||
101 | } |
||
102 | |||
103 | # ------------------------ |
||
104 | |||
105 | return $items; |
||
106 | } |
||
107 | |||
108 | # Count entries in DB |
||
109 | |||
110 | private function count(int $parent_id = null, array $config = []) { |
||
126 | |||
127 | # Get items |
||
128 | |||
129 | public function items(array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
||
133 | |||
134 | # Get items count |
||
135 | |||
136 | public function itemsCount(array $config = []) { |
||
140 | |||
141 | # Get children |
||
142 | |||
143 | public function children(int $parent_id = 0, array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
||
149 | |||
150 | # Get children count |
||
151 | |||
152 | public function childrenCount(int $parent_id = 0, array $config = []) { |
||
158 | } |
||
159 | } |
||
160 |