PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.80
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.80
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataProjects / Parent_Child / WPDP_Parent_List_View.php

WPDP_Parent_List_View.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.80, at WPDataProjects/Parent_Child/WPDP_Parent_List_View.php

301 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 *
6 * @package WPDataProjects\Parent_Child
7 */
8
9 namespace WPDataProjects\Parent_Child {
10
11 use WPDataAccess\List_Table\WPDA_List_View;
12 use WPDataAccess\Utilities\WPDA_Repository;
13 use WPDataProjects\Project\WPDP_Project;
14 use WPDataProjects\Data_Dictionary\WPDP_List_Columns_Cache;
15 use WPDataProjects\List_Table\WPDP_List_View;
16
17 /**
18 * Class WPDP_Parent_List_View extends WPDA_List_View
19 *
20 * Adds parent-child functionality to WPDA_List_View
21 *
22 * @see WPDA_List_View
23 *
24 * @author Peter Schulz
25 * @since 2.0.0
26 */
27 class WPDP_Parent_List_View extends WPDP_List_View {
28
29 /**
30 * Project ID
31 *
32 * @var string
33 */
34 protected $project_id = null;
35
36 /**
37 * Page ID
38 *
39 * @var string
40 */
41 protected $page_id = null;
42
43 /**
44 * Instance of class WPDP_Project for $this->project_id
45 *
46 * @var WPDP_Project
47 */
48 protected $project;
49
50 /**
51 * Parent info
52 *
53 * @var array
54 */
55 protected $parent;
56
57 /**
58 * Child relationships
59 *
60 * @var array
61 */
62 protected $children;
63
64 /**
65 * Page title
66 *
67 * @var string
68 */
69 protected $title;
70
71 /**
72 * Page sub title
73 *
74 * @var string
75 */
76 protected $subtitle;
77
78 /**
79 * Possible values: TRUE and null
80 *
81 * TRUE = request is a child request
82 * All other values (including null) = request is a parent request
83 *
84 * @var mixed
85 */
86 protected $child_request;
87
88 /**
89 * Possible values: edit and view
90 *
91 * @var string
92 */
93 protected $mode = null;
94
95 /**
96 * Class to be instantiated for data entry form
97 *
98 * @var string|null
99 */
100 protected $parent_edit_form_class = null;
101
102 /**
103 * SQL where clause
104 *
105 * @var null
106 */
107 protected $where_clause = null;
108
109 /**
110 * Order by
111 *
112 * @var null
113 */
114 protected $orderby_clause = null;
115
116 /**
117 * WPDP_Parent_List_View constructor
118 *
119 * Adds parent-child functionality
120 *
121 * @param array $args
122 */
123 public function __construct( $args = array() ) {
124 if ( isset( $args['project_id'] ) ) {
125 $this->project_id = sanitize_text_field( wp_unslash( $args['project_id'] ) );
126 } elseif ( isset( $_REQUEST['tab'] ) && 'tables' === $_REQUEST['tab'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified in parent class
127 $this->project_id = 'wpda_sys_tables';
128 }
129 if ( isset( $args['page_id'] ) ) {
130 $this->page_id = sanitize_text_field( wp_unslash( $args['page_id'] ) );
131 }
132
133 if ( null !== $this->title && '' !== $this->title ) {
134 $args['title'] = $this->title;
135 }
136 $args['subtitle'] = $this->subtitle;
137
138 parent::__construct( $args );
139
140 $this->child_request = (
141 isset( $_REQUEST['child_request'] ) && 'TRUE' === sanitize_text_field( wp_unslash( $_REQUEST['child_request'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified in parent class
142 );
143
144 if ( isset( $_REQUEST['mode'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified in parent class
145 $this->mode = sanitize_text_field( wp_unslash( $_REQUEST['mode'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified in parent class
146 }
147
148 if ( isset( $args['parent_edit_form_class'] ) ) {
149 $this->parent_edit_form_class = $args['parent_edit_form_class']; // input var okay.
150 }
151
152 if ( isset( $args['where_clause'] ) && '' !== $args['where_clause'] ) {
153 $this->where_clause = $args['where_clause'];
154 }
155
156 if ( isset( $args['orderby_clause'] ) && '' !== $args['orderby_clause'] ) {
157 $this->orderby_clause = $args['orderby_clause'];
158 }
159 }
160
161 /**
162 * Overwrites method show to add parent-child functionality
163 */
164 public function show() {
165 // Add datetimepicker
166 wp_enqueue_style( 'datetimepicker' );
167 wp_enqueue_script( 'datetimepicker' );
168
169 $this->project = new WPDP_Project( $this->project_id, $this->page_id );
170 if ( null === $this->project->get_project() ) {
171 wp_die( esc_attr__( 'Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' ) );
172 }
173 if ( null === $this->title ) {
174 $this->title = $this->project->get_title();
175 }
176 if ( null === $this->mode ) {
177 $this->mode = $this->project->get_mode();
178 }
179 $this->subtitle = $this->project->get_subtitle();
180 $this->parent = $this->project->get_parent();
181 $this->children = $this->project->get_children();
182
183 $wpda_repository = new WPDA_Repository();
184 $wpda_repository->inform_user();
185
186 // DO NOT REMOVE!!!
187 // Yes, this is double code! But for some completely unclear reason this member seems to lose this value...
188 $this->child_request = (
189 isset( $_REQUEST['child_request'] ) && 'TRUE' === sanitize_text_field( wp_unslash( $_REQUEST['child_request'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- verified in parent class
190 );
191
192 if ( $this->child_request ) {
193 $this->display_edit_form();
194 } else {
195 switch ( $this->action ) {
196 case 'new':
197 case 'view':
198 case 'edit':
199 $this->display_edit_form();
200 break;
201 default:
202 $this->display_list_table();
203 }
204 }
205 }
206
207 /**
208 * Overwrites method display_edit_form to add parent-child functionality
209 */
210 protected function display_edit_form() {
211 if (
212 'view' === $this->mode &&
213 'only' !== $this->allow_insert ||
214 ( ! $this->child_request && 'view' === $this->action )
215 ) {
216 $edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form_View';
217 $mode = 'view';
218 } else {
219 $edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form';
220 $mode = 'edit';
221 }
222
223 if ( null !== $this->parent_edit_form_class ) {
224 $edit_form_class = $this->parent_edit_form_class;
225 }
226
227 $args = array(
228 'title' => null === $this->title ? __( 'Back', 'wp-data-access' ) : $this->title,
229 'subtitle' => $this->subtitle,
230 'add_action_to_title' => 'FALSE',
231 'mode' => $mode,
232 'child_request' => $this->child_request,
233 );
234 if ( 'off' === $this->allow_insert ) {
235 $args['hide_add_new'] = true;
236 }
237 if ( 'only' === $this->allow_insert ) {
238 $args['action'] = 'new';
239 }
240
241 $this->wpda_list_columns = WPDP_List_Columns_Cache::get_list_columns( $this->schema_name, $this->table_name, 'tableform', $this->setname );
242 $form = new $edit_form_class(
243 $this->schema_name,
244 $this->table_name,
245 $this->wpda_list_columns,
246 $args,
247 array(
248 'parent' => $this->parent,
249 'children' => $this->children,
250 )
251 );
252
253 $form->prepare_form();
254
255 if ( isset( $_POST['postaction'] ) && 'list' === $_POST['postaction'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified in parent class
256 $this->display_list_table();
257 } else {
258 $form->show();
259 }
260 }
261
262 /**
263 * Overwrites method display_list_table to add parent-child functionality
264 */
265 protected function display_list_table() {
266 $this->wpda_list_columns = WPDP_List_Columns_Cache::get_list_columns( $this->schema_name, $this->table_name, 'listtable', $this->setname );
267 $this->wpda_list_table = new $this->list_table_class(
268 array(
269 'wpdaschema_name' => $this->schema_name,
270 'table_name' => $this->table_name,
271 'wpda_list_columns' => $this->wpda_list_columns,
272 'column_headers' => $this->column_headers,
273 'project' => $this->project,
274 'where_clause' => $this->where_clause,
275 'orderby_clause' => $this->orderby_clause,
276 'default_where' => $this->default_where,
277 'allow_delete' => $this->allow_delete,
278 'allow_import' => $this->allow_import,
279 'allow_update' => $this->allow_update,
280 'allow_insert' => $this->allow_insert,
281 'pid' => $this->page_id,
282 )
283 );
284
285 $this->wpda_list_table->set_bulk_actions_enabled( $this->bulk_actions_enabled );
286 $this->wpda_list_table->set_search_box_enabled( $this->search_box_enabled );
287
288 if ( null !== $this->title ) {
289 $this->wpda_list_table->set_title( $this->title );
290 }
291 if ( null !== $this->subtitle ) {
292 $this->wpda_list_table->set_subtitle( $this->subtitle );
293 }
294
295 $this->wpda_list_table->show();
296 }
297
298 }
299
300 }
301