| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDataAccess\Plugin_Table_Models { |
| 4 |
|
| 5 |
use WPDataAccess\WPDA; |
| 6 |
|
| 7 |
class WPDA_App_Apps_Model extends WPDA_Plugin_Table_Base_Model { |
| 8 |
|
| 9 |
const BASE_TABLE_NAME = 'wpda_app_apps'; |
| 10 |
|
| 11 |
public static function select_all( $app_id ) { |
| 12 |
|
| 13 |
global $wpdb; |
| 14 |
return $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table |
| 15 |
$wpdb->prepare( |
| 16 |
'SELECT * FROM `%1s` WHERE app_id = %d order by seq_nr', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders |
| 17 |
array( |
| 18 |
WPDA::remove_backticks( self::get_base_table_name() ), |
| 19 |
$app_id, |
| 20 |
) |
| 21 |
), // db call ok; no-cache ok. |
| 22 |
'ARRAY_A' |
| 23 |
); // phpcs:ignore |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
public static function list() { |
| 28 |
|
| 29 |
global $wpdb; |
| 30 |
return $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table |
| 31 |
$wpdb->prepare(' |
| 32 |
SELECT * |
| 33 |
FROM %i |
| 34 |
ORDER BY app_id, seq_nr, app_id_detail |
| 35 |
', |
| 36 |
array( |
| 37 |
WPDA::remove_backticks( self::get_base_table_name() ) |
| 38 |
) |
| 39 |
), |
| 40 |
'ARRAY_A' |
| 41 |
); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
public static function create( |
| 46 |
$app_id, |
| 47 |
$app_id_detail, |
| 48 |
$seq_nr |
| 49 |
) { |
| 50 |
|
| 51 |
global $wpdb; |
| 52 |
if ( 1 === $wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- plugin table |
| 53 |
static::get_base_table_name(), |
| 54 |
array( |
| 55 |
'app_id' => $app_id, |
| 56 |
'app_id_detail' => $app_id_detail, |
| 57 |
'seq_nr' => $seq_nr, |
| 58 |
) |
| 59 |
) |
| 60 |
) { |
| 61 |
return true; |
| 62 |
} else { |
| 63 |
return false; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public static function delete( $app_id, $delete_as_detail = false ) { |
| 68 |
|
| 69 |
global $wpdb; |
| 70 |
|
| 71 |
if ( $delete_as_detail ) { |
| 72 |
$wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table |
| 73 |
static::get_base_table_name(), |
| 74 |
array( |
| 75 |
'app_id_detail' => $app_id, |
| 76 |
) |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
return $wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table |
| 81 |
static::get_base_table_name(), |
| 82 |
array( |
| 83 |
'app_id' => $app_id, |
| 84 |
) |
| 85 |
); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
public static function update( |
| 90 |
$app_id, |
| 91 |
$app_apps |
| 92 |
) { |
| 93 |
|
| 94 |
self::delete( $app_id ); |
| 95 |
foreach ( $app_apps as $index => $app_detail_id ) { |
| 96 |
self::create( $app_id, $app_detail_id, $index ); |
| 97 |
} |
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
} |