1: | <?php
2: | namespace Opencart\Admin\Model\Setting;
3: | /**
4: | * Class Module
5: | *
6: | * @package Opencart\Admin\Model\Setting
7: | */
8: | class Module extends \Opencart\System\Engine\Model {
9: | /**
10: | * Add Module
11: | *
12: | * @param string $code
13: | * @param array<string, mixed> $data
14: | *
15: | * @return int
16: | */
17: | public function addModule(string $code, array $data): int {
18: | $this->db->query("INSERT INTO `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape($code) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "'");
19: |
20: | $module_id = $this->db->getLastId();
21: |
22: | return (int)$module_id;
23: | }
24: |
25: | /**
26: | * Edit Module
27: | *
28: | * @param int $module_id
29: | * @param array<string, mixed> $data
30: | *
31: | * @return void
32: | */
33: | public function editModule(int $module_id, array $data): void {
34: | $this->db->query("UPDATE `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "' WHERE `module_id` = '" . (int)$module_id . "'");
35: | }
36: |
37: | /**
38: | * Delete Module
39: | *
40: | * @param int $module_id
41: | *
42: | * @return void
43: | */
44: | public function deleteModule(int $module_id): void {
45: | $this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
46: | }
47: |
48: | /**
49: | * Delete Modules By Code
50: | *
51: | * @param string $code
52: | *
53: | * @return void
54: | */
55: | public function deleteModulesByCode(string $code): void {
56: | $this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "'");
57: |
58: | $this->load->model('design/layout');
59: |
60: | $this->model_design_layout->deleteModulesByCode($code);
61: | }
62: |
63: | /**
64: | * Get Module
65: | *
66: | * @param int $module_id
67: | *
68: | * @return array<mixed>
69: | */
70: | public function getModule(int $module_id): array {
71: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
72: |
73: | if ($query->row) {
74: | return json_decode($query->row['setting'], true);
75: | } else {
76: | return [];
77: | }
78: | }
79: |
80: | /**
81: | * Get Modules
82: | *
83: | * @return array<int, array<string, mixed>>
84: | */
85: | public function getModules(): array {
86: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` ORDER BY `code`");
87: |
88: | return $query->rows;
89: | }
90: |
91: | /**
92: | * Get Modules By Code
93: | *
94: | * @param string $code
95: | *
96: | * @return array<int, array<string, mixed>>
97: | */
98: | public function getModulesByCode(string $code): array {
99: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "' ORDER BY `name`");
100: |
101: | return $query->rows;
102: | }
103: | }
104: |

OpenCart API API documentation generated by ApiGen dev-master