Browse Source

Split tests controller to separate scripts

Alan Lam 8 years ago
parent
commit
913a8b114b

+ 3 - 113
controllers/tests.php

@@ -9,127 +9,17 @@ $user = Core::$user;
 
 // Admin / Super Admin
 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");
-	$location_internal_id = http::value("location_internal_id", "int");
-	$pass = http::value("pass", "int");
-	$custom = http::value("custom");
-
-	$filter_count_offset = 0;
-
-	$nvp = [];
-	if(strlen($status) > 0) $nvp["status"] = $status;
-	else {
-		$nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
-		$filter_count_offset--;
-	}
-	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]);
-		if($locations) {
-			$nvp["location_id"] = array_column($locations, "id");
-		}
-	}
-	if($test_id) $nvp["id"] = $test_id;
-	if(strlen($pass) > 0) $nvp["pass"] = $pass;
-
-	$filter_count = count($nvp);
-
-	$sort = http::value("sort");
-	switch($sort) {
-		case "updated":
-			$query_options = ["sort" => "dts_updated", "order" => "desc"];
-			break;
-		case "due":
-			$query_options = ["sort" => "dts_due", "order" => "desc"];
-			break;
-		default:
-			$sort = "status";
-			$query_options = ["sort" => "status", "order" => "asc"];
-			break;
-	}
-
-	$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);
-	$tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
-
-	$testers = User::load(array_column($tests, "tester_id"));
-	$customers = Customer::query([], ["sort" => "name"]);
-
-
-	usort($projects, function($a, $b) {
-		return $a->name <=> $b->name;
-	});
-
-	$sorts = [
-		"status" => "Status",
-		"updated" => "Update",
-		"due" => "Due",
-	];
-
-	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", "custom", "test_id", "filter_count", "status"));
+	require "tests_admin_list.php";
 }
 
 // HQ / Venue (view completed tests)
 else if($user->level >= User::LEVEL_VENUE) {
-
-	//$testers = User::load(array_column($tests, "tester_id"));
-
-	View::includeOnce("header", compact("page_title"));
-	View::include("test_list_venue", compact("tests"));
+	require "tests_location_list.php";
 }
 
 // Tester
 else if($user->level == User::LEVEL_TESTER) {
-	$tests = $user->getPendingTests();
-	$testers = User::load(array_column($tests, "tester_id"));
-
-	View::includeOnce("header", compact("page_title"));
-	View::include("test_list_assigned", compact("tests"));
+	require "tests_tester_list.php";
 }
 
 View::includeOnce("modal_page_jump");

+ 106 - 0
controllers/tests_admin_list.php

@@ -0,0 +1,106 @@
+<?php
+
+$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");
+$location_internal_id = http::value("location_internal_id", "int");
+$pass = http::value("pass", "int");
+$custom = http::value("custom");
+
+$filter_count_offset = 0;
+
+$nvp = [];
+if(strlen($status) > 0) $nvp["status"] = $status;
+else {
+	$nvp["status"] = (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED);
+	$filter_count_offset--;
+}
+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]);
+	if($locations) {
+		$nvp["location_id"] = array_column($locations, "id");
+	}
+}
+if($test_id) $nvp["id"] = $test_id;
+if(strlen($pass) > 0) $nvp["pass"] = $pass;
+
+$filter_count = count($nvp);
+
+$sort = http::value("sort");
+switch($sort) {
+	case "updated":
+		$query_options = ["sort" => "dts_updated", "order" => "desc"];
+		break;
+	case "due":
+		$query_options = ["sort" => "dts_due", "order" => "desc"];
+		break;
+	default:
+		$sort = "status";
+		$query_options = ["sort" => "status", "order" => "asc"];
+		break;
+}
+
+$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);
+$tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
+
+$testers = User::load(array_column($tests, "tester_id"));
+$customers = Customer::query([], ["sort" => "name"]);
+
+
+usort($projects, function($a, $b) {
+	return $a->name <=> $b->name;
+});
+
+$sorts = [
+	"status" => "Status",
+	"updated" => "Update",
+	"due" => "Due",
+];
+
+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", "custom", "test_id", "filter_count", "status"));
+
+?>

+ 6 - 0
controllers/tests_location_list.php

@@ -0,0 +1,6 @@
+<?php
+
+View::includeOnce("header", compact("page_title"));
+View::include("test_list_venue", compact("tests"));
+
+?>

+ 9 - 0
controllers/tests_tester_list.php

@@ -0,0 +1,9 @@
+<?php
+
+$tests = $user->getPendingTests();
+$testers = User::load(array_column($tests, "tester_id"));
+
+View::includeOnce("header", compact("page_title"));
+View::include("test_list_assigned", compact("tests"));
+
+?>