| 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\WPDA; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class WPDA_Table_Settings_Model |
| 15 |
* |
| 16 |
* Model for plugin table 'table_settings' |
| 17 |
* |
| 18 |
* @author Peter Schulz |
| 19 |
* @since 2.6.0 |
| 20 |
*/ |
| 21 |
class WPDA_Table_Settings_Model extends WPDA_Plugin_Table_Base_Model { |
| 22 |
|
| 23 |
const BASE_TABLE_NAME = 'wpda_table_settings'; |
| 24 |
|
| 25 |
public static function query( $table_name, $schema_name ) { |
| 26 |
global $wpdb; |
| 27 |
if ( '' === $schema_name ) { |
| 28 |
$schema_name = $wpdb->dbname; |
| 29 |
} |
| 30 |
|
| 31 |
return $wpdb->get_results( |
| 32 |
$wpdb->prepare( |
| 33 |
'SELECT wpda_table_settings FROM `%1s` WHERE wpda_schema_name = %s AND wpda_table_name = %s', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders |
| 34 |
array( |
| 35 |
WPDA::remove_backticks( static::get_base_table_name() ), |
| 36 |
$schema_name, |
| 37 |
$table_name, |
| 38 |
) |
| 39 |
), |
| 40 |
'ARRAY_A' |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Insert a record in the base table |
| 46 |
* |
| 47 |
* @param string $table_name Table name |
| 48 |
* @param string $table_settings Table settings |
| 49 |
* @param string $schema_name Schema name |
| 50 |
* |
| 51 |
* @return bool TRUE = Insert was successful |
| 52 |
*/ |
| 53 |
public static function insert( $table_name, $table_settings, $schema_name ) { |
| 54 |
global $wpdb; |
| 55 |
|
| 56 |
return ( 1 === $wpdb->insert( |
| 57 |
static::get_base_table_name(), |
| 58 |
array( |
| 59 |
'wpda_schema_name' => $schema_name, |
| 60 |
'wpda_table_name' => $table_name, |
| 61 |
'wpda_table_settings' => $table_settings, |
| 62 |
) |
| 63 |
) |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Update a record in the base table |
| 69 |
* |
| 70 |
* @param string $table_name Table name |
| 71 |
* @param string $table_settings Table settings |
| 72 |
* @param string $schema_name Schema name |
| 73 |
* |
| 74 |
* @return mixed Transaction status |
| 75 |
*/ |
| 76 |
public static function update( $table_name, $table_settings, $schema_name ) { |
| 77 |
global $wpdb; |
| 78 |
|
| 79 |
return $wpdb->update( |
| 80 |
static::get_base_table_name(), |
| 81 |
array( |
| 82 |
'wpda_table_settings' => $table_settings, |
| 83 |
), |
| 84 |
array( |
| 85 |
'wpda_schema_name' => $schema_name, |
| 86 |
'wpda_table_name' => $table_name, |
| 87 |
) |
| 88 |
); |
| 89 |
} |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
} |
| 94 |
|