Преглед изворни кода

Implemented Tests (Completed) page. Pagination changes and margin fixes.

Alan Lam пре 8 година
родитељ
комит
9875a0e749

+ 1 - 1
controllers/account.php

@@ -23,7 +23,7 @@ if(Core::$user->level >= User::LEVEL_TESTER) {
 
 
 if(Core::$user->level == User::LEVEL_TESTER) {
 if(Core::$user->level == User::LEVEL_TESTER) {
 	$links["/account/addresses"] = "Addresses";
 	$links["/account/addresses"] = "Addresses";
-	$links["/account/tests-completed"] = "Tests (Completed)";
+	$links["/account/tests/completed"] = "Tests (Completed)";
 }
 }
 
 
 if(Core::$user->level == User::LEVEL_REGISTERED) {
 if(Core::$user->level == User::LEVEL_REGISTERED) {

+ 4 - 0
controllers/test_file.php

@@ -3,6 +3,10 @@
 $test = Test::get($id);
 $test = Test::get($id);
 if(!$test) throw new Exception("Test not found.");
 if(!$test) throw new Exception("Test not found.");
 
 
+if(Core::$user->level < User::LEVEL_ADMIN) {
+	if(Core::$user->id != $test->tester_id) throw new Exception("You do not have permission to access this resource.");
+}
+
 $directory = $test->getDirectory();
 $directory = $test->getDirectory();
 $path = $directory . "/" . $name . ".jpg";
 $path = $directory . "/" . $name . ".jpg";
 
 

+ 1 - 1
controllers/tests.php

@@ -95,7 +95,7 @@ else if($user->level >= User::LEVEL_VENUE) {
 	//$testers = User::load(array_column($tests, "tester_id"));
 	//$testers = User::load(array_column($tests, "tester_id"));
 
 
 	View::includeOnce("header", compact("page_title"));
 	View::includeOnce("header", compact("page_title"));
-	View::include("test_list_completed", compact("tests"));
+	View::include("test_list_venue", compact("tests"));
 }
 }
 
 
 // Tester
 // Tester

+ 21 - 0
controllers/tests_completed.php

@@ -0,0 +1,21 @@
+<?php
+
+$page_title = "Completed Tests";
+
+Core::addBreadcrumb("/account", "Account");
+Core::addBreadcrumb("/account/tests", "Tests");
+Core::addBreadcrumb("/account/tests/completed", $page_title);
+
+$tests = Core::$user->getCompletedTests();
+$projects = Project::load(array_column($tests, "project_id"));
+
+$pagination_object = Util::getPaginationObject($tests, 25);
+
+Core::$page = $pagination_object->page;
+Core::$page_count = $pagination_object->pageCount;
+
+View::includeOnce("header", compact("page_title"));
+View::include("test_list_completed", compact("tests", "pagination_object"));
+View::includeOnce("footer");
+
+?>

+ 1 - 1
engine/user.php

@@ -258,7 +258,7 @@ class User extends Model {
 	public function getCompletedTests() {
 	public function getCompletedTests() {
 		return Test::query([
 		return Test::query([
 			"tester_id" => $this->id,
 			"tester_id" => $this->id,
-			"status" => Test::STATUS_COMPLETED,
+			"status" => [Test::STATUS_CANCELLED, Test::STATUS_COMPLETED],
 		], [
 		], [
 			"sort" => "id",
 			"sort" => "id",
 		]);
 		]);

+ 35 - 0
engine/util.php

@@ -1,6 +1,41 @@
 <?php
 <?php
 class Util {
 class Util {
 
 
+	public static function getPaginationObject($array, $page_size = 25) {
+		$item_count = count($array);
+
+		$page = http::value("page");
+		if($page < 1) $page = 1;
+
+		$offset = ($page - 1) * $page_size;
+		$page_count = ceil($item_count / $page_size);
+		if($page_count < 1) $page_count = 1;
+
+		$first_item = ($offset + 1);
+		$last_item = $offset + $page_size;
+
+		if($last_item > $item_count) {
+			$last_item = $item_count;
+		}
+
+		if($page_count == 1) {
+			$range_text = "Showing $item_count items";
+		}
+		else {
+			$range_text = "Showing $first_item - $last_item of $item_count items";
+		}
+
+		return (object) [
+			"page" => $page,
+			"pageCount" => $page_count,
+			"pageSize" => $page_size,
+			"offset" => $offset,
+			"firstItem" => $first_item,
+			"lastItem" => $last_item,
+			"rangeText" => $range_text
+		];
+	}
+
 	public static function getItemDirectory($folder, $id) {
 	public static function getItemDirectory($folder, $id) {
 		$shard = str_pad($id % 1000, 3, "0", STR_PAD_LEFT);
 		$shard = str_pad($id % 1000, 3, "0", STR_PAD_LEFT);
 		return ROOT_DIR . "/files/" . $folder . "/" . $shard . "/" . $id;
 		return ROOT_DIR . "/files/" . $folder . "/" . $shard . "/" . $id;

+ 2 - 0
routes.php

@@ -54,7 +54,9 @@ $routes = [
 
 
 	// Tests
 	// Tests
 	"/^account\/tests$/" => ["controller" => "tests", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests$/" => ["controller" => "tests", "require_user_level" => User::LEVEL_TESTER],
+	"/^account\/tests\/completed$/" => ["controller" => "tests_completed", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern$/" => ["controller" => "test", "params" => ["id"], "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern$/" => ["controller" => "test", "params" => ["id"], "require_user_level" => User::LEVEL_TESTER],
+	"/^account\/tests\/$id_pattern\/(selfie)$/" => ["controller" => "test_file", "params" => ["id", "name"], "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern\/files\/([a-z_]+)$/" => ["controller" => "test_file", "params" => ["id", "name"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/tests\/$id_pattern\/files\/([a-z_]+)$/" => ["controller" => "test_file", "params" => ["id", "name"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/tests\/$id_pattern\/result$/" => ["controller" => "test_result", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],
 	"/^account\/tests\/$id_pattern\/result$/" => ["controller" => "test_result", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],
 	"/^account\/tests\/$id_pattern\/pdf$/" => ["controller" => "test_pdf", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],
 	"/^account\/tests\/$id_pattern\/pdf$/" => ["controller" => "test_pdf", "params" => ["id"], "require_user_level" => User::LEVEL_VENUE],

+ 1 - 1
views/pagination.php

@@ -20,7 +20,7 @@ $next_url = $path . "?" . http_build_query(array_merge($nvp, ["page" => $page +
 
 
 ?>
 ?>
 <nav aria-label="Page navigation">
 <nav aria-label="Page navigation">
-	<ul class="pagination">
+	<ul class="pagination mb-0 justify-content-center">
 		<li class="page-item <?=$previous_disabled?>">
 		<li class="page-item <?=$previous_disabled?>">
 			<a class="page-link" href="<?=htmlspecialchars($previous_url)?>">
 			<a class="page-link" href="<?=htmlspecialchars($previous_url)?>">
 				<span aria-hidden="true">&laquo;</span>
 				<span aria-hidden="true">&laquo;</span>

+ 4 - 4
views/test_list.php

@@ -168,10 +168,10 @@ $results = [
 		?>
 		?>
 
 
 		<div class="row">
 		<div class="row">
-			<div class="col-md text-center text-md-left align-self-md-center mb-3">
+			<div class="col-md text-center text-md-left align-self-center mb-3">
 				<?=htmlspecialchars($pagination_string)?>
 				<?=htmlspecialchars($pagination_string)?>
 			</div>
 			</div>
-			<div class="col-md-auto d-flex justify-content-center">
+			<div class="col-md-auto mb-3">
 				<?php
 				<?php
 				View::include("pagination");
 				View::include("pagination");
 				?>
 				?>
@@ -274,10 +274,10 @@ $results = [
 
 
 
 
 		<div class="row">
 		<div class="row">
-			<div class="col-md text-center text-md-left align-self-md-center mb-3">
+			<div class="col-md text-center mb-3 text-md-left align-self-center">
 				<?=htmlspecialchars($pagination_string)?>
 				<?=htmlspecialchars($pagination_string)?>
 			</div>
 			</div>
-			<div class="col-md-auto d-flex justify-content-center">
+			<div class="col-md-auto mb-3">
 				<?php
 				<?php
 				View::include("pagination");
 				View::include("pagination");
 				?>
 				?>

+ 113 - 19
views/test_list_completed.php

@@ -1,38 +1,132 @@
 <div class="container mt-3 py-4">
 <div class="container mt-3 py-4">
 
 
-	<h2>Tests</h2>
+	<h2>Completed Tests</h2>
 
 
 	<?php
 	<?php
 
 
 	if(empty($tests)) {
 	if(empty($tests)) {
 		?>
 		?>
 		<div class="alert alert-info">
 		<div class="alert alert-info">
-			No tests have been completed for your location yet.
+			You have not completed any tests yet.
 		</div>
 		</div>
 		<?php
 		<?php
 	}
 	}
 	else {
 	else {
 		?>
 		?>
-		<div class="list-group">
-		<?php
-		foreach($tests as $test) {
-			$location = $test->getLocation();
-			?>
-			<div class="list-group-item">
-				<div class="row">
-					<div class="col-md">
-						<?=htmlspecialchars($location->name)?><br />
-						<?=htmlspecialchars($location->getDisplayAddress())?>
-					</div>
-					<div class="col-auto align-self-center">
-						<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>" title="View Results" data-toggle="tooltip"><i class="fal fa-search"></i></a>
-					</div>
-				</div>
+
+		<div class="row">
+			<div class="col-sm text-center text-sm-left align-self-center mb-3">
+			<?=htmlspecialchars($pagination_object->rangeText)?>
 			</div>
 			</div>
+			<div class="col-sm-auto mb-3">
 			<?php
 			<?php
-		}
-		?>
+			View::include("pagination");
+			?>
+			</div>
 		</div>
 		</div>
+
+		<table class="table table-sm table-hover">
+			<thead>
+				<tr>
+					<th class="text-right">ID</th>
+					<th>Location</th>
+					<th>Attire</th>
+					<th>Selfie</th>
+					<th>Date</th>
+					<th>Time</th>
+					<th>Duration</th>
+					<th>Status</th>
+					<th>Fee</th>
+				</tr>
+			</thead>
+			<tbody>
+			<?php
+
+			$original_timezone = date_default_timezone_get();
+
+			foreach($tests as $test) {
+				$location = $test->getLocation();
+				$project = $test->getProject();
+
+				$attire = $date_start = $time_start = $duration = "N/A";
+				$attire_class = $date_start_class = $time_start_class = $duration_class = $fee_class = "text-muted";
+
+				date_default_timezone_set("UTC");
+				if($test->dts_start) {
+					$start_dt = new DateTime($test->dts_start);
+					$date_start = $start_dt->format("d/m/Y");
+					$time_start = $start_dt->format("H:i:s");
+					$attire = $test->attire;
+
+					$attire_class = $date_start_class = $time_start_class = "";
+				}
+				if($test->dts_start && $test->dts_end) {
+					$end_dt = new DateTime($test->dts_end);
+					$diff = $start_dt->diff($end_dt, true);
+					$duration = $diff->format("%H:%I:%S");
+					$duration_class = "";
+
+
+
+				}
+
+				date_default_timezone_set($original_timezone);
+
+				$status_class = $test->getStatusClass();
+				$status_text = $test->getStatusText();
+
+				$status_class = "secondary";
+				$status_text = "Pending";
+
+				if($test->status == Test::STATUS_CANCELLED) {
+					$status_class = "danger";
+					$status_text = "Rejected";
+					$fee = "N/A";
+				}
+				if($test->status == Test::STATUS_COMPLETED) {
+					$status_class = "success";
+					$status_text = "Accepted";
+					$fee = $test->fee ? $test->fee : $project->default_tester_fee;
+					$fee = "£" . $fee;
+					$fee_class = "";
+				}
+
+				?>
+					<tr>
+						<td class="text-right">
+							<?=$test->id?>
+						</td>
+						<td>
+							<?=htmlspecialchars($location->name)?><br />
+							<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]))?></small>
+						</td>
+						<td class="<?=$attire_class?>">
+							<?=htmlspecialchars($attire)?>
+						</td>
+						<td class="align-middle">
+							<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>/selfie">View</a>
+						</td>
+						<td class="text-center align-middle <?=$date_start_class?>">
+							<?=htmlspecialchars($date_start)?>
+						</td>
+						<td class="text-center align-middle <?=$time_start_class?>">
+							<?=htmlspecialchars($time_start)?>
+						</td>
+						<td class="text-center align-middle <?=$duration_class?>">
+							<?=htmlspecialchars($duration)?>
+						</td>
+						<td class="text-center align-middle">
+							<span class="badge badge-lg badge-<?=$status_class?>"><?=htmlspecialchars($status_text)?></span>
+						</td>
+						<td class="text-center align-middle <?=$fee_class?>">
+							<?=$fee?>
+						</td>
+					</tr>
+				<?php
+			}
+			?>
+			</tbody>
+		</table>
 		<?php
 		<?php
 	}
 	}