|
|
@@ -20,10 +20,13 @@ class LocationSearch {
|
|
|
private bool $includeClosed = false;
|
|
|
private ?string $minTestDate = null;
|
|
|
private ?string $maxTestDate = null;
|
|
|
- private bool $includeTested = true;
|
|
|
private ?string $filter = null;
|
|
|
|
|
|
- private array $latestTests = [];
|
|
|
+ /** @var Test[] */
|
|
|
+ private array $liveTests = [];
|
|
|
+
|
|
|
+ /** @var Test[] */
|
|
|
+ private array $allTests = [];
|
|
|
|
|
|
public function __construct(Customer $customer) {
|
|
|
$this->customer = $customer;
|
|
|
@@ -101,14 +104,6 @@ class LocationSearch {
|
|
|
$this->maxTestDate = $maxTestDate;
|
|
|
}
|
|
|
|
|
|
- public function isIncludeTested(): bool {
|
|
|
- return $this->includeTested;
|
|
|
- }
|
|
|
-
|
|
|
- public function setIncludeTested(bool $includeTested): void {
|
|
|
- $this->includeTested = $includeTested;
|
|
|
- }
|
|
|
-
|
|
|
public function getFilter(): ?string {
|
|
|
return $this->filter;
|
|
|
}
|
|
|
@@ -143,40 +138,88 @@ class LocationSearch {
|
|
|
"location_id" => array_column($locations, "id")
|
|
|
];
|
|
|
|
|
|
- if(!$this->includeTested) {
|
|
|
- $test_nvp = $base_test_nvp;
|
|
|
+ $this->populateAllTests($base_test_nvp);
|
|
|
+ $this->populateLiveTests($base_test_nvp);
|
|
|
|
|
|
- if($this->minTestDate && $this->maxTestDate) {
|
|
|
- $test_nvp["dts_start"] = Constraint::between($this->minTestDate, $this->maxTestDate);
|
|
|
- }
|
|
|
- else {
|
|
|
- [$min_dts, $max_dts] = $this->customer->getYearCycleDates();
|
|
|
- $test_nvp["dts_start"] = Constraint::between($min_dts, $max_dts);
|
|
|
+ if($this->filter) {
|
|
|
+ $exclude_location_flags = [];
|
|
|
+
|
|
|
+ $tests = $this->allTests;
|
|
|
+ if(preg_match("/current$/", $this->filter)) {
|
|
|
+ $tests = $this->liveTests;
|
|
|
}
|
|
|
|
|
|
- $tests = Test::query($test_nvp);
|
|
|
- $location_test_flags = [];
|
|
|
- foreach($tests as $test) {
|
|
|
- $location_test_flags[$test->location_id] = true;
|
|
|
+ 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;
|
|
|
}
|
|
|
- unset($tests);
|
|
|
|
|
|
- $locations = array_filter($locations, static function(Location $location) use ($location_test_flags) {
|
|
|
- return !isset($location_test_flags[$location->id]);
|
|
|
+ $locations = array_filter($locations, static function(Location $location) use ($exclude_location_flags) {
|
|
|
+ return empty($exclude_location_flags[$location->id]);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- $all_tests = Test::query($base_test_nvp, ["sort" => "dts_start", "order" => "asc"]);
|
|
|
+ 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->latestTests[$test->location_id] = $test;
|
|
|
+ $this->allTests[$test->location_id] = $test;
|
|
|
}
|
|
|
|
|
|
- return $locations;
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
- public function getLatestTests(): array {
|
|
|
- return $this->latestTests;
|
|
|
+ private function getDateTimeConstraint(): Constraint {
|
|
|
+ if($this->minTestDate && $this->maxTestDate) {
|
|
|
+ $constraint = Constraint::between($this->minTestDate, $this->maxTestDate);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ [$min_dts, $max_dts] = $this->customer->getYearCycleDates();
|
|
|
+ $constraint = Constraint::between($min_dts, $max_dts);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $constraint;
|
|
|
}
|
|
|
|
|
|
}
|