1 | <?php |
||
15 | abstract class display |
||
16 | { |
||
17 | /** @var \phpbb\db\driver\driver_interface */ |
||
18 | protected $db; |
||
19 | |||
20 | /** @var string */ |
||
21 | protected $items_table; |
||
22 | |||
23 | /** @var string */ |
||
24 | protected $pk; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $sql_where; |
||
28 | |||
29 | /** @var array */ |
||
30 | protected $errors = array(); |
||
31 | |||
32 | /** @var array */ |
||
33 | protected $data = array(); |
||
34 | |||
35 | /** |
||
36 | * Construct |
||
37 | * |
||
38 | * @param \phpbb\db\driver\driver_interface $db Database connection |
||
39 | * @param string $items_table Table name |
||
40 | * @param string $pk Primary key |
||
41 | * @param string $sql_where Column restriction |
||
42 | */ |
||
43 | 30 | public function __construct(\phpbb\db\driver\driver_interface $db, $items_table, $pk, $sql_where = '') |
|
50 | |||
51 | /** |
||
52 | * Is subject node an ancestor of the object node? |
||
53 | * |
||
54 | * @param array $object |
||
55 | * @param array $subject |
||
56 | * @return bool |
||
57 | */ |
||
58 | 5 | public function is_ancestor(array $object, array $subject) |
|
59 | { |
||
60 | 5 | return ($subject['left_id'] < $object['left_id'] && $subject['right_id'] > $object['right_id']) ? true : false; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Count node descendants |
||
65 | * @param array $row |
||
66 | * @return int |
||
67 | */ |
||
68 | 11 | public function count_descendants(array $row) |
|
69 | { |
||
70 | 11 | return (int) (($row['right_id'] - $row['left_id'] - 1) / 2); |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Get node row |
||
75 | * @param int $node_id |
||
76 | * @return mixed |
||
77 | */ |
||
78 | 6 | public function get_node_info($node_id) |
|
89 | |||
90 | /** |
||
91 | * Get Tree Query |
||
92 | * |
||
93 | * @param integer $start Starting depth |
||
94 | * @param integer $max_depth Max depth |
||
95 | * @param array $sql_array Array of elements to merge into query |
||
96 | * array( |
||
97 | * 'SELECT' => array('p.*'), |
||
98 | * 'WHERE' => array('p.post_id = 2'), |
||
99 | * ) |
||
100 | * @return array |
||
101 | */ |
||
102 | 3 | public function qet_tree_sql($start = 0, $max_depth = 0, $sql_array = array()) |
|
124 | |||
125 | /** |
||
126 | * Get the tree data |
||
127 | * |
||
128 | * @param integer $start Starting depth |
||
129 | * @param integer $max_depth Max depth |
||
130 | * @param array $sql_array Array of elements to merge into query |
||
131 | * array( |
||
132 | * 'SELECT' => array('p.*'), |
||
133 | * 'WHERE' => array('p.post_id = 2'), |
||
134 | * ) |
||
135 | * @return array |
||
136 | */ |
||
137 | 3 | public function get_tree_data($start = 0, $max_depth = 0, $sql_array = array()) |
|
152 | |||
153 | /** |
||
154 | * @param array $data |
||
155 | * @param \phpbb\template\twig\twig $template |
||
156 | * @param string $handle |
||
157 | */ |
||
158 | 1 | public function display_list(array $data, \phpbb\template\twig\twig &$template, $handle = 'tree') |
|
184 | |||
185 | /** |
||
186 | * @param int $repeat |
||
187 | * @param string $handle |
||
188 | * @param \phpbb\template\twig\twig $template |
||
189 | * @return void |
||
190 | */ |
||
191 | 1 | protected function recursively_close_tags($repeat, $handle, \phpbb\template\twig\twig &$template) |
|
198 | |||
199 | /** |
||
200 | * Get tree as form options or data |
||
201 | * |
||
202 | * @param array $db_data Raw tree data from database |
||
203 | * @param string $title_column Database column name to use as label/title for each item |
||
204 | * @param array $selected_ids Array of selected items |
||
205 | * @param string $return_mode options | data |
||
206 | * @param string $pad_with Character used to denote nesting |
||
207 | * |
||
208 | * @return mixed Returns array of padded titles or html string of options depending on $return_mode |
||
209 | */ |
||
210 | 3 | public function display_options($db_data, $title_column, $selected_ids = array(), $return_mode = 'options', $pad_with = ' ') |
|
232 | |||
233 | /** |
||
234 | * @param string $padding |
||
235 | * @param string $pad_with |
||
236 | * @param array $row |
||
237 | * @param array $padding_store |
||
238 | * @param int $right |
||
239 | * @retur void |
||
240 | */ |
||
241 | 3 | protected function set_padding(&$padding, $pad_with, array $row, array $padding_store, $right) |
|
253 | |||
254 | /** |
||
255 | * @param string $padding |
||
256 | * @param string $title |
||
257 | * @return string |
||
258 | */ |
||
259 | 3 | protected function get_padded_title($padding, $title) |
|
263 | |||
264 | /** |
||
265 | * @param array $row |
||
266 | * @param array $selected_ids |
||
267 | * @param string $title |
||
268 | * @return string |
||
269 | */ |
||
270 | 3 | protected function get_html_option(array $row, array $selected_ids, $title) |
|
275 | } |
||
276 |