| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- class Location extends Model {
- protected static $table = "location";
- protected static $id_field = "id";
- protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "shop_left", "shop_right", "region", "internal_id", "area_manager", "area_manager_email", "closed", "latitude", "longitude", "dts_verified"];
- // Object methods
- public function getCustomer() {
- return Customer::get($this->customer_id);
- }
- public function getDirectory() {
- $directory = ROOT_DIR . "/files/locations/" . $this->id;
- if(!file_exists($directory)) mkdir($directory, 0777, true);
- return $directory;
- }
- public function getDisplayAddress($fields = ["address_1", "address_2", "city", "county", "postal_code", "state", "country"], $glue = ", ") {
- $parts = [];
- foreach($fields as $field) {
- $parts[] = $this->$field;
- }
- return implode($glue, array_filter($parts));
- }
- public function getGeolocation() {
- return [
- doubleval($this->latitude),
- doubleval($this->longitude)
- ];
- }
- public function getPhotos() {
- return LocationFile::query([
- "location_id" => $this->id,
- "type" => LocationFile::TYPE_PHOTO
- ]);
- }
- }
- ?>
|