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