PluginProbe
Database Addon For WPForms ( wpforms entries ) – WPFormsDB / trunk
Database Addon For WPForms ( wpforms entries ) – WPFormsDB vtrunk
trunk 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.8.1 1.0.9 1.1.0
database-for-wpforms / inc / class-main-page.php

class-main-page.php in Database Addon For WPForms ( wpforms entries ) – WPFormsDB trunk, at inc/class-main-page.php

192 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPFormsDB Admin section
4 */
5
6 if (!defined( 'ABSPATH')) exit;
7
8 /**
9 * WPFormsDB_Wp_List_Table class will create the page to load the table
10 */
11 class WPFormsDB_Wp_Main_Page
12 {
13 /**
14 * Constructor will create the menu item
15 */
16 public function __construct()
17 {
18 add_action( 'admin_menu', array($this, 'admin_list_table_page' ) );
19 }
20
21
22 /**
23 * Menu item will allow us to load the page to display the table
24 */
25 public function admin_list_table_page()
26 {
27
28 // Fallback: Make sure admin always has access
29 $WPFormsDB_cap = ( current_user_can( 'WPFormsDB_access') ) ? 'WPFormsDB_access' : 'manage_options';
30
31 add_menu_page( __( 'WPForms Submissions', 'contact-form-WPFormsDB' ), __( 'WPForms DB', 'contact-form-WPFormsDB' ),
32 $WPFormsDB_cap, 'wp-forms-db-list.php', array($this, 'list_table_page'),
33 'data:image/svg+xml;base64,' . base64_encode('<?xml version="1.0" ?><svg id="Layer_1" style="enable-background:new 0 0 50 50;" version="1.1" viewBox="0 0 50 50" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Layer_1_1_"><path d="M5,7v42h34v-6h6V1H11v6H5z M37,47H7V9h4h19v7h7v27V47z M32,10.414L35.586,14H32V10.414z M13,3h30v38h-4V14.586L31.414,7H13 V3z"/><rect height="2" width="22" x="11" y="20"/><rect height="2" width="22" x="11" y="26"/><rect height="2" width="22" x="11" y="32"/><rect height="2" width="9" x="11" y="40"/><rect height="2" width="9" x="24" y="40"/><rect height="2" width="8" x="18" y="14"/></g></svg>'));
34
35 wp_enqueue_style( 'wpformsdb-admin-style', plugin_dir_url(dirname(__FILE__)).'admin-style.css', [], '1.0.7' );
36
37 require 'addons.php';
38 }
39 /**
40 * Display the list table page
41 *
42 * @return Void
43 */
44 public function list_table_page()
45 {
46 if ( ! function_exists('wpforms') ) {
47
48 wp_die( 'Please activate <a href="https://wordpress.org/plugins/wpforms-lite/" target="_blank">WPForms</a> plugin.' );
49 }
50
51 $fid = empty($_GET['fid']) ? 0 : (int) $_GET['fid'];
52 $ufid = empty($_GET['ufid']) ? 0 : (int) $_GET['ufid'];
53
54 if ( !empty($fid) && empty($_GET['ufid']) ) {
55
56 new WPFormsDB_Wp_Sub_Page();
57 return;
58 }
59
60 if( !empty($ufid) && !empty($fid) ){
61
62 new WPFormsDB_Form_Details();
63 return;
64 }
65
66 $ListTable = new WPFormsDB_Main_List_Table();
67 $ListTable->prepare_items();
68 ?>
69 <div class="wrap">
70 <div id="icon-users" class="icon32"></div>
71 <h2><?php esc_html_e( 'WPForms List', 'database-for-wpforms' ); ?></h2>
72 <?php $ListTable->display(); ?>
73 </div>
74 <?php
75 }
76
77 }
78 // WP_List_Table is not loaded automatically so we need to load it in our application
79 if( ! class_exists( 'WP_List_Table' ) ) {
80 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
81 }
82 /**
83 * Create a new table class that will extend the WP_List_Table
84 */
85 class WPFormsDB_Main_List_Table extends WP_List_Table
86 {
87
88 /**
89 * Prepare the items for the table to process
90 *
91 * @return Void
92 */
93 public function prepare_items()
94 {
95
96 $columns = $this->get_columns();
97 $hidden = $this->get_hidden_columns();
98 $data = $this->table_data();
99 $perPage = 10;
100 $currentPage = $this->get_pagenum();
101 $count_forms = wp_count_posts('wpforms');
102 $totalItems = $count_forms->publish;
103
104
105 $this->set_pagination_args( array(
106 'total_items' => $totalItems,
107 'per_page' => $perPage
108 ) );
109
110 $this->_column_headers = array($columns, $hidden );
111 $this->items = $data;
112 }
113
114 /**
115 * Override the parent columns method. Defines the columns to use in your listing table
116 *
117 * @return Array
118 */
119 public function get_columns()
120 {
121
122
123 $columns = array(
124 'name' => __( 'Name', 'contact-form-WPFormsDB' ),
125 'count'=> __( 'Count', 'contact-form-WPFormsDB' )
126 );
127
128 return $columns;
129 }
130 /**
131 * Define which columns are hidden
132 *
133 * @return Array
134 */
135 public function get_hidden_columns()
136 {
137 return array();
138 }
139
140 /**
141 * Get the table data
142 *
143 * @return Array
144 */
145 private function table_data()
146 {
147 global $wpdb;
148
149 $cfdb = apply_filters( 'WPFormsDB_database', $wpdb );
150 $data = array();
151 $table_name = $cfdb->prefix.'wpforms_db';
152 $page = $this->get_pagenum();
153 $page = $page - 1;
154 $start = $page * 10;
155
156 $args = array(
157 'post_type'=> 'wpforms',
158 'order' => 'ASC',
159 'posts_per_page' => 10,
160 'offset' => $start
161 );
162
163 $the_query = new WP_Query( $args );
164
165 while ( $the_query->have_posts() ) : $the_query->the_post();
166 $form_post_id = get_the_id();
167 $totalItems = $cfdb->get_var("SELECT COUNT(*) FROM $table_name WHERE form_post_id = $form_post_id");
168 $title = get_the_title();
169 $link = "<a class='row-title' href=admin.php?page=wp-forms-db-list.php&fid=$form_post_id>%s</a>";
170 $data_value['name'] = sprintf( $link, $title );
171 $data_value['count'] = sprintf( $link, $totalItems );
172 $data[] = $data_value;
173 endwhile;
174
175 return $data;
176 }
177 /**
178 * Define what data to show on each column of the table
179 *
180 * @param Array $item Data
181 * @param String $column_name - Current column name
182 *
183 * @return Mixed
184 */
185 public function column_default( $item, $column_name )
186 {
187 return $item[ $column_name ];
188
189 }
190
191 }
192