| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Classes; |
| 4 |
|
| 5 |
abstract class AbstractModel { |
| 6 |
protected $wpdb; |
| 7 |
protected string $table; |
| 8 |
protected string $query; |
| 9 |
protected string $prefix; |
| 10 |
protected string $primary_key = 'ID'; |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
global $wpdb; |
| 14 |
$this->wpdb = $wpdb; |
| 15 |
$this->prefix = $wpdb->prefix; |
| 16 |
$this->table = $this->prefix . $this->table; |
| 17 |
} |
| 18 |
|
| 19 |
abstract public function save( array $args = [] ); |
| 20 |
|
| 21 |
abstract public function update( int $id, array $args ); |
| 22 |
|
| 23 |
abstract public function delete( ?int $id = null ); |
| 24 |
|
| 25 |
protected function create_item( array $data, ?array $format = null ) { |
| 26 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 27 |
return $this->wpdb->insert( $this->table, $data, $format ); |
| 28 |
} |
| 29 |
|
| 30 |
protected function update_item( array $data, array $where, ?array $format = null, ?array $where_format = null ) { |
| 31 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 32 |
return $this->wpdb->update( $this->table, $data, $where, $format, $where_format ); |
| 33 |
} |
| 34 |
|
| 35 |
protected function delete_item( array $where, ?array $format = null ) { |
| 36 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 37 |
return $this->wpdb->delete( $this->table, $where, $format ); |
| 38 |
} |
| 39 |
} |
| 40 |
|