ソースを参照

Added custom filters.

Alan Lam 8 年 前
親
コミット
6663337a2c
2 ファイル変更、60 行追加、5 行削除
  1. 37 4
      controllers/tests.php
  2. 23 1
      views/test_list.php

+ 37 - 4
controllers/tests.php

@@ -17,6 +17,7 @@ if($user->level >= User::LEVEL_ADMIN) {
 	$test_id = http::value("test_id", "int");
 	$test_id = http::value("test_id", "int");
 	$location_internal_id = http::value("location_internal_id", "int");
 	$location_internal_id = http::value("location_internal_id", "int");
 	$pass = http::value("pass", "int");
 	$pass = http::value("pass", "int");
+	$custom = http::value("custom");
 
 
 	$filter_count_offset = 0;
 	$filter_count_offset = 0;
 
 
@@ -42,8 +43,6 @@ if($user->level >= User::LEVEL_ADMIN) {
 	if(strlen($pass) > 0) $nvp["pass"] = $pass;
 	if(strlen($pass) > 0) $nvp["pass"] = $pass;
 
 
 	$filter_count = count($nvp);
 	$filter_count = count($nvp);
-	$filter_count += $filter_count_offset;
-	if(!$filter_count) $filter_count = "";
 
 
 	$sort = http::value("sort");
 	$sort = http::value("sort");
 	switch($sort) {
 	switch($sort) {
@@ -60,13 +59,47 @@ if($user->level >= User::LEVEL_ADMIN) {
 	}
 	}
 
 
 	$tests = Test::query($nvp, $query_options);
 	$tests = Test::query($nvp, $query_options);
+	$projects = Project::load(array_column($tests, "project_id"));
+
+	switch($custom) {
+		case "overdue_project":
+			$tests = array_filter($tests, function($test) {
+				if($test->status == Test::STATUS_CANCELLED) return false;
+				$project = $test->getProject();
+
+				$unix_deadline = Util::getUnixTimeFromUTC($project->dts_deadline);
+
+				return ($test->status != Test::STATUS_COMPLETED && time() > $unix_deadline);
+			});
+
+			$filter_count++;
+
+			break;
+		case "overdue_test":
+			$tests = array_filter($tests, function($test) {
+				if($test->status == Test::STATUS_CANCELLED) return false;
+				if(is_null($test->dts_due)) return false;
+
+				$unix_due = Util::getUnixTimeFromUTC($test->dts_due);
+
+				return ($test->status < Test::STATUS_STARTED && time() > $unix_due);
+			});
+
+			$filter_count++;
+
+			break;
+	}
+
+	$filter_count += $filter_count_offset;
+	if(!$filter_count) $filter_count = "";
+
 	$pagination_object = Util::getPaginationObject($tests);
 	$pagination_object = Util::getPaginationObject($tests);
 	$tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
 	$tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
 
 
 	$testers = User::load(array_column($tests, "tester_id"));
 	$testers = User::load(array_column($tests, "tester_id"));
-	$projects = Project::load(array_column($tests, "project_id"));
 	$customers = Customer::query([], ["sort" => "name"]);
 	$customers = Customer::query([], ["sort" => "name"]);
 
 
+
 	usort($projects, function($a, $b) {
 	usort($projects, function($a, $b) {
 		return $a->name <=> $b->name;
 		return $a->name <=> $b->name;
 	});
 	});
@@ -78,7 +111,7 @@ if($user->level >= User::LEVEL_ADMIN) {
 	];
 	];
 
 
 	View::includeOnce("header", compact("page_title"));
 	View::includeOnce("header", compact("page_title"));
-	View::include("test_list", compact("tests", "pagination_object", "sort", "sorts", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "test_id", "filter_count", "status"));
+	View::include("test_list", compact("tests", "pagination_object", "sort", "sorts", "projects", "customers", "customer_id", "project_id", "location_id", "location_internal_id", "pass", "custom", "test_id", "filter_count", "status"));
 }
 }
 
 
 // HQ / Venue (view completed tests)
 // HQ / Venue (view completed tests)

+ 23 - 1
views/test_list.php

@@ -11,6 +11,11 @@ $results = [
 	"0" => "Fail",
 	"0" => "Fail",
 ];
 ];
 
 
+$custom_filters = [
+	"overdue_project" => "Overdue (Project Deadline)",
+	"overdue_test" => "Overdue (Test Due Date)",
+];
+
 ?>
 ?>
 <div class="container mt-3 py-4">
 <div class="container mt-3 py-4">
 
 
@@ -159,6 +164,22 @@ $results = [
 								<input class="form-control" type="text" name="location_internal_id" id="location-internal-id" placeholder="Enter location internal ID" value="<?=$location_internal_id?>" />
 								<input class="form-control" type="text" name="location_internal_id" id="location-internal-id" placeholder="Enter location internal ID" value="<?=$location_internal_id?>" />
 							</div>
 							</div>
 						</div>
 						</div>
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="custom">Custom Filter</label>
+							<div class="col-sm">
+								<select class="form-control" name="custom" id="custom">
+									<option value="">Select custom filter</option>
+									<?php
+									foreach($custom_filters as $value => $display) {
+										$selected = (strval($value) === strval($custom)) ? "selected" : "";
+										?>
+										<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
+										<?php
+									}
+									?>
+								</select>
+							</div>
+						</div>
 					</div>
 					</div>
 				</div>
 				</div>
 
 
@@ -242,7 +263,8 @@ $results = [
 							<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city"]))?></small>
 							<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city"]))?></small>
 						</td>
 						</td>
 						<td class="align-middle">
 						<td class="align-middle">
-							<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
+							<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a><br />
+							<small><strong>Deadline:</strong> <?=date("d/m/Y", strtotime($project->dts_deadline . " UTC"))?><small>
 						</td>
 						</td>
 						<td class="align-middle">
 						<td class="align-middle">
 						<?php
 						<?php