location.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class Location extends Model {
  3. protected static $table = "location";
  4. protected static $id_field = "id";
  5. 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"];
  6. // Object methods
  7. public function getCustomer() {
  8. return Customer::get($this->customer_id);
  9. }
  10. public function getDirectory() {
  11. $directory = ROOT_DIR . "/files/locations/" . $this->id;
  12. if(!file_exists($directory)) mkdir($directory, 0777, true);
  13. return $directory;
  14. }
  15. public function getDisplayAddress($fields = ["address_1", "address_2", "city", "county", "postal_code", "state", "country"], $glue = ", ") {
  16. $parts = [];
  17. foreach($fields as $field) {
  18. $parts[] = $this->$field;
  19. }
  20. return implode($glue, array_filter($parts));
  21. }
  22. public function getGeolocation() {
  23. return [
  24. doubleval($this->latitude),
  25. doubleval($this->longitude)
  26. ];
  27. }
  28. public function getPhotos() {
  29. return LocationFile::query([
  30. "location_id" => $this->id,
  31. "type" => LocationFile::TYPE_PHOTO
  32. ]);
  33. }
  34. }
  35. ?>