Browse Source

Show assigned and completed tests on user page.

Alan Lam 8 năm trước cách đây
mục cha
commit
565d04f038
2 tập tin đã thay đổi với 98 bổ sung và 0 xóa
  1. 2 0
      engine/user.php
  2. 96 0
      views/user.php

+ 2 - 0
engine/user.php

@@ -273,6 +273,7 @@ class User extends Model {
 			"status" => [Test::STATUS_ASSIGNED, Test::STATUS_CONFIRMED],
 		], [
 			"sort" => "id",
+			"order" => "desc"
 		]);
 	}
 
@@ -282,6 +283,7 @@ class User extends Model {
 			"status" => [Test::STATUS_CANCELLED, Test::STATUS_COMPLETED],
 		], [
 			"sort" => "id",
+			"order" => "desc"
 		]);
 	}
 

+ 96 - 0
views/user.php

@@ -107,6 +107,59 @@ $completed_tests = $user->getCompletedTests();
 		<div class="alert alert-info">This user has no assigned tests.</div>
 		<?php
 	}
+	else {
+		?>
+		<table class="table table-sm table-hover">
+			<col style="width: 10%;" />
+			<col style="width: 40%;" />
+			<col style="width: 20%;" />
+			<col style="width: 10%;" />
+			<col style="width: 10%;" />
+			<thead>
+				<th>ID</th>
+				<th>Location</th>
+				<th>Project</th>
+				<th>Date Due</th>
+				<th></th>
+			</thead>
+		<?php
+		foreach($pending_tests as $test) {
+			$project = $test->getProject();
+			$location = $test->getLocation();
+
+			if(!is_null($test->dts_due)) {
+				$date = explode(" ", $test->dts_due)[0];
+				$unix_date = strtotime($date);
+			}
+			else {
+				$date = explode(" ", $project->dts_deadline)[0];
+				$unix_date = strtotime($date);
+			}
+
+			$date = date("d/m/Y", $unix_date);
+
+			?>
+				<tr>
+					<td><?=$test->id?></td>
+					<td>
+						<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a><br />
+						<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postcode"]))?></small>
+					</td>
+					<td class="align-middle">
+						<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
+					</td>
+					<td class="align-middle">
+						<?=$date?>
+					</td>
+					<td class="align-middle text-right">
+					</td>
+				</tr>
+			<?php
+		}
+		?>
+		</table>
+		<?php
+	}
 	?>
 
 	<h3>Completed Tests</h3>
@@ -117,6 +170,49 @@ $completed_tests = $user->getCompletedTests();
 		<div class="alert alert-info">This user has no completed tests.</div>
 		<?php
 	}
+	else {
+		?>
+		<table class="table table-sm table-hover">
+			<col style="width: 10%;" />
+			<col style="width: 40%;" />
+			<col style="width: 20%;" />
+			<col style="width: 10%;" />
+			<col style="width: 10%;" />
+			<thead>
+				<th>ID</th>
+				<th>Location</th>
+				<th>Project</th>
+				<th>Date</th>
+				<th></th>
+			</thead>
+		<?php
+		foreach($completed_tests as $test) {
+			$location = $test->getLocation();
+			$date = explode(" ", $test->dts_start)[0];
+			$date = date("d/m/Y", strtotime($date));
+			?>
+				<tr>
+					<td><?=$test->id?></td>
+					<td>
+						<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a><br />
+						<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postcode"]))?></small>
+					</td>
+					<td class="align-middle">
+						<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
+					</td>
+					<td class="align-middle">
+						<?=$date?>
+					</td>
+					<td class="align-middle text-right">
+						<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">View</a>
+					</td>
+				</tr>
+			<?php
+		}
+		?>
+		</table>
+		<?php
+	}
 	?>