1 | <?php |
||
13 | abstract class main |
||
14 | { |
||
15 | /** @type string */ |
||
16 | protected $u_action; |
||
17 | /** |
||
18 | * Declare overridden properties |
||
19 | */ |
||
20 | protected $db; |
||
21 | protected $user; |
||
22 | protected $data; |
||
23 | protected $lang_key_prefix; |
||
24 | protected $lang_key_suffix; |
||
25 | protected $table_name; |
||
26 | protected $table_schema; |
||
27 | |||
28 | /** |
||
29 | * Construct |
||
30 | * |
||
31 | * @param \phpbb\db\driver\driver_interface $db Database object |
||
32 | * @param \phpbb\user $user User object |
||
33 | * @param string $lang_key_prefix Prefix for the messages thrown by exceptions |
||
34 | * @param string $lang_key_suffix Suffix for the messages thrown by exceptions |
||
35 | * @param string $table_name Table name |
||
36 | * @param array $table_schema Array with column names to overwrite and type of data |
||
37 | * |
||
38 | * @access public |
||
39 | */ |
||
40 | public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $lang_key_prefix = '', $lang_key_suffix = '', $table_name = '', $table_schema = array()) |
||
49 | |||
50 | /** |
||
51 | * Insert the item for the first time |
||
52 | * |
||
53 | * Will throw an exception if the item was already inserted (call save() instead) |
||
54 | * |
||
55 | * @param string $run_before_insert |
||
56 | * |
||
57 | * @return donation_pages $this object for chaining calls; load()->set()->save() |
||
58 | * @access public |
||
59 | */ |
||
60 | public function insert($run_before_insert = '') |
||
83 | |||
84 | /** |
||
85 | * Display Error message |
||
86 | * |
||
87 | * @param string $lang_key |
||
88 | * @param string $args |
||
89 | * |
||
90 | * @return null |
||
91 | * @access protected |
||
92 | */ |
||
93 | protected function display_error_message($lang_key, $args = '') |
||
98 | |||
99 | /** |
||
100 | * Run function before do some alter some data in the database |
||
101 | * |
||
102 | * @param string $function_name |
||
103 | * |
||
104 | * @return bool |
||
105 | * @access private |
||
106 | */ |
||
107 | private function run_function_before_action($function_name) |
||
117 | |||
118 | /** |
||
119 | * Save the current settings to the database |
||
120 | * |
||
121 | * This must be called before closing or any changes will not be saved! |
||
122 | * If adding a page (saving for the first time), you must call insert() or an exception will be thrown |
||
123 | * |
||
124 | * @param bool $required_fields |
||
125 | * |
||
126 | * @return \skouat\ppde\entity\main $this object for chaining calls; load()->set()->save() |
||
127 | * @access public |
||
128 | */ |
||
129 | public function save($required_fields) |
||
144 | |||
145 | /** |
||
146 | * Get id |
||
147 | * |
||
148 | * @return int Item identifier |
||
149 | * @access public |
||
150 | */ |
||
151 | public function get_id() |
||
155 | |||
156 | /** |
||
157 | * Check the Identifier of the called data exists in the database |
||
158 | * |
||
159 | * @param string $sql SQL Query |
||
160 | * |
||
161 | * @return bool |
||
162 | * @access public |
||
163 | */ |
||
164 | public function data_exists($sql) |
||
171 | |||
172 | /** |
||
173 | * Set item Identifier |
||
174 | * |
||
175 | * @param int $id |
||
176 | * |
||
177 | * @return main $this object for chaining calls; load()->set()->save() |
||
178 | * @access public |
||
179 | */ |
||
180 | public function set_id($id) |
||
186 | |||
187 | /** |
||
188 | * SQL Query to return the ID of selected currency |
||
189 | * |
||
190 | * @return string |
||
191 | * @access public |
||
192 | */ |
||
193 | public function build_sql_data_exists() |
||
199 | |||
200 | /** |
||
201 | * Load the data from the database |
||
202 | * |
||
203 | * @param int $id |
||
204 | * |
||
205 | * @return main $this object for chaining calls; load()->set()->save() |
||
206 | * @access public |
||
207 | */ |
||
208 | public function load($id) |
||
225 | |||
226 | /** |
||
227 | * Get Item name |
||
228 | * |
||
229 | * @return string Item name |
||
230 | * @access public |
||
231 | */ |
||
232 | public function get_name() |
||
236 | |||
237 | /** |
||
238 | * Set Item name |
||
239 | * |
||
240 | * @param string $name |
||
241 | * |
||
242 | * @return main $this object for chaining calls; load()->set()->save() |
||
243 | * @access public |
||
244 | */ |
||
245 | public function set_name($name) |
||
252 | |||
253 | /** |
||
254 | * Set page url |
||
255 | * |
||
256 | * @param string $u_action Custom form action |
||
257 | * |
||
258 | * @return null |
||
259 | * @access public |
||
260 | */ |
||
261 | public function set_page_url($u_action) |
||
265 | |||
266 | /** |
||
267 | * Check if required field are set |
||
268 | * |
||
269 | * @return bool |
||
270 | * @access public |
||
271 | */ |
||
272 | public function check_required_field() |
||
276 | |||
277 | /** |
||
278 | * Check we are in the ACP |
||
279 | * |
||
280 | * @return bool |
||
281 | * @access public |
||
282 | */ |
||
283 | public function is_in_admin() |
||
287 | |||
288 | /** |
||
289 | * Delete data from the database |
||
290 | * |
||
291 | * @param integer $id |
||
292 | * @param string $action_before_delete |
||
293 | * |
||
294 | * @param string $sql_where |
||
295 | * |
||
296 | * @return bool |
||
297 | * @access public |
||
298 | */ |
||
299 | public function delete($id, $action_before_delete = '', $sql_where = '') |
||
316 | |||
317 | /** |
||
318 | * Returns if we can proceed to item deletion |
||
319 | * |
||
320 | * @param integer $id |
||
321 | * |
||
322 | * @return bool |
||
323 | */ |
||
324 | private function disallow_deletion($id) |
||
328 | |||
329 | /** |
||
330 | * Get data from the database |
||
331 | * |
||
332 | * @param string $sql |
||
333 | * @param array $additional_table_schema |
||
334 | * @param int $limit |
||
335 | * @param $limit_offset |
||
336 | * |
||
337 | * @return array |
||
338 | * @throws \skouat\ppde\exception\invalid_argument |
||
339 | * @access public |
||
340 | */ |
||
341 | public function get_data($sql, $additional_table_schema = array(), $limit = 0, $limit_offset = 0) |
||
356 | |||
357 | /** |
||
358 | * Use query limit if requested |
||
359 | * |
||
360 | * @param $sql |
||
361 | * @param $limit |
||
362 | * @param $offset |
||
363 | * |
||
364 | * @return mixed |
||
365 | * @access private |
||
366 | */ |
||
367 | private function limit_query($sql, $limit, $offset) |
||
371 | |||
372 | /** |
||
373 | * Import and validate data |
||
374 | * |
||
375 | * Used when the data is already loaded externally. |
||
376 | * Any existing data on this page is over-written. |
||
377 | * All data is validated and an exception is thrown if any data is invalid. |
||
378 | * |
||
379 | * @param array $data Data array, typically from the database |
||
380 | * @param array $additional_table_schema |
||
381 | * |
||
382 | * @return object $this->data object |
||
383 | * @throws \skouat\ppde\exception\invalid_argument |
||
384 | * @access public |
||
385 | */ |
||
386 | public function import($data, $additional_table_schema = array()) |
||
415 | } |
||
416 |