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