user_address.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Class UserAddress
  4. *
  5. * @property int $id
  6. * @property int $user_id
  7. * @property string $name
  8. * @property string $address_1
  9. * @property string $address_2
  10. * @property string $city
  11. * @property string $county
  12. * @property string $postal_code
  13. * @property string $state
  14. * @property string $country
  15. * @property double $latitude
  16. * @property double $longitude
  17. * @property float $max_radius_miles
  18. * @property bool $invoice
  19. */
  20. class UserAddress extends Model {
  21. protected static $table = "user_address";
  22. protected static $id_field = "id";
  23. protected static $fillable_fields = ["user_id", "name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "latitude", "longitude", "max_radius_miles", "invoice"];
  24. const RADIUSES = [
  25. "0.25", "0.50", "1.00", "1.50", "2.00", "2.50", "3.00", "4.00", "5.00", "7.50", "10.00", "12.50", "15.00", "20.00", "25.00",
  26. ];
  27. // Object methods
  28. /**
  29. * @return User|null
  30. * @throws Exception
  31. */
  32. public function getUser(): ?User {
  33. return User::get($this->user_id);
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function getDisplayAddress(): string {
  39. $parts = [];
  40. $fields = ["address_1", "address_2", "city", "county", "postal_code", "state", "country"];
  41. foreach($fields as $field) {
  42. $parts[] = $this->$field;
  43. }
  44. return implode(", ", array_filter($parts));
  45. }
  46. /**
  47. * @return array
  48. */
  49. public function getGeolocation(): array {
  50. return [$this->latitude, $this->longitude];
  51. }
  52. }