| 1: | <?php
|
| 2: | namespace Opencart\Admin\Model\Setting;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Startup extends \Opencart\System\Engine\Model {
|
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | public function addStartup(array $data): int {
|
| 17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "startup` SET `code` = '" . $this->db->escape($data['code']) . "', `description` = '" . $this->db->escape($data['description']) . "', `action` = '" . $this->db->escape($data['action']) . "', `status` = '" . (bool)$data['status'] . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
| 18: |
|
| 19: | return $this->db->getLastId();
|
| 20: | }
|
| 21: |
|
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: |
|
| 29: | public function deleteStartup(int $startup_id): void {
|
| 30: | $this->db->query("DELETE FROM `" . DB_PREFIX . "startup` WHERE `startup_id` = '" . (int)$startup_id . "'");
|
| 31: | }
|
| 32: |
|
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: |
|
| 40: | public function deleteStartupByCode(string $code): void {
|
| 41: | $this->db->query("DELETE FROM `" . DB_PREFIX . "startup` WHERE `code` = '" . $this->db->escape($code) . "'");
|
| 42: | }
|
| 43: |
|
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: |
|
| 52: | public function editStatus(int $startup_id, bool $status): void {
|
| 53: | $this->db->query("UPDATE `" . DB_PREFIX . "startup` SET `status` = '" . (bool)$status . "' WHERE `startup_id` = '" . (int)$startup_id . "'");
|
| 54: | }
|
| 55: |
|
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: |
|
| 63: | public function getStartup(int $startup_id): array {
|
| 64: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "startup` WHERE `startup_id` = '" . (int)$startup_id . "'");
|
| 65: |
|
| 66: | return $query->row;
|
| 67: | }
|
| 68: |
|
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: |
|
| 76: | public function getStartupByCode(string $code): array {
|
| 77: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "startup` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
|
| 78: |
|
| 79: | return $query->row;
|
| 80: | }
|
| 81: |
|
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: |
|
| 89: | public function getStartups(array $data = []): array {
|
| 90: | $sql = "SELECT * FROM `" . DB_PREFIX . "startup`";
|
| 91: |
|
| 92: | $sort_data = [
|
| 93: | 'code',
|
| 94: | 'action',
|
| 95: | 'status',
|
| 96: | 'sort_order',
|
| 97: | 'date_added'
|
| 98: | ];
|
| 99: |
|
| 100: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
| 101: | $sql .= " ORDER BY " . $data['sort'];
|
| 102: | } else {
|
| 103: | $sql .= " ORDER BY `sort_order`";
|
| 104: | }
|
| 105: |
|
| 106: | if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
| 107: | $sql .= " DESC";
|
| 108: | } else {
|
| 109: | $sql .= " ASC";
|
| 110: | }
|
| 111: |
|
| 112: | if (isset($data['start']) || isset($data['limit'])) {
|
| 113: | if ($data['start'] < 0) {
|
| 114: | $data['start'] = 0;
|
| 115: | }
|
| 116: |
|
| 117: | if ($data['limit'] < 1) {
|
| 118: | $data['limit'] = 20;
|
| 119: | }
|
| 120: |
|
| 121: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
| 122: | }
|
| 123: |
|
| 124: | $query = $this->db->query($sql);
|
| 125: |
|
| 126: | return $query->rows;
|
| 127: | }
|
| 128: |
|
| 129: | |
| 130: | |
| 131: | |
| 132: | |
| 133: |
|
| 134: | public function getTotalStartups(): int {
|
| 135: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "startup`");
|
| 136: |
|
| 137: | return (int)$query->row['total'];
|
| 138: | }
|
| 139: | }
|
| 140: | |