1
0

location.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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", "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 [$this->latitude, $this->longitude];
  24. }
  25. public function getPhotos() {
  26. return LocationFile::query([
  27. "location_id" => $this->id,
  28. "type" => LocationFile::TYPE_PHOTO
  29. ]);
  30. }
  31. }
  32. ?>