BaseRepository.php
3 years ago
CouponRepository.php
2 years ago
CustomerRepository.php
1 year ago
GroupRepository.php
3 years ago
OrderRepository.php
11 months ago
PlanRepository.php
2 months ago
RepositoryInterface.php
3 years ago
SubscriptionRepository.php
3 months ago
index.php
3 years ago
BaseRepository.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace ProfilePress\Core\Membership\Repositories; |
| 5 | |
| 6 | abstract class BaseRepository implements RepositoryInterface |
| 7 | { |
| 8 | protected $table; |
| 9 | |
| 10 | public function wpdb() |
| 11 | { |
| 12 | global $wpdb; |
| 13 | |
| 14 | return $wpdb; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Update a column in table. |
| 19 | * |
| 20 | * @param int $id |
| 21 | * @param string $column |
| 22 | * @param string $value |
| 23 | * |
| 24 | * @return false|int |
| 25 | */ |
| 26 | public function updateColumn($id, $column, $value) |
| 27 | { |
| 28 | return $this->wpdb()->update( |
| 29 | $this->table, |
| 30 | [$column => $value], |
| 31 | ['id' => $id], |
| 32 | ['%s'], |
| 33 | ['%d'] |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Retrieve a column in DB table. |
| 39 | * |
| 40 | * @param int $id |
| 41 | * @param string $column |
| 42 | * |
| 43 | * @return string|null |
| 44 | */ |
| 45 | public function retrieveColumn($id, $column) |
| 46 | { |
| 47 | return $this->wpdb()->get_var( |
| 48 | $this->wpdb()->prepare( |
| 49 | "SELECT $column FROM $this->table WHERE id = %d", |
| 50 | $id |
| 51 | ) |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return string|null |
| 57 | */ |
| 58 | public function record_count() |
| 59 | { |
| 60 | return $this->wpdb()->get_var("SELECT COUNT(*) FROM $this->table"); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @return static |
| 65 | */ |
| 66 | public static function init() |
| 67 | { |
| 68 | return new static(); |
| 69 | } |
| 70 | } |