Quellcode durchsuchen

Added Customer filter.

Alan Lam vor 8 Jahren
Ursprung
Commit
1ba7de39b4
2 geänderte Dateien mit 23 neuen und 1 gelöschten Zeilen
  1. 7 1
      controllers/tests.php
  2. 16 0
      views/test_list.php

+ 7 - 1
controllers/tests.php

@@ -18,6 +18,7 @@ Core::$page = $page;
 if($user->level >= User::LEVEL_ADMIN) {
 
 	$status = http::value("status", "int");
+	$customer_id = http::value("customer_id", "int");
 	$project_id = http::value("project_id", "int");
 	$location_id = http::value("location_id", "int");
 	$test_id = http::value("test_id", "int");
@@ -27,6 +28,10 @@ if($user->level >= User::LEVEL_ADMIN) {
 	$nvp = [];
 	if($status) $nvp["status"] = $status;
 	if($project_id) $nvp["project_id"] = $project_id;
+	else if($customer_id) {
+		$projects = Project::query(["customer_id" => $customer_id]);
+		$nvp["project_id"] = array_column($projects, "id");
+	}
 	if($location_id) $nvp["location_id"] = $location_id;
 	else if($location_internal_id) {
 		$locations = Location::query(["internal_id" => $location_internal_id]);
@@ -68,6 +73,7 @@ if($user->level >= User::LEVEL_ADMIN) {
 
 	$testers = User::load(array_column($tests, "tester_id"));
 	$projects = Project::load(array_column($tests, "project_id"));
+	$customers = Customer::query([], ["sort" => "name"]);
 
 	usort($projects, function($a, $b) {
 		return $a->name <=> $b->name;
@@ -86,7 +92,7 @@ if($user->level >= User::LEVEL_ADMIN) {
 	];
 
 	View::includeOnce("header", compact("page_title"));
-	View::include("test_list", compact("tests", "test_count", "sort", "sorts", "pagination_string", "projects", "project_id", "location_id", "location_internal_id", "pass", "test_id", "filter_count", "status"));
+	View::include("test_list", compact("tests", "test_count", "sort", "sorts", "pagination_string", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "test_id", "filter_count", "status"));
 }
 
 // HQ / Venue (view completed tests)

+ 16 - 0
views/test_list.php

@@ -94,6 +94,22 @@ $results = [
 									</select>
 								</div>
 							</div>
+							<div class="row mb-1">
+								<label class="col-form-label col-sm-4" for="customer-id">Customer</label>
+								<div class="col-sm">
+									<select class="form-control" name="customer_id" id="customer-id">
+										<option value="">Select customer</option>
+										<?php
+										foreach($customers as $customer) {
+											$selected = ($customer->id == $customer_id) ? "selected" : "";
+											?>
+											<option value="<?=$customer->id?>" <?=$selected?>><?=htmlspecialchars($customer->name)?></option>
+											<?php
+										}
+										?>
+									</select>
+								</div>
+							</div>
 							<div class="row mb-1">
 								<label class="col-form-label col-sm-4" for="project-id">Project</label>
 								<div class="col-sm">