PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 2.0.13
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v2.0.13
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
← All changes | WPDataProjects/Project/WPDP_Project.php +110 -218 5.5.42.0.13 View file →
@@ -1,10 +1,9 @@
1 1 <?php
2 -
3 2 /**
4 3 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 4 *
6 - * @package WPDataProjects\Project
5 + * @package WPDataProjects
7 6 */
8 7
9 8 namespace WPDataProjects\Project {
10 9
@@ -9,13 +8,13 @@
9 8 namespace WPDataProjects\Project {
10 9
11 10 use WPDataAccess\WPDA;
12 11 use WPDataAccess\Data_Dictionary\WPDA_List_Columns_Cache;
13 - use WPDataAccess\Plugin_Table_Models\WPDP_Project_Design_Table_Model;
14 12
15 13 /**
16 14 * Class WPDP_Project
17 15 *
16 + * @package WPDataProjects\Project
18 17 * @author Peter Schulz
19 18 * @since 2.0.0
20 19 */
21 20 class WPDP_Project {
@@ -20,37 +19,26 @@
20 19 */
21 20 class WPDP_Project {
22 21
23 22 /**
24 - * Project structure
25 - *
26 - * @var array|null
23 + * @var
27 24 */
28 - protected $project = null;
25 + protected $project;
29 26
30 27 /**
31 - * Project ID
32 - *
33 - * @var string|null
28 + * @var null
34 29 */
35 30 protected $project_id = null;
36 -
37 31 /**
38 - * Page ID
39 - *
40 - * @var string|null
32 + * @var null
41 33 */
42 34 protected $page_id = null;
43 35
44 36 /**
45 - * WPDP_Project constructor
37 + * WPDP_Project constructor.
46 38 *
47 - * Set project and page ID. Sets the structure for the Data Projects tool main page if no project ID is
48 - * provided. Sets the structure for the Data Projects tool table options page if project ID is
49 - * 'wpda_sys_tables'.
50 - *
51 - * @param string $project_id Project ID
52 - * @param string $page_id Page ID
39 + * @param null $project_id
40 + * @param null $page_id
53 41 */
54 42 public function __construct( $project_id = null, $page_id = null ) {
55 43 $this->project_id = $project_id;
56 44 $this->page_id = $page_id;
@@ -64,242 +52,182 @@
64 52 }
65 53 }
66 54
67 55 /**
68 - * Sets the structure for the Data Projects tool main page
56 + *
69 57 */
70 58 protected function init_self() {
71 59 global $wpdb;
72 60 $this->project =
73 - array(
61 + [
74 62 'mode' => 'edit',
75 - 'setname' => '',
76 63 'title' => '',
77 64 'subtitle' => '',
78 65 'parent' =>
79 - array(
80 - 'key' => array( 'project_id' ),
81 - 'data_type' => array( 'number' ),
82 - ),
66 + [
67 + 'key' => [ 'project_id' ],
68 + 'data_type' => [ 'number' ],
69 + ],
83 70 'children' =>
84 - array(
85 - array(
86 - 'table_name' => $wpdb->prefix . 'wpda_project_page',
87 - 'setname' => '',
88 - 'tab_label' => 'Pages',
89 - 'default_where' => '',
90 - 'default_orderby' => '',
91 - 'relation_1n' =>
92 - array(
93 - 'parent_key' => array( 'project_id' ),
94 - 'child_key' => array( 'project_id' ),
95 - 'data_type' => array( 'number' ),
96 - ),
97 - ),
98 - ),
99 - );
71 + [
72 + [
73 + 'table_name' => $wpdb->prefix . 'wpdp_page',
74 + 'tab_label' => 'Pages',
75 + 'relation_1n' =>
76 + [
77 + 'child_key' => [ 'project_id' ],
78 + 'data_type' => [ 'number' ],
79 + ],
80 + ],
81 + ],
82 + ];
100 83 }
101 84
102 85 /**
103 - * Sets the structure for the Data Projects tool table options page
86 + *
104 87 */
105 88 protected function init_self_tables() {
106 89 $this->project =
107 - array(
90 + [
108 91 'mode' => 'edit',
109 - 'setname' => '',
110 92 'title' => '',
111 93 'subtitle' => '',
112 94 'parent' =>
113 - array(
114 - 'key' => array( 'wpda_table_name' ),
115 - 'data_type' => array( 'varchar' ),
116 - ),
95 + [
96 + 'key' => [ 'wpda_table_name' ],
97 + 'data_type' => [ 'varchar' ],
98 + ],
117 99 'children.' =>
118 - array(),
119 - );
100 + [],
101 + ];
120 102 }
121 103
122 104 /**
123 - * Creates the structure for the given project page
124 - *
125 - * @param string $project_id Project ID
126 - * @param string $page_id Page ID
105 + * @param $project_id
106 + * @param $page_id
127 107 */
128 108 protected function init_project_page( $project_id, $page_id ) {
129 109 global $wpdb;
130 110 $query = $wpdb->prepare(
131 111 "
132 - select * from {$wpdb->prefix}wpda_project_page
133 - where project_id = %d
112 + select * from {$wpdb->prefix}wpdp_page
113 + where project_id = %d
134 114 and page_id = %d
135 115 ",
136 - array(
116 + [
137 117 $project_id,
138 118 $page_id,
139 - )
119 + ]
140 120 );
121 + $project_page = $wpdb->get_results( $query, 'ARRAY_A' ); // WPCS: unprepared SQL OK; db call ok; no-cache ok.
141 122
142 - $project_page = $wpdb->get_results( $query, 'ARRAY_A' ); // phpcs:ignore WordPress.DB.PreparedSQL
143 - if ( 0 === $wpdb->num_rows ) {
144 - return;
145 - }
123 + $table_name = $project_page[0]['page_table_name'];
124 + $relationships = WPDP_Project_Design_Table_Model::get_column_options( $table_name, 'relationships' );
146 125
147 - $schema_name = $project_page[0]['page_schema_name'];
148 - $table_name = $project_page[0]['page_table_name'];
149 - $page_setname = $project_page[0]['page_setname'];
150 -
151 - $relationships = WPDP_Project_Design_Table_Model::get_column_options( $table_name, 'relationships', $page_setname, $schema_name );
152 - if ( ! isset( $relationships['relationships'] ) || null === $relationships['relationships'] ) {
153 - $this->project =
154 - array(
155 - 'mode' => $project_page[0]['page_mode'],
156 - 'setname' => $page_setname,
157 - 'title' => $project_page[0]['page_title'],
158 - 'subtitle' => $project_page[0]['page_subtitle'],
159 - 'parent' => array(),
160 - 'children' => array(),
161 - 'page_allow_full_export' => $project_page[0]['page_allow_full_export'],
162 - );
163 -
164 - return;
165 - }
166 -
167 - // Add parent column and data type
168 - $wpda_list_columns = WPDA_List_Columns_Cache::get_list_columns( $schema_name, $table_name );
126 + $wpda_list_columns = WPDA_List_Columns_Cache::get_list_columns( '', $table_name );
169 127 $parent_primary_key = $wpda_list_columns->get_table_primary_key();
170 - $parent_primary_key_data_type = array();
128 + $parent_primary_key_data_type = [];
171 129 foreach ( $parent_primary_key as $pk ) {
172 130 if ( isset( $relationships['table'] ) && null !== $relationships['table'] ) {
173 131 foreach ( $relationships['table'] as $column ) {
174 132 if ( $column->column_name === $pk ) {
175 - array_push( $parent_primary_key_data_type, WPDA::get_type( $column->data_type ) );//phpcs:ignore - 8.1 proof
133 + array_push( $parent_primary_key_data_type, WPDA::get_type( $column->data_type ) );
176 134 break;
177 135 }
178 136 }
179 137 }
180 138 }
139 + $parent = [
140 + 'key' => $parent_primary_key,
141 + 'data_type' => $parent_primary_key_data_type,
142 + ];
181 143
182 - // Add children
183 - $children = array();
184 - foreach ( $relationships['relationships'] as $relationship ) {
185 - $child_key_data_type = array();
186 - if ( '1n' === $relationship->relation_type ) {
187 - $n_relationship = WPDP_Project_Design_Table_Model::get_column_options( $relationship->target_table_name, 'tableinfo', $page_setname, $schema_name );
144 + $children = [];
145 + if ( isset( $relationships['relationships'] ) && null !== $relationships['relationships'] ) {
146 + foreach ( $relationships['relationships'] as $relationship ) {
147 + $child_key_data_type = [];
148 + if ( '1n' === $relationship->relation_type || 'lookup' === $relationship->relation_type ) {
149 + $n_relationship = WPDP_Project_Design_Table_Model::get_column_options( $relationship->target_table_name, 'tableinfo' );
188 150
189 - if ( isset( $n_relationship->tab_label ) ) {
190 - $tab_label = $n_relationship->tab_label;
191 - } else {
192 - $tab_label = '';
193 - }
151 + if ( isset( $n_relationship->tab_label ) ) {
152 + $tab_label = $n_relationship->tab_label;
153 + } else {
154 + $tab_label = '';
155 + }
194 156
195 - foreach ( $relationship->source_column_name as $source_column_name ) {
196 - if ( ! in_array( $source_column_name, $parent_primary_key ) ) {
197 - array_push( $parent_primary_key, $source_column_name );//phpcs:ignore - 8.1 proof
198 - foreach ( $relationships['table'] as $column ) {
199 - if ( $column->column_name === $source_column_name ) {
200 - array_push( $parent_primary_key_data_type, WPDA::get_type( $column->data_type ) );//phpcs:ignore - 8.1 proof
157 + foreach ( $relationships['table'] as $column ) {
158 + foreach ( $relationship->target_column_name as $target_column_name ) {
159 + if ( $column->column_name === $target_column_name ) {
160 + array_push( $child_key_data_type, WPDA::get_type( $column->data_type ) );
201 161 break;
202 162 }
203 163 }
204 164 }
205 - }
165 + $child = [
166 + 'table_name' => $relationship->target_table_name,
167 + 'tab_label' => $tab_label === '' ? $relationship->target_table_name : $tab_label,
168 + 'relation_' . $relationship->relation_type => [
169 + 'child_key' => $relationship->target_column_name,
170 + 'data_type' => $child_key_data_type,
171 + ]
172 + ];
173 + array_push( $children, $child );
174 + } elseif ( 'nm' === $relationship->relation_type ) {
175 + $nm_relationships = WPDP_Project_Design_Table_Model::get_column_options( $relationship->relation_table_name, 'relationships' );
206 176
207 - foreach ( $relationship->target_column_name as $target_column_name ) {
208 - foreach ( $relationships['table'] as $column ) {
209 - if ( $column->column_name === $target_column_name ) {
210 - array_push( $child_key_data_type, WPDA::get_type( $column->data_type ) );//phpcs:ignore - 8.1 proof
211 - break;
212 - }
177 + if ( isset( $nm_relationships['tableinfo'] ) && isset( $nm_relationships['tableinfo']->tab_label ) ) {
178 + $tab_label = $nm_relationships['tableinfo']->tab_label;
179 + } else {
180 + $tab_label = '';
213 181 }
214 - }
215 182
216 - $child = array(
217 - 'table_name' => $relationship->target_table_name,
218 - 'tab_label' => $tab_label === '' ? $relationship->target_table_name : $tab_label,
219 - 'default_where' => isset( $n_relationship->default_where ) ? $n_relationship->default_where : '',
220 - 'default_orderby' => isset( $n_relationship->default_orderby ) ? $n_relationship->default_orderby : '',
221 - 'relation_' . $relationship->relation_type => array(
222 - 'parent_key' => $relationship->source_column_name,
223 - 'child_key' => $relationship->target_column_name,
224 - 'data_type' => $child_key_data_type,
225 - ),
226 - );
227 - array_push( $children, $child );//phpcs:ignore - 8.1 proof
228 - } elseif ( 'nm' === $relationship->relation_type ) {
229 - $nm_relationships = WPDP_Project_Design_Table_Model::get_column_options( $relationship->relation_table_name, 'relationships', $page_setname, $schema_name );
230 -
231 - if ( isset( $nm_relationships['tableinfo'] ) && isset( $nm_relationships['tableinfo']->tab_label ) ) {
232 - $tab_label = $nm_relationships['tableinfo']->tab_label;
233 - } else {
234 - $tab_label = '';
235 - }
236 -
237 - if ( isset( $nm_relationships['relationships'] ) && null !== $nm_relationships['relationships'] ) {
238 - $nm_relationship_found = null;
239 - foreach ( $nm_relationships['relationships'] as $nm_relationship ) {
240 - if ( $nm_relationship->target_table_name === $relationship->target_table_name ) {
241 - $nm_relationship_found = $nm_relationship;
242 - break;
183 + if ( null !== $nm_relationships['relationships'] ) {
184 + $nm_relationship_found = null;
185 + foreach ( $nm_relationships['relationships'] as $nm_relationship ) {
186 + if ( $nm_relationship->target_table_name === $relationship->target_table_name ) {
187 + $nm_relationship_found = $nm_relationship;
188 + break;
189 + }
243 190 }
244 - }
245 -
246 - if ( null !== $nm_relationship_found ) {
247 191 foreach ( $nm_relationship_found->source_column_name as $source_column_name ) {
248 192 foreach ( $nm_relationships['table'] as $column ) {
249 193 if ( $column->column_name === $source_column_name ) {
250 - array_push( $child_key_data_type, WPDA::get_type( $column->data_type ) );//phpcs:ignore - 8.1 proof
251 - if ( ! in_array( $source_column_name, $parent_primary_key ) ) {//phpcs:ignore - 8.1 proof
252 - array_push( $parent_primary_key, $source_column_name );//phpcs:ignore - 8.1 proof
253 - array_push( $parent_primary_key_data_type, WPDA::get_type( $column->data_type ) );//phpcs:ignore - 8.1 proof
254 - }
194 + array_push( $child_key_data_type, WPDA::get_type( $column->data_type ) );
255 195 break;
256 196 }
257 197 }
258 198 }
259 -
260 - $child = array(
261 - 'table_name' => $relationship->relation_table_name,
262 - 'tab_label' => $tab_label === '' ? $relationship->relation_table_name : $tab_label,
263 - 'default_where' => isset( $nm_relationships['tableinfo']->default_where ) ? $nm_relationships['tableinfo']->default_where : '',
264 - 'default_orderby' => isset( $nm_relationships['tableinfo']->default_orderby ) ? $nm_relationships['tableinfo']->default_orderby : '',
265 - 'relation_nm' => array(
199 + $child = [
200 + 'table_name' => $relationship->relation_table_name,
201 + 'tab_label' => $tab_label === '' ? $relationship->relation_table_name : $tab_label,
202 + 'relation_nm' => [
266 203 'child_table' => $relationship->target_table_name,
267 204 'parent_key' => $nm_relationship->source_column_name,
268 205 'child_table_select' => $nm_relationship->target_column_name,
269 206 'child_table_where' => $relationship->target_column_name,
270 207 'data_type' => $child_key_data_type,
271 - ),
272 - );
273 - array_push( $children, $child );//phpcs:ignore - 8.1 proof
208 + ]
209 + ];
210 + array_push( $children, $child );
274 211 }
275 212 }
276 213 }
277 214 }
278 215
279 - // Prepare parent key
280 - $parent = array(
281 - 'key' => $parent_primary_key,
282 - 'data_type' => $parent_primary_key_data_type,
283 - );
216 + $this->project =
217 + [
218 + 'mode' => $project_page[0]['page_mode'],
219 + 'title' => $project_page[0]['page_title'],
220 + 'subtitle' => $project_page[0]['page_subtitle'],
221 + 'parent' => $parent,
222 + 'children' => $children,
223 + ];
284 224
285 - $this->project =
286 - array(
287 - 'mode' => $project_page[0]['page_mode'],
288 - 'setname' => $page_setname,
289 - 'title' => $project_page[0]['page_title'],
290 - 'subtitle' => $project_page[0]['page_subtitle'],
291 - 'parent' => $parent,
292 - 'children' => $children,
293 - 'page_allow_full_export' => $project_page[0]['page_allow_full_export'],
294 - );
295 225 }
296 226
297 227
298 228 /**
299 - * Returns the project structure
300 - *
301 - * @return array
229 + * @return mixed
302 230 */
303 231 public function get_project() {
304 232 return $this->project;
305 233 }
@@ -304,11 +232,9 @@
304 232 return $this->project;
305 233 }
306 234
307 235 /**
308 - * Returns the project mode or null if not available
309 - *
310 - * @return string|null
236 + * @return null
311 237 */
312 238 public function get_mode() {
313 239 if ( isset( $this->project['mode'] ) ) {
314 240 return $this->project['mode'];
@@ -317,25 +243,10 @@
317 243 }
318 244 }
319 245
320 246 /**
321 - * Returns the project setname or null if not available
322 - *
323 - * @return string|null
247 + * @return null
324 248 */
325 - public function get_setname() {
326 - if ( isset( $this->project['setname'] ) ) {
327 - return $this->project['setname'];
328 - } else {
329 - return null;
330 - }
331 - }
332 -
333 - /**
334 - * Returns the project title or null if not available
335 - *
336 - * @return string|null
337 - */
338 249 public function get_title() {
339 250 if ( isset( $this->project['title'] ) ) {
340 251 return $this->project['title'];
341 252 } else {
@@ -343,11 +254,9 @@
343 254 }
344 255 }
345 256
346 257 /**
347 - * Returns the project sub title or null if not available
348 - *
349 - * @return string|null
258 + * @return null
350 259 */
351 260 public function get_subtitle() {
352 261 if ( isset( $this->project['subtitle'] ) ) {
353 262 return $this->project['subtitle'];
@@ -356,11 +265,9 @@
356 265 }
357 266 }
358 267
359 268 /**
360 - * Returns the project parent info or null if not available
361 - *
362 - * @return array|null
269 + * @return null
363 270 */
364 271 public function get_parent() {
365 272 if ( isset( $this->project['parent'] ) ) {
366 273 return $this->project['parent'];
@@ -369,11 +276,9 @@
369 276 }
370 277 }
371 278
372 279 /**
373 - * Returns the project children or null if not available
374 - *
375 - * @return array|null
280 + * @return null
376 281 */
377 282 public function get_children() {
378 283 if ( isset( $this->project['children'] ) ) {
379 284 return $this->project['children'];
@@ -378,21 +283,8 @@
378 283 if ( isset( $this->project['children'] ) ) {
379 284 return $this->project['children'];
380 285 } else {
381 286 return null;
382 - }
383 - }
384 -
385 - /**
386 - * Is the user allowed to start a full export to CSV or JSON
387 - *
388 - * @return string yes or no
389 - */
390 - public function get_page_allow_full_export() {
391 - if ( isset( $this->project['page_allow_full_export'] ) ) {
392 - return $this->project['page_allow_full_export'];
393 - } else {
394 - return 'no';
395 287 }
396 288 }
397 289
398 290 }