PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.3
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.3
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 5.5.43 All 159 releases
wp-data-access / WPDataAccess / Design_Table / WPDA_Design_Table_List_Table.php

WPDA_Design_Table_List_Table.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.3, at WPDataAccess/Design_Table/WPDA_Design_Table_List_Table.php

117 lines 3.2 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 WPDataAccess\Design_Table
7 */
8
9 namespace WPDataAccess\Design_Table {
10
11 use WPDataAccess\List_Table\WPDA_List_Table;
12 use WPDataAccess\WPDA;
13
14 /**
15 * Class WPDA_Design_Table_List_Table
16 *
17 * @author Peter Schulz
18 * @since 1.1.0
19 */
20 class WPDA_Design_Table_List_Table extends WPDA_List_Table {
21
22 /**
23 * WPDA_Design_Table_List_Table constructor
24 *
25 * @param array $args See {@see WPDA_List_Table::__construct()}.
26 *
27 * @since 1.1.0
28 *
29 * @see WPDA_List_Table
30 */
31 public function __construct( $args = array() ) {
32 $args['column_headers'] = self::column_headers_labels();
33 $args['title'] = 'Data Designer';
34
35 parent::__construct( $args );
36 }
37
38 /**
39 * Add buttons new and import (overwritten)
40 */
41 protected function add_header_button() {
42 ?>
43 <form
44 method="post"
45 action="?page=<?php echo esc_attr( $this->page ); ?>"
46 style="display: inline-block; vertical-align: baseline;"
47 >
48 <div>
49 <input type="hidden" name="table_name" value="<?php echo esc_attr( $this->table_name ); ?>">
50 <input type="hidden" name="action" value="edit">
51 <button type="submit" class="page-title-action">
52 <i class="fas fa-plus-circle wpda_icon_on_button"></i>
53 <?php echo __( 'Design new table', 'wp-data-access' ); ?>
54 </button>
55 <?php
56 // Add import button to title.
57 if ( null !== $this->wpda_import ) {
58 $this->wpda_import->add_button();
59 }
60 ?>
61 </div>
62 </form>
63 <?php
64 }
65
66 /**
67 * Overwrites method column_default to support static pages
68 *
69 * @param array $item
70 * @param string $column_name
71 *
72 * @return mixed|string
73 */
74 public function column_default( $item, $column_name ) {
75 if ( 'wpda_table_name' === $column_name ) {
76 if ( null !== $item['wpda_table_design'] ) {
77 $table_structure = json_decode( $item['wpda_table_design'], true );
78 if ( isset( $table_structure['table'] ) ) {
79 $column_names = array_column( (array) $table_structure['table'], 'column_name' ); //phpcs:ignore - 8.1 proof
80 } else {
81 $column_names = array();
82 }
83 } else {
84 $column_names = array();
85 }
86 // Validate schema, table and column names
87 $warning = WPDA::validate_names( $item['wpda_schema_name'], $item['wpda_table_name'], $column_names );
88 if ( '' !== $warning ) {
89 return $item['wpda_table_name'] . $warning .
90 substr( parent::column_default( $item, $column_name ), strlen( $item['wpda_table_name'] ) );
91 }
92 }
93
94 if ( 'wpda_schema_name' === $column_name ) {
95 global $wpdb;
96 if ( $wpdb->dbname === $item[ $column_name ] ) {
97 return "WordPress database ({$item[ $column_name ]})";
98 }
99 }
100
101 return parent::column_default( $item, $column_name );
102 }
103
104 public static function column_headers_labels() {
105 return array(
106 'wpda_table_name' => __( 'Table name', 'wp-data-access' ),
107 'wpda_schema_name' => __( 'Database', 'wp-data-access' ),
108 'wpda_table_design' => __( 'Table structure', 'wp-data-access' ),
109 'wpda_date_created' => __( 'Creation date', 'wp-data-access' ),
110 'wpda_last_updated' => __( 'Last updated', 'wp-data-access' ),
111 );
112 }
113
114 }
115
116 }
117