$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", ]); } }