PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.23
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.23
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 / WPDataAccess / Plugin_Table_Models / WPDA_Plugin_Table_Base_Model.php

WPDA_Plugin_Table_Base_Model.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.23, at WPDataAccess/Plugin_Table_Models/WPDA_Plugin_Table_Base_Model.php

91 lines 2.0 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\Plugin_Table_Models
7 */
8
9 namespace WPDataAccess\Plugin_Table_Models {
10
11 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist;
12 use WPDataAccess\WPDA;
13
14 /**
15 * Class WPDA_Plugin_Table_Base_Model
16 *
17 * Base class to handle standard plugin table features
18 *
19 * @author Peter Schulz
20 * @since 2.6.0
21 */
22 class WPDA_Plugin_Table_Base_Model {
23
24 /**
25 * Base table name (without prefixes): MUST BE DEFINED IN SUBCLASS!!!
26 */
27 const BASE_TABLE_NAME = null;
28
29 /**
30 * Check if const BASE_TABLE_NAME is defined (cannot proceed without)
31 */
32 public static function check_base_table_name() {
33 if ( null === static::BASE_TABLE_NAME ) {
34 wp_die( __( 'Wrong usage of class WPDA_Plugin_Table_Base_Model [missing BASE_TABLE_NAME]', 'wp-data-access' ) );
35 }
36 }
37
38 /**
39 * Check if base table exists
40 *
41 * @return bool TRUE = table found
42 */
43 public static function table_exists() {
44 static::check_base_table_name();
45
46 $wpda_dictionary_exist = new WPDA_Dictionary_Exist( '', static::get_base_table_name() );
47 return $wpda_dictionary_exist->table_exists( false );
48 }
49
50 /**
51 * Get base table name
52 *
53 * @return string Base table name
54 */
55 public static function get_base_table_name() {
56 static::check_base_table_name();
57
58 global $wpdb;
59 return $wpdb->prefix . static::BASE_TABLE_NAME;
60 }
61
62 /**
63 * Return number of records in base table
64 *
65 * @return int
66 */
67 public static function count() {
68 static::check_base_table_name();
69
70 global $wpdb;
71 $result = $wpdb->get_results(
72 $wpdb->prepare(
73 'SELECT count(*) AS noitems FROM `%1s` ', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
74 array(
75 WPDA::remove_backticks( static::get_base_table_name() ),
76 )
77 ),
78 'ARRAY_A'
79 ); // phpcs:ignore Standard.Category.SniffName.ErrorCode
80
81 if ( 1 === $wpdb->num_rows ) {
82 return $result[0]['noitems'];
83 } else {
84 return 0;
85 }
86 }
87
88 }
89
90 }
91