customer = $customer; $this->user = $user; } 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; $this->filterCount++; } if($this->ids) { $nvp["id"] = $this->ids; $this->filterCount++; } if($this->internalId) { $nvp["internal_id"] = Constraint::contains($this->internalId); $this->filterCount++; } if($this->name) { $nvp["name"] = Constraint::contains($this->name); $this->filterCount++; } if($this->legalEntityName) { $nvp["legal_entity_name"] = Constraint::contains($this->legalEntityName); $this->filterCount++; } if($this->includeArchived) { unset($nvp["archived"]); $this->filterCount++; } if($this->includeClosed) { unset($nvp["closed"]); $this->filterCount++; } if($this->brandName) { $nvp["brand"] = $this->brandName; $this->filterCount++; } if($this->regionName) { $nvp["region"] = $this->regionName; $this->filterCount++; } if($this->areaManagerName) { $nvp["area_manager"] = $this->areaManagerName; $this->filterCount++; } if($this->operationsManagerName) { $nvp["operations_manager_name"] = $this->operationsManagerName; $this->filterCount++; } if($this->gamingManagerName) { $nvp["gaming_manager_name"] = $this->gamingManagerName; $this->filterCount++; } if($this->seniorGamingManagerName) { $nvp["senior_gaming_manager_name"] = $this->seniorGamingManagerName; $this->filterCount++; } $locations = Location::query($nvp, ["sort" => "name", "order" => "asc"]); $base_test_nvp = [ "status" => Constraint::notEquals(Test::STATUS_CANCELLED), "location_id" => array_column($locations, "id") ]; if($this->user && $this->user->level <= User::LEVEL_CUSTOMER) { $base_test_nvp["status"] = Test::STATUS_COMPLETED; } $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; } public function getBrandName(): ?string { return $this->brandName; } public function getRegionName(): ?string { return $this->regionName; } public function getAreaManagerName(): ?string { return $this->areaManagerName; } public function getOperationsManagerName(): ?string { return $this->operationsManagerName; } public function getGamingManagerName(): ?string { return $this->gamingManagerName; } public function getSeniorGamingManagerName(): ?string { return $this->seniorGamingManagerName; } public function setBrandName(?string $brandName): void { $this->brandName = $brandName; } public function setRegionName(?string $regionName): void { $this->regionName = $regionName; } public function setAreaManagerName(?string $areaManagerName): void { $this->areaManagerName = $areaManagerName; } public function setOperationsManagerName(?string $operationsManagerName): void { $this->operationsManagerName = $operationsManagerName; } public function setSeniorGamingManagerName(?string $seniorGamingManagerName): void { $this->seniorGamingManagerName = $seniorGamingManagerName; } public function setGamingManagerName(?string $gamingManagerName): void { $this->gamingManagerName = $gamingManagerName; } public function getFilterCount(): int { return $this->filterCount; } }