1: | <?php
2: | namespace Opencart\Admin\Model\Localisation;
3: | /**
4: | * Class Address Format
5: | *
6: | * @package Opencart\Admin\Model\Localisation
7: | */
8: | class AddressFormat extends \Opencart\System\Engine\Model {
9: | /**
10: | * Add Address Format
11: | *
12: | * @param array<string, mixed> $data
13: | *
14: | * @return int
15: | */
16: | public function addAddressFormat(array $data): int {
17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "address_format` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address_format` = '" . $this->db->escape((string)$data['address_format']) . "'");
18: |
19: | return $this->db->getLastId();
20: | }
21: |
22: | /**
23: | * Edit Address Format
24: | *
25: | * @param int $address_format_id
26: | * @param array<string, mixed> $data
27: | *
28: | * @return void
29: | */
30: | public function editAddressFormat(int $address_format_id, array $data): void {
31: | $this->db->query("UPDATE `" . DB_PREFIX . "address_format` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address_format` = '" . $this->db->escape((string)$data['address_format']) . "' WHERE `address_format_id` = '" . (int)$address_format_id . "'");
32: | }
33: |
34: | /**
35: | * Delete Address Format
36: | *
37: | * @param int $address_format_id
38: | *
39: | * @return void
40: | */
41: | public function deleteAddressFormat(int $address_format_id): void {
42: | $this->db->query("DELETE FROM `" . DB_PREFIX . "address_format` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
43: | }
44: |
45: | /**
46: | * Get Address Format
47: | *
48: | * @param int $address_format_id
49: | *
50: | * @return array<string, mixed>
51: | */
52: | public function getAddressFormat(int $address_format_id): array {
53: | $query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "address_format` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
54: |
55: | return $query->row;
56: | }
57: |
58: | /**
59: | * Get Address Formats
60: | *
61: | * @param array<string, mixed> $data
62: | *
63: | * @return array<int, array<string, mixed>>
64: | */
65: | public function getAddressFormats(array $data = []): array {
66: | $sql = "SELECT * FROM `" . DB_PREFIX . "address_format`";
67: |
68: | if (isset($data['start']) || isset($data['limit'])) {
69: | if ($data['start'] < 0) {
70: | $data['start'] = 0;
71: | }
72: |
73: | if ($data['limit'] < 1) {
74: | $data['limit'] = 20;
75: | }
76: |
77: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
78: | }
79: |
80: | $query = $this->db->query($sql);
81: |
82: | return $query->rows;
83: | }
84: |
85: | /**
86: | * Get Total Address Formats
87: | *
88: | * @param array<string, mixed> $data
89: | *
90: | * @return int
91: | */
92: | public function getTotalAddressFormats(array $data = []): int {
93: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address_format`");
94: |
95: | return (int)$query->row['total'];
96: | }
97: | }
98: |

OpenCart API API documentation generated by ApiGen dev-master