| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- /**
- * Class UserAddress
- *
- * @property int $id
- * @property int $user_id
- * @property string $name
- * @property string $address_1
- * @property string $address_2
- * @property string $city
- * @property string $county
- * @property string $postal_code
- * @property string $state
- * @property string $country
- * @property double $latitude
- * @property double $longitude
- * @property float $max_radius_miles
- * @property bool $invoice
- */
- class UserAddress extends Model {
- protected static $table = "user_address";
- protected static $id_field = "id";
- protected static $fillable_fields = ["user_id", "name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "latitude", "longitude", "max_radius_miles", "invoice"];
- const RADIUSES = [
- "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",
- ];
- // Object methods
- /**
- * @return User|null
- * @throws Exception
- */
- public function getUser(): ?User {
- return User::get($this->user_id);
- }
- /**
- * @return string
- */
- public function getDisplayAddress(): string {
- $parts = [];
- $fields = ["address_1", "address_2", "city", "county", "postal_code", "state", "country"];
- foreach($fields as $field) {
- $parts[] = $this->$field;
- }
- return implode(", ", array_filter($parts));
- }
- /**
- * @return array
- */
- public function getGeolocation(): array {
- return [$this->latitude, $this->longitude];
- }
- }
|