1: | <?php
2: | namespace Opencart\Admin\Model\Setting;
3: | /**
4: | * Class Startup
5: | *
6: | * @package Opencart\Admin\Model\Setting
7: | */
8: | class Startup extends \Opencart\System\Engine\Model {
9: | /**
10: | * Add Startup
11: | *
12: | * @param array<string, mixed> $data
13: | *
14: | * @return int
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: | * Delete Startup
24: | *
25: | * @param int $startup_id
26: | *
27: | * @return void
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: | * Delete Startup By Code
35: | *
36: | * @param string $code
37: | *
38: | * @return void
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: | * Edit Status
46: | *
47: | * @param int $startup_id
48: | * @param bool $status
49: | *
50: | * @return void
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: | * Get Startup
58: | *
59: | * @param int $startup_id
60: | *
61: | * @return array<string, mixed>
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: | * Get Startup By Code
71: | *
72: | * @param string $code
73: | *
74: | * @return array<string, mixed>
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: | * Get Startups
84: | *
85: | * @param array<string, mixed> $data
86: | *
87: | * @return array<int, array<string, mixed>>
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: | * Get Total Startyps
131: | *
132: | * @return int
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: |

OpenCart API API documentation generated by ApiGen dev-master