getCustomers(); if(count($customers) == 0) throw new Exception("At least one customer must exist before this page can be accessed."); else if(count($customers) == 1) { $customer = array_shift($customers); } else { $customer_id = http::value("customer_id", "int"); if(!$customer_id) { $page_title = "Select Customer"; View::includeOnce("header", compact("page_title")); View::include("customer_select", compact("customers")); View::includeOnce("footer"); exit; } $customer = Customer::get($customer_id); // Enforce restriction if CUSTOMER or lower if(Core::$user->level < User::LEVEL_ADMIN) { $link = UserCustomer::get(Core::$user->id, $customer_id); if(!$link) $customer = null; } } if(empty($customer)) throw new Exception("Customer not found."); return $customer; } // Object methods /** * @param array $query * @return Location[] * @throws Exception */ public function getLocations(array $query = []): array { $nvp = array_merge(["customer_id" => $this->id], $query); return Location::query($nvp, ["sort" => "name"]); } /** * @return Project[] * @throws Exception */ public function getProjects() { return Project::query(["customer_id" => $this->id], ["sort" => "dts_deadline", "order" => "desc"]); } /** * @return Template[] * @throws Exception */ public function getTemplates() { return Template::query(["customer_id" => $this->id], ["sort" => "name"]); } /** * @return string */ public function getTestResultsUrl(): string { $slug = Util::slugWithId($this->name, $this->id); $url = "/account/test-results/{$slug}"; return $url; } }