Back to Opencart

File admin\model\localisation\location.php

docs/api/source-admin.model.localisation.location.html

4.1.0.38.8 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Model\Localisation; | | 3: | /** | | 4: | * Class Location | | 5: | * | | 6: | * @package Opencart\Admin\Model\Localisation | | 7: | */ | | 8: | class Location extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Add Location | | 11: | * | | 12: | * @param array<string, mixed> $data | | 13: | * | | 14: | * @return int | | 15: | */ | | 16: | public function addLocation(array $data): int { | | 17: | $this->db->query("INSERT INTO " . DB\_PREFIX . "location SET name = '" . $this->db->escape((string)$data['name']) . "', address = '" . $this->db->escape((string)$data['address']) . "', geocode = '" . $this->db->escape((string)$data['geocode']) . "', telephone = '" . $this->db->escape((string)$data['telephone']) . "', image = '" . $this->db->escape((string)$data['image']) . "', open = '" . $this->db->escape((string)$data['open']) . "', comment = '" . $this->db->escape((string)$data['comment']) . "'"); | | 18: | | | 19: | return $this->db->getLastId(); | | 20: | } | | 21: | | | 22: | /** | | 23: | * Edit Location | | 24: | * | | 25: | * @param int $location_id | | 26: | * @param array<string, mixed> $data | | 27: | * | | 28: | * @return void | | 29: | */ | | 30: | public function editLocation(int $location_id, array $data): void { | | 31: | $this->db->query("UPDATE " . DB\_PREFIX . "location SET name = '" . $this->db->escape((string)$data['name']) . "', address = '" . $this->db->escape((string)$data['address']) . "', geocode = '" . $this->db->escape((string)$data['geocode']) . "', telephone = '" . $this->db->escape((string)$data['telephone']) . "', image = '" . $this->db->escape((string)$data['image']) . "', open = '" . $this->db->escape((string)$data['open']) . "', comment = '" . $this->db->escape((string)$data['comment']) . "' WHERE location_id = '" . (int)$location_id . "'"); | | 32: | } | | 33: | | | 34: | /** | | 35: | * Delete Location | | 36: | * | | 37: | * @param int $location_id | | 38: | * | | 39: | * @return void | | 40: | */ | | 41: | public function deleteLocation(int $location_id): void { | | 42: | $this->db->query("DELETE FROM " . DB\_PREFIX . "location WHERE location\_id = '" . (int)$location_id . "'"); | | 43: | } | | 44: | | | 45: | /** | | 46: | * Get Location | | 47: | * | | 48: | * @param int $location_id | | 49: | * | | 50: | * @return array<string, mixed> | | 51: | */ | | 52: | public function getLocation(int $location_id): array { | | 53: | $query = $this->db->query("SELECT DISTINCT * FROM " . DB\_PREFIX . "location WHERE location\_id = '" . (int)$location_id . "'"); | | 54: | | | 55: | return $query->row; | | 56: | } | | 57: | | | 58: | /** | | 59: | * Get Locations | | 60: | * | | 61: | * @param array<string, mixed> $data | | 62: | * | | 63: | * @return array<int, array<string, mixed>> | | 64: | */ | | 65: | public function getLocations(array $data = []): array { | | 66: | $sql = "SELECT location_id, name, address FROM " . DB\_PREFIX . "location"; | | 67: | | | 68: | $sort_data = [ | | 69: | 'name', | | 70: | 'address', | | 71: | ]; | | 72: | | | 73: | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { | | 74: | $sql .= " ORDER BY " . $data['sort']; | | 75: | } else { | | 76: | $sql .= " ORDER BY name"; | | 77: | } | | 78: | | | 79: | if (isset($data['order']) && ($data['order'] == 'DESC')) { | | 80: | $sql .= " DESC"; | | 81: | } else { | | 82: | $sql .= " ASC"; | | 83: | } | | 84: | | | 85: | if (isset($data['start']) || isset($data['limit'])) { | | 86: | if ($data['start'] < 0) { | | 87: | $data['start'] = 0; | | 88: | } | | 89: | | | 90: | if ($data['limit'] < 1) { | | 91: | $data['limit'] = 20; | | 92: | } | | 93: | | | 94: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; | | 95: | } | | 96: | | | 97: | $query = $this->db->query($sql); | | 98: | | | 99: | return $query->rows; | | 100: | } | | 101: | | | 102: | /** | | 103: | * Get Total Locations | | 104: | * | | 105: | * @return int | | 106: | */ | | 107: | public function getTotalLocations(): int { | | 108: | $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB\_PREFIX . "location"); | | 109: | | | 110: | return (int)$query->row['total']; | | 111: | } | | 112: | } | | 113: | |

OpenCart API API documentation generated by ApiGen dev-master