1: | <?php
|
2: | namespace Opencart\Catalog\Model\Catalog;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class SubscriptionPlan extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: |
|
16: | public function getSubscriptionPlan(int $subscription_plan_id): array {
|
17: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_plan` `sp` LEFT JOIN `" . DB_PREFIX . "subscription_plan_description` `spd` ON (`sp`.`subscription_plan_id` = `spd`.`subscription_plan_id`) WHERE `sp`.`subscription_plan_id` = '" . (int)$subscription_plan_id . "' AND `spd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
18: |
|
19: | return $query->row;
|
20: | }
|
21: |
|
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: |
|
29: | public function getSubscriptionPlans(array $data = []): array {
|
30: | $sql = "SELECT * FROM `" . DB_PREFIX . "subscription_plan` `sp` LEFT JOIN `" . DB_PREFIX . "subscription_plan_description` `spd` ON (`sp`.`subscription_plan_id` = `spd`.`subscription_plan_id`) WHERE `spd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
31: |
|
32: | if (!empty($data['filter_name'])) {
|
33: | $sql .= " AND spd.`name` LIKE '" . $this->db->escape($data['filter_name'] . '%') . "'";
|
34: | }
|
35: |
|
36: | $sort_data = [
|
37: | 'spd.name',
|
38: | 'sp.sort_order'
|
39: | ];
|
40: |
|
41: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
42: | $sql .= " ORDER BY " . $data['sort'];
|
43: | } else {
|
44: | $sql .= " ORDER BY `spd`.`name`";
|
45: | }
|
46: |
|
47: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
48: | $sql .= " DESC";
|
49: | } else {
|
50: | $sql .= " ASC";
|
51: | }
|
52: |
|
53: | if (isset($data['start']) || isset($data['limit'])) {
|
54: | if ($data['start'] < 0) {
|
55: | $data['start'] = 0;
|
56: | }
|
57: |
|
58: | if ($data['limit'] < 1) {
|
59: | $data['limit'] = 20;
|
60: | }
|
61: |
|
62: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
63: | }
|
64: |
|
65: | $query = $this->db->query($sql);
|
66: |
|
67: | return $query->rows;
|
68: | }
|
69: |
|
70: | |
71: | |
72: | |
73: | |
74: |
|
75: | public function getTotalSubscriptionPlans(): int {
|
76: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_plan`");
|
77: |
|
78: | return (int)$query->row['total'];
|
79: | }
|
80: | }
|
81: | |