| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * @method Location get(int $id)
- */
- class Location extends Model {
- protected static $table = "location";
- protected static $id_field = "id";
- 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", "brand", "region", "region_name", "internal_id", "area_manager", "area_manager_name", "area_manager_email", "operations_manager_name", "closed", "latitude", "longitude", "dts_verified"];
- // Object methods
- public function assignVenueTypes($types) {
- $links = LocationVenueType::query(["location_id" => $this->id]);
- foreach($links as $link) {
- $link->delete();
- }
- foreach($types as $type) {
- $link = new LocationVenueType;
- $link->location_id = $this->id;
- $link->venue_type_id = $type->id;
- $link->commit();
- }
- return true;
- }
- public function getVenueTypes() {
- $links = LocationVenueType::query(["location_id" => $this->id]);
- $ids = array_column($links, "venue_type_id");
- return VenueType::query(["id" => $ids]);
- }
- public function getCustomer() {
- return Customer::get($this->customer_id);
- }
- public function getDirectory() {
- $directory = ROOT_DIR . "/files/locations/" . $this->id;
- if(!file_exists($directory)) mkdir($directory, 0777, true);
- return $directory;
- }
- public function getDisplayAddress($fields = ["address_1", "address_2", "city", "county", "postal_code", "state", "country"], $glue = ", ") {
- $parts = [];
- foreach($fields as $field) {
- $parts[] = $this->$field;
- }
- return implode($glue, array_filter($parts));
- }
- public function getGeolocation() {
- return [
- doubleval($this->latitude),
- doubleval($this->longitude)
- ];
- }
- /**
- * @return LocationFile[]
- */
- public function getPhotos() {
- return LocationFile::query([
- "location_id" => $this->id,
- "type" => LocationFile::TYPE_PHOTO
- ]);
- }
- /**
- * @return Test[]
- */
- public function getTests() {
- return Test::query([
- "location_id" => $this->id,
- "status" => (new Constraint("MORE_THAN_OR_EQUAL"))->setValues(Test::STATUS_UNASSIGNED),
- ], [
- "sort" => "dts_start",
- "order" => "desc",
- ]);
- }
- /**
- * @return Test[]
- */
- public function getCompletedTests() {
- return Test::query([
- "location_id" => $this->id,
- "status" => Test::STATUS_COMPLETED,
- ], [
- "sort" => "dts_start",
- "order" => "desc",
- ]);
- }
- }
|