|
|
@@ -21,6 +21,9 @@ class LocationSearch {
|
|
|
private ?string $minTestDate = null;
|
|
|
private ?string $maxTestDate = null;
|
|
|
private bool $includeTested = true;
|
|
|
+ private ?string $filter = null;
|
|
|
+
|
|
|
+ private array $latestTests = [];
|
|
|
|
|
|
public function __construct(Customer $customer) {
|
|
|
$this->customer = $customer;
|
|
|
@@ -106,6 +109,14 @@ class LocationSearch {
|
|
|
$this->includeTested = $includeTested;
|
|
|
}
|
|
|
|
|
|
+ public function getFilter(): ?string {
|
|
|
+ return $this->filter;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setFilter(?string $filter): void {
|
|
|
+ $this->filter = $filter;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return Location[]
|
|
|
* @throws \Exception
|
|
|
@@ -127,11 +138,13 @@ class LocationSearch {
|
|
|
|
|
|
$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->includeTested) {
|
|
|
- $test_nvp = [
|
|
|
- "status" => Constraint::notEquals(Test::STATUS_CANCELLED),
|
|
|
- "location_id" => array_column($locations, "id")
|
|
|
- ];
|
|
|
+ $test_nvp = $base_test_nvp;
|
|
|
|
|
|
if($this->minTestDate && $this->maxTestDate) {
|
|
|
$test_nvp["dts_start"] = Constraint::between($this->minTestDate, $this->maxTestDate);
|
|
|
@@ -142,18 +155,28 @@ class LocationSearch {
|
|
|
}
|
|
|
|
|
|
$tests = Test::query($test_nvp);
|
|
|
-
|
|
|
$location_test_flags = [];
|
|
|
foreach($tests as $test) {
|
|
|
$location_test_flags[$test->location_id] = true;
|
|
|
}
|
|
|
+ unset($tests);
|
|
|
|
|
|
$locations = array_filter($locations, static function(Location $location) use ($location_test_flags) {
|
|
|
return !isset($location_test_flags[$location->id]);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ $all_tests = Test::query($base_test_nvp, ["sort" => "dts_start", "order" => "asc"]);
|
|
|
+
|
|
|
+ foreach($all_tests as $test) {
|
|
|
+ $this->latestTests[$test->location_id] = $test;
|
|
|
+ }
|
|
|
+
|
|
|
return $locations;
|
|
|
}
|
|
|
|
|
|
+ public function getLatestTests(): array {
|
|
|
+ return $this->latestTests;
|
|
|
+ }
|
|
|
+
|
|
|
}
|