|
@@ -20,6 +20,18 @@ if($submit) {
|
|
|
// Gets all locations for a customer
|
|
// Gets all locations for a customer
|
|
|
case "get-customer-locations": {
|
|
case "get-customer-locations": {
|
|
|
|
|
|
|
|
|
|
+ // Initialise Results
|
|
|
|
|
+ $results = [];
|
|
|
|
|
+
|
|
|
|
|
+ $init_result = static function(Location $location): object {
|
|
|
|
|
+ return (object) [
|
|
|
|
|
+ "location" => $location,
|
|
|
|
|
+ "latestTest" => null,
|
|
|
|
|
+ "testerId" => null,
|
|
|
|
|
+ "testCount" => 0
|
|
|
|
|
+ ];
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
// Input
|
|
// Input
|
|
|
$customer_id = http::value("customer_id", "int");
|
|
$customer_id = http::value("customer_id", "int");
|
|
|
|
|
|
|
@@ -33,6 +45,10 @@ if($submit) {
|
|
|
// Get locations
|
|
// Get locations
|
|
|
$locations = $customer->getLocations(["archived" => 0]);
|
|
$locations = $customer->getLocations(["archived" => 0]);
|
|
|
|
|
|
|
|
|
|
+ foreach($locations as $location) {
|
|
|
|
|
+ $results[$location->id] = $init_result($location);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Get tests
|
|
// Get tests
|
|
|
$nvp = [
|
|
$nvp = [
|
|
|
"status" => Constraint::notEquals(Test::STATUS_CANCELLED),
|
|
"status" => Constraint::notEquals(Test::STATUS_CANCELLED),
|
|
@@ -57,33 +73,45 @@ if($submit) {
|
|
|
|
|
|
|
|
$tests = Test::query($nvp);
|
|
$tests = Test::query($nvp);
|
|
|
|
|
|
|
|
- $location_test_array = [];
|
|
|
|
|
foreach($tests as $test) {
|
|
foreach($tests as $test) {
|
|
|
- $exists = isset($location_test_array[$test->location_id]);
|
|
|
|
|
- if(!$exists) {
|
|
|
|
|
- $location_test_array[$test->location_id] = $test;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ $result = $results[$test->location_id];
|
|
|
|
|
+ $result->testCount++;
|
|
|
|
|
+
|
|
|
|
|
+ $assign_test = false;
|
|
|
|
|
+ if($result->latestTest === null) {
|
|
|
|
|
+ $assign_test = true;
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
/** @var Test $existing */
|
|
/** @var Test $existing */
|
|
|
- $existing = $location_test_array[$test->location_id];
|
|
|
|
|
|
|
+ $existing = $result->latestTest;
|
|
|
|
|
|
|
|
$unix_start_existing = ($existing->dts_start === null) ? 0 : strtotime($existing->dts_start . " UTC");
|
|
$unix_start_existing = ($existing->dts_start === null) ? 0 : strtotime($existing->dts_start . " UTC");
|
|
|
$unix_start_current = ($test->dts_start === null) ? 0 : strtotime($test->dts_start . " UTC");
|
|
$unix_start_current = ($test->dts_start === null) ? 0 : strtotime($test->dts_start . " UTC");
|
|
|
|
|
|
|
|
if($unix_start_current > $unix_start_existing) {
|
|
if($unix_start_current > $unix_start_existing) {
|
|
|
- $location_test_array[$test->location_id] = $test;
|
|
|
|
|
|
|
+ $assign_test = true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if($assign_test) {
|
|
|
|
|
+ $result->latestTest = $test;
|
|
|
|
|
+ $result->testerId = $test->tester_id;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $tester_ids = array_column($location_test_array, "tester_id");
|
|
|
|
|
|
|
+ $tester_ids = array_column($results, "testerId");
|
|
|
User::load($tester_ids);
|
|
User::load($tester_ids);
|
|
|
|
|
|
|
|
$output = [];
|
|
$output = [];
|
|
|
|
|
|
|
|
- foreach($locations as $location) {
|
|
|
|
|
|
|
+ foreach($results as $result) {
|
|
|
|
|
+
|
|
|
|
|
+ /** @var Location $location */
|
|
|
|
|
+ $location = $result->location;
|
|
|
|
|
|
|
|
- $test = $location_test_array[$location->id] ?? false;
|
|
|
|
|
|
|
+ /** @var Test $test */
|
|
|
|
|
+ $test = $result->latestTest;
|
|
|
|
|
|
|
|
$customer_slug = Util::slug($customer->name, "_");
|
|
$customer_slug = Util::slug($customer->name, "_");
|
|
|
|
|
|
|
@@ -149,7 +177,8 @@ if($submit) {
|
|
|
"test" => null,
|
|
"test" => null,
|
|
|
"doNotTest" => (bool) $location->do_not_test,
|
|
"doNotTest" => (bool) $location->do_not_test,
|
|
|
"closed" => (bool) $location->closed,
|
|
"closed" => (bool) $location->closed,
|
|
|
- "archived" => $location->isArchived()
|
|
|
|
|
|
|
+ "archived" => $location->isArchived(),
|
|
|
|
|
+ "testCount" => $result->testCount
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
if($test) {
|
|
if($test) {
|