|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Cadmium\System\Modules\Entitizer |
|
5
|
|
|
* @author Anton Romanov |
|
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
|
7
|
|
|
* @link http://cadmium-cms.com |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Modules\Entitizer\Utils\Entity { |
|
11
|
|
|
|
|
12
|
|
|
use Modules\Entitizer; |
|
13
|
|
|
|
|
14
|
|
|
trait Collection { |
|
15
|
|
|
|
|
16
|
|
|
protected $definition = null, $dataset = null; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Get the list of items |
|
20
|
|
|
* |
|
21
|
|
|
* @param $config an array of filtering options |
|
22
|
|
|
* @param $order_by an array where each key is a field name and each value is a sorting direction (ASC or DESC) |
|
23
|
|
|
* @param $index a page index |
|
24
|
|
|
* @param $display a number of results per page |
|
25
|
|
|
* |
|
26
|
|
|
* @return array|false : the array of entities or false on failure |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
public function getItems(array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
|
30
|
|
|
|
|
31
|
|
|
return Entitizer::getListview(static::$table)->getItems($config, $order_by, $index, $display); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get the items count |
|
36
|
|
|
* |
|
37
|
|
|
* @param $config : an array of filtering options |
|
38
|
|
|
* |
|
39
|
|
|
* @return int|false : the number of entities or false on failure |
|
40
|
|
|
*/ |
|
41
|
|
|
|
|
42
|
|
|
public function getItemsCount(array $config = []) { |
|
43
|
|
|
|
|
44
|
|
|
return Entitizer::getListview(static::$table)->getItemsCount($config); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the list of children items |
|
49
|
|
|
* |
|
50
|
|
|
* @param $config an array of filtering options |
|
51
|
|
|
* @param $order_by an array where each key is a field name and each value is a sorting direction (ASC or DESC) |
|
52
|
|
|
* @param $index a page index |
|
53
|
|
|
* @param $display a number of results per page |
|
54
|
|
|
* |
|
55
|
|
|
* @return array|false : the array of entities or false on failure |
|
56
|
|
|
*/ |
|
57
|
|
|
|
|
58
|
|
|
public function getChildren(array $config = [], array $order_by = [], int $index = 0, int $display = 0) { |
|
59
|
|
|
|
|
60
|
|
|
return Entitizer::getListview(static::$table)->getChildren($this->id, $config, $order_by, $index, $display); |
|
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the children items count |
|
65
|
|
|
* |
|
66
|
|
|
* @param $config : an array of filtering options |
|
67
|
|
|
* |
|
68
|
|
|
* @return int|false : the number of entities or false on failure |
|
69
|
|
|
*/ |
|
70
|
|
|
|
|
71
|
|
|
public function getChildrenCount(array $config = []) { |
|
72
|
|
|
|
|
73
|
|
|
return Entitizer::getListview(static::$table)->getChildrenCount($this->id, $config); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get the entity subtree |
|
78
|
|
|
* |
|
79
|
|
|
* @param $config an array of filtering options |
|
80
|
|
|
* @param $order_by an array where each key is a field name and each value is a sorting direction (ASC or DESC) |
|
81
|
|
|
* |
|
82
|
|
|
* @return array|false : the multidimensional array containing the tree or false on failure |
|
83
|
|
|
*/ |
|
84
|
|
|
|
|
85
|
|
|
public function getSubtree(array $config = [], array $order_by = []) { |
|
86
|
|
|
|
|
87
|
|
|
return Entitizer::getTreeview(static::$table)->getSubtree($this->id, $config, $order_by); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get the count of items within the entity subtree |
|
92
|
|
|
* |
|
93
|
|
|
* @return int|false : the number of entities or false on failure |
|
94
|
|
|
*/ |
|
95
|
|
|
|
|
96
|
|
|
public function getSubtreeCount() { |
|
97
|
|
|
|
|
98
|
|
|
return Entitizer::getTreeview(static::$table)->getSubtreeCount($this->id); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the subtree depth |
|
103
|
|
|
* |
|
104
|
|
|
* @return int|false : the depth or false on failure |
|
105
|
|
|
*/ |
|
106
|
|
|
|
|
107
|
|
|
public function getSubtreeDepth() { |
|
108
|
|
|
|
|
109
|
|
|
return Entitizer::getTreeview(static::$table)->getSubtreeDepth($this->id); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get the entity path |
|
114
|
|
|
* |
|
115
|
|
|
* @return array|false : the array of path items or false on failure |
|
116
|
|
|
*/ |
|
117
|
|
|
|
|
118
|
|
|
public function getPath() { |
|
119
|
|
|
|
|
120
|
|
|
return Entitizer::getTreeview(static::$table)->getPath($this->id); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: