customer = $customer; } public function getId(): ?int { return $this->id; } public function setId(?int $id): void { $this->id = $id; } public function getIds(): ?array { return $this->ids; } public function setIds(?array $ids): void { $this->ids = $ids; } public function getInternalId(): ?string { return $this->internalId; } public function setInternalId(?string $internalId): void { $this->internalId = $internalId; } public function getName(): ?string { return $this->name; } public function setName(?string $name): void { $this->name = $name; } public function getLegalEntityName(): ?string { return $this->legalEntityName; } public function setLegalEntityName(?string $legalEntityName): void { $this->legalEntityName = $legalEntityName; } public function isIncludeArchived(): bool { return $this->includeArchived; } public function setIncludeArchived(bool $includeArchived): void { $this->includeArchived = $includeArchived; } public function isIncludeClosed(): bool { return $this->includeClosed; } public function setIncludeClosed(bool $includeClosed): void { $this->includeClosed = $includeClosed; } public function getMinTestDate(): ?string { return $this->minTestDate; } public function setMinTestDate(?string $minTestDate): void { $this->minTestDate = $minTestDate; } public function getMaxTestDate(): ?string { return $this->maxTestDate; } public function setMaxTestDate(?string $maxTestDate): void { $this->maxTestDate = $maxTestDate; } public function getFilter(): ?string { return $this->filter; } public function setFilter(?string $filter): void { $this->filter = $filter; } /** * @return Location[] * @throws \Exception */ public function run(): array { $nvp = [ "customer_id" => $this->customer->id, "archived" => 0, "closed" => 0 ]; if($this->id) $nvp["id"] = $this->id; if($this->ids) $nvp["id"] = $this->ids; if($this->internalId) $nvp["internal_id"] = Db::escape($this->internalId); if($this->name) $nvp["name"] = Constraint::contains($this->name); if($this->legalEntityName) $nvp["legal_entity_name"] = Constraint::contains($this->legalEntityName); if($this->includeArchived) unset($nvp["archived"]); if($this->includeClosed) unset($nvp["closed"]); $locations = Location::query($nvp, ["sort" => "name", "order" => "asc"]); $base_test_nvp = [ "status" => Constraint::notEquals(Test::STATUS_CANCELLED), "location_id" => array_column($locations, "id") ]; $this->populateAllTests($base_test_nvp); $this->populateLiveTests($base_test_nvp); if($this->filter) { $exclude_location_flags = []; $tests = $this->allTests; if(preg_match("/current$/", $this->filter)) { $tests = $this->liveTests; } switch($this->filter) { case "untested-current": case "untested-all": foreach($tests as $test) { $exclude_location_flags[$test->location_id] = true; } break; case "failed-current": case "failed-all": foreach($tests as $test) { if(!$test->isFail() || $test->isVoid()) { $exclude_location_flags[$test->location_id] = true; } } foreach($locations as $location) { if(!isset($tests[$location->id])) { $exclude_location_flags[$location->id] = true; } } break; } $locations = array_filter($locations, static function(Location $location) use ($exclude_location_flags) { return empty($exclude_location_flags[$location->id]); }); } return $locations; } /** * @param array $nvp * @return Test[] * @throws \Exception */ public function populateAllTests(array $nvp): array { $all_tests = Test::query($nvp, ["sort" => "dts_start", "order" => "asc"]); foreach($all_tests as $test) { $this->allTests[$test->location_id] = $test; } return $this->allTests; } /** * @param array $nvp * @return Test[] * @throws \Exception */ public function populateLiveTests(array $nvp): array { $nvp["dts_start"] = $this->getDateTimeConstraint(); $this->liveTests = Test::query($nvp); return $this->liveTests; } public function getAllTests(): array { return $this->allTests; } private function getDateTimeConstraint(): Constraint { if($this->minTestDate && $this->maxTestDate) { $constraint = Constraint::between($this->minTestDate, $this->maxTestDate); } else { $constraint = $this->customer->getYearCycleConstraint(TIMEZONE); } return $constraint; } }