PluginProbe
WP Data Access – App Builder for Tables, Forms, Dashboards, Charts & Maps / 2.0.13
WP Data Access – App Builder for Tables, Forms, Dashboards, Charts & Maps v2.0.13
5.5.87 5.5.85 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 All 162 releases
← All changes | WPDataProjects/Project/WPDP_Project_Page_Form.php +47 -207 5.5.3 → 2.0.13 View file →
@@ -1,26 +1,20 @@
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
11 10 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists;
12 - use WPDataAccess\Plugin_Table_Models\WPDP_Project_Design_Table_Model;
13 - use WPDataAccess\Simple_Form\WPDA_Simple_Form_Item_Enum;
14 - use WPDataAccess\Simple_Form\WPDA_Simple_Form_Item_Set;
15 - use WPDataAccess\WPDA;
16 11 use WPDataProjects\Parent_Child\WPDP_Child_Form;
17 12
18 13 /**
19 - * Class WPDP_Project_Page_Form extends WPDP_Child_Form
14 + * Class WPDP_Project_Page_Form
20 15 *
21 - * @see WPDP_Child_Form
22 - *
16 + * @package WPDataProjects\Project
23 17 * @author Peter Schulz
24 18 * @since 2.0.0
25 19 */
26 20 class WPDP_Project_Page_Form extends WPDP_Child_Form {
@@ -32,103 +26,38 @@
32 26 * @param $table_name
33 27 * @param $wpda_list_columns
34 28 * @param array $args
35 29 */
36 - public function __construct( $schema_name, $table_name, $wpda_list_columns, array $args = array() ) {
30 + public function __construct( $schema_name, $table_name, $wpda_list_columns, array $args = [] ) {
37 31 // Add column labels.
38 - $args['column_headers'] = array(
39 - 'project_id' => __( 'Project ID', 'wp-data-access' ),
40 - 'page_id' => __( 'Page ID', 'wp-data-access' ),
41 - 'add_to_menu' => __( 'Add To Menu', 'wp-data-access' ),
42 - 'page_name' => __( 'Menu Name', 'wp-data-access' ),
43 - 'page_type' => __( 'Type', 'wp-data-access' ),
44 - 'page_schema_name' => __( 'Schema Name', 'wp-data-access' ),
45 - 'page_table_name' => __( 'Table Name', 'wp-data-access' ),
46 - 'page_setname' => __( 'Template Set Name', 'wp-data-access' ),
47 - 'page_mode' => __( 'Mode', 'wp-data-access' ),
48 - 'page_allow_insert' => __( 'Allow insert?', 'wp-data-access' ),
49 - 'page_allow_delete' => __( 'Allow delete?', 'wp-data-access' ),
50 - 'page_allow_import' => __( 'Allow import?', 'wp-data-access' ),
51 - 'page_allow_bulk' => __( 'Allow bulk actions?', 'wp-data-access' ),
52 - 'page_allow_full_export' => __( 'Allow full table export?', 'wp-data-access' ),
53 - 'page_content' => __( 'Post', 'wp-data-access' ),
54 - 'page_title' => __( 'Title', 'wp-data-access' ),
55 - 'page_subtitle' => __( 'Subtitle', 'wp-data-access' ),
56 - 'page_role' => __( 'Role', 'wp-data-access' ),
57 - 'page_where' => __( 'WHERE Clause', 'wp-data-access' ),
58 - 'page_orderby' => __( 'Default ORDER BY', 'wp-data-access' ),
59 - 'page_sequence' => __( 'Seq#', 'wp-data-access' ),
60 - );
32 + $args['column_headers'] = [
33 + 'project_id' => __( 'Project ID', 'wp-data-access' ),
34 + 'page_id' => __( 'Page ID', 'wp-data-access' ),
35 + 'add_to_menu' => __( 'Add To Menu', 'wp-data-access' ),
36 + 'page_name' => __( 'Menu Name', 'wp-data-access' ),
37 + 'page_type' => __( 'Type', 'wp-data-access' ),
38 + 'page_table_name' => __( 'Table Name', 'wp-data-access' ),
39 + 'page_mode' => __( 'Mode', 'wp-data-access' ),
40 + 'page_allow_insert' => __( 'Allow insert?', 'wp-data-access' ),
41 + 'page_allow_delete' => __( 'Allow delete?', 'wp-data-access' ),
42 + 'page_content' => __( 'Post', 'wp-data-access' ),
43 + 'page_title' => __( 'Title', 'wp-data-access' ),
44 + 'page_subtitle' => __( 'Subtitle', 'wp-data-access' ),
45 + 'page_role' => __( 'Role', 'wp-data-access' ),
46 + 'page_where' => __( 'WHERE Clause', 'wp-data-access' ),
47 + 'page_sequence' => __( 'Seq#', 'wp-data-access' ),
48 + ];
61 49
62 50 parent::__construct( $schema_name, $table_name, $wpda_list_columns, $args );
63 51 }
64 52
65 53 /**
66 - * Overwrites method prepare_items for specific user interaction
67 - *
68 54 * @param bool $set_back_form_values
69 55 */
70 56 protected function prepare_items( $set_back_form_values = false ) {
57 +
71 58 parent::prepare_items( $set_back_form_values );
72 59
73 - // Get available databases
74 - $schema_names = WPDA_Dictionary_Lists::get_db_schemas();
75 - $databases = array();
76 - foreach ( $schema_names as $schema_name ) {
77 - array_push( $databases, $schema_name['schema_name'] );//phpcs:ignore - 8.1 proof
78 - }
79 -
80 - $tables = array();
81 - $column_index = $this->get_item_index( 'page_schema_name' );
82 - if ( false !== $column_index ) {
83 - $pub_schema_name = $this->form_items[ $column_index ]->get_item_value();
84 - if ( '' === $pub_schema_name || null === $pub_schema_name ) {
85 - $pub_schema_name = WPDA::get_user_default_scheme();
86 - }
87 -
88 - // Check table access to prepare table listbox content
89 - global $wpdb;
90 - if ( $wpdb->dbname === $pub_schema_name ) {
91 - $table_access = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS );
92 - } else {
93 - $table_access = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_ACCESS . $pub_schema_name );
94 - if ( false === $table_access ) {
95 - $table_access = 'show';
96 - }
97 - }
98 - switch ( $table_access ) {
99 - case 'show':
100 - $tables = $this->get_all_db_tables( $pub_schema_name );
101 - break;
102 - case 'hide':
103 - $tables = $this->get_all_db_tables( $pub_schema_name );
104 - // Remove WordPress tables from listbox content
105 - $tables_named = array();
106 - foreach ( $tables as $table ) {
107 - $tables_named[ $table ] = true;
108 - }
109 - foreach ( $wpdb->tables( 'all', true ) as $wp_table ) {
110 - unset( $tables_named[ $wp_table ] );
111 - }
112 - $tables = array();
113 - foreach ( $tables_named as $key => $value ) {
114 - array_push( $tables, $key );//phpcs:ignore - 8.1 proof
115 - }
116 - break;
117 - default:
118 - // Show only selected tables and views
119 - if ( $wpdb->dbname === $pub_schema_name ) {
120 - $tables = WPDA::get_option( WPDA::OPTION_BE_TABLE_ACCESS_SELECTED );
121 - } else {
122 - $tables = get_option( WPDA::BACKEND_OPTIONNAME_DATABASE_SELECTED . $pub_schema_name );
123 - if ( false === $tables ) {
124 - $tables = array();
125 - }
126 - }
127 - }
128 - }
129 -
130 - $i = 0;
131 60 foreach ( $this->form_items as $item ) {
132 61 if ( 'page_type' === $item->get_item_name() ) {
133 62 $item_js =
134 63 'function set_item_visibility(page_type) { ' .
@@ -145,9 +74,9 @@
145 74 ' jQuery(\'[name="page_allow_delete"]\').parent().parent().show(); ' .
146 75 ' jQuery(\'[name="page_content"]\').parent().parent().hide(); ' .
147 76 ' } ' .
148 77 '} ' .
149 - 'jQuery(function () { ' .
78 + 'jQuery(document).ready(function () { ' .
150 79 ' jQuery(\'[name="page_type"]\').change(function() { ' .
151 80 ' set_item_visibility(jQuery(this).val()); ' .
152 81 ' }); ' .
153 82 ' set_item_visibility(jQuery(\'[name="page_type"]\').val()); ' .
@@ -154,142 +83,53 @@
154 83 '});';
155 84 $item->set_item_js( $item_js );
156 85 } elseif ( 'page_content' === $item->get_item_name() ) {
157 86 $posts = get_posts(
158 - array(
87 + [
159 88 'post_status' => '%',
160 89 'orderby' => 'ID',
161 - )
90 + ]
162 91 );
163 92
164 - $lov = array();
165 - $lov_options = array();
93 + $lov = [];
94 + $lov_options = [];
166 95 // For some reason get_posts always sorts DESC on ID: reverse array.
167 - $posts_reverse = array_reverse( $posts );//phpcs:ignore - 8.1 proof
96 + $posts_reverse = array_reverse( $posts );
168 97 // Set first element to blank.
169 - array_push( $lov, '' );//phpcs:ignore - 8.1 proof
170 - array_push( $lov_options, '0' );//phpcs:ignore - 8.1 proof
98 + array_push( $lov, '' );
99 + array_push( $lov_options, '0' );
171 100 foreach ( $posts_reverse as $post ) {
172 101 $post_element = $post->post_title . ' (ID=' . $post->ID . ')';
173 - array_push( $lov, $post_element );//phpcs:ignore - 8.1 proof
174 - array_push( $lov_options, $post->ID );//phpcs:ignore - 8.1 proof
102 + array_push( $lov, $post_element );
103 + array_push( $lov_options, $post->ID );
175 104 }
176 105
106 + $item->set_data_type( 'enum' );
177 107 $item->set_enum( $lov );
178 108 $item->set_enum_options( $lov_options );
179 - $this->form_items[ $i ] = new WPDA_Simple_Form_Item_Enum( $item );
180 - } elseif ( 'page_schema_name' === $item->get_item_name() ) {
181 - // Prepare listbox for column pub_schema_name
182 - if ( '' === $item->get_item_value() || null === $item->get_item_value() ) {
183 - $item->set_item_value( WPDA::get_user_default_scheme() );
109 + $item->set_item_hide_icon( true );
110 + } elseif ( 'page_table_name' === $item->get_item_name() ) {
111 + $wpda_dictionary_lists = WPDA_Dictionary_Lists::get_tables();
112 + $lov = [];
113 + array_push( $lov, '' );
114 + foreach ( $wpda_dictionary_lists as $dictionary_list ) {
115 + array_push( $lov, $dictionary_list['table_name'] );
184 116 }
185 - $item->set_enum( $databases );
186 - $this->form_items[ $i ] = new WPDA_Simple_Form_Item_Enum( $item );
187 - } elseif ( 'page_table_name' === $item->get_item_name() ) {
188 - $item->set_enum( $tables );
189 - $this->form_items[ $i ] = new WPDA_Simple_Form_Item_Enum( $item );
117 + $item->set_data_type( 'enum' );
118 + $item->set_enum( $lov );
190 119 } elseif ( 'page_role' === $item->get_item_name() ) {
191 120 global $wp_roles;
192 - $lov = array();
193 - $lov_options = array();
121 + $lov = [];
194 122 foreach ( $wp_roles->roles as $role => $val ) {
195 - array_push( $lov_options, $role );//phpcs:ignore - 8.1 proof
196 - array_push( $lov, isset( $val['name'] ) ? $val['name'] : $role );//phpcs:ignore - 8.1 proof
123 + array_push( $lov, $role );
197 124 }
125 + $item->set_data_type( 'set' );
198 126 $item->set_enum( $lov );
199 - $item->set_enum_options( $lov_options );
200 - $this->form_items[ $i ] = new WPDA_Simple_Form_Item_Set( $item );
201 - } elseif ( 'page_setname' === $item->get_item_name() ) {
202 - global $wpdb;
203 - $setnames = $wpdb->get_results(
204 - $wpdb->prepare(
205 - 'select distinct wpda_table_setname from `%1s` order by wpda_table_setname', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
206 - array(
207 - WPDA::remove_backticks( WPDP_Project_Design_Table_Model::get_base_table_name() ),
208 - )
209 - ),
210 - 'ARRAY_A'
211 - );
212 - $lov = array();
213 - foreach ( $setnames as $setname ) {
214 - array_push( $lov, $setname['wpda_table_setname'] );//phpcs:ignore - 8.1 proof
215 - }
216 - if ( 0 === count( $lov ) ) {//phpcs:ignore - 8.1 proof
217 - array_push( $lov, 'default' );//phpcs:ignore - 8.1 proof
218 - }
219 - $item->set_enum( $lov );
220 - $this->form_items[ $i ] = new WPDA_Simple_Form_Item_Enum( $item );
221 - } elseif ( 'page_allow_full_export' === $item->get_item_name() ) {
222 - if ( wpda_freemius()->is_free_plan() ) {
223 - $item->set_hide_item( true );
224 - }
127 + $item->set_item_hide_icon( true );
225 128 }
226 - $i ++;
227 129 }
228 - }
229 130
230 - /**
231 - * Get all db tables and views
232 - *
233 - * @param string $database Database schema name
234 - *
235 - * @return array
236 - */
237 - protected function get_all_db_tables( $database ) {
238 - $tables = array();
239 - $db_tables = WPDA_Dictionary_Lists::get_tables( true, $database ); // select all db tables and views
240 - foreach ( $db_tables as $db_table ) {
241 - //phpcs:ignore - 8.1 proof
242 - array_push( $tables, $db_table['table_name'] ); // add table or view to array
243 - }
244 -
245 - return $tables;
246 131 }
247 132
248 - /**
249 - * Overwrites method show
250 - *
251 - * @param bool $allow_save
252 - * @param string $add_param
253 - */
254 - public function show( $allow_save = true, $add_param = '' ) {
255 - parent::show( $allow_save, $add_param );
256 -
257 - global $wpdb;
258 - ?>
259 - <script type='text/javascript'>
260 - function update_table_list(schema_name) {
261 - var url = location.pathname + '?action=wpda_get_tables';
262 - var data = {
263 - wpdaschema_name: schema_name,
264 - wpda_wpnonce: '<?php echo esc_attr( wp_create_nonce( 'wpda-getdata-access-' . WPDA::get_current_user_login() ) ); ?>'
265 - };
266 - jQuery.post(
267 - url,
268 - data,
269 - function (data) {
270 - jQuery('#page_table_name').empty();
271 -
272 - var tables = JSON.parse(data);
273 - for (var i = 0; i < tables.length; i++) {
274 - jQuery('<option/>', {
275 - value: tables[i].table_name,
276 - html: tables[i].table_name
277 - }).appendTo("#page_table_name");
278 - }
279 - }
280 - );
281 - }
282 - jQuery(function () {
283 - jQuery("#page_schema_name option[value='<?php echo esc_attr( $wpdb->dbname ); ?>']").text("WordPress database (<?php echo esc_attr( $wpdb->dbname ); ?>)");
284 - jQuery('#page_allow_full_export').parent().parent().find('.icon').empty().append('<i title="Adds CSV and JSON full table export buttons to list tables\n\nWorks on back-end pages only" class="fas fa-circle-question pointer wpda_tooltip"></i>');
285 - jQuery('#page_schema_name').on('change', function () {
286 - update_table_list(jQuery(this).val());
287 - });
288 - });
289 - </script>
290 - <?php
291 - }
292 -
293 133 }
294 134
295 -}
135 +}