Просмотр исходного кода

Add last test status in project locations list

Alan Lam 3 лет назад
Родитель
Сommit
eacf6d5c7a
4 измененных файлов с 69 добавлено и 21 удалено
  1. 19 0
      engine/customer.php
  2. 30 0
      engine/test.php
  3. 1 20
      views/location_list.php
  4. 19 1
      views/project_form.php

+ 19 - 0
engine/customer.php

@@ -174,4 +174,23 @@ class Customer extends Model {
 		return null;
 	}
 
+	/**
+	 * @return Test[]
+	 * @throws Exception
+	 */
+	public function getLatestTestByLocation(): array {
+		$output = [];
+
+		$tests = Test::query([
+			"status" => Constraint::notEquals(Test::STATUS_CANCELLED),
+			"location_id" => array_column($this->getLocations(), "id")
+		], ["sort" => "dts_start", "order" => "asc"]);
+
+		foreach($tests as $test) {
+			$output[$test->location_id] = $test;
+		}
+
+		return $output;
+	}
+
 }

+ 30 - 0
engine/test.php

@@ -915,4 +915,34 @@ class Test extends Model {
 		return CarbonImmutable::parse($this->dts_rejected, "UTC");
 	}
 
+	public function renderTestStatus(User $user): void {
+		?>
+		<a href="/account/tests/<?=$this->id?>">
+		<?php
+		
+		if($this->isPass()) {
+			?>
+			<i class="fa fa-fw fa-check-circle text-success"></i> Passed on <?=$user->formatDate($this->getDateTimeStart())?>
+			<?php
+		}
+		elseif($this->isVoid()) {
+			?>
+			<i class="fa fa-fw fa-minus-circle text-secondary"></i> Void on <?=$user->formatDate($this->getDateTimeStart())?>
+			<?php
+		}
+		elseif($this->isFail()) {
+			?>
+			<i class="fa fa-fw fa-times-circle text-danger"></i> Failed on <?=$user->formatDate($this->getDateTimeStart())?>
+			<?php
+		}
+		else {
+			?>
+			<i class="fa fa-fw fa-question-circle text-warning"></i> Result Pending (Test <?=htmlspecialchars($this->getStatusText())?>)
+			<?php
+		}
+		?>
+		</a>
+		<?php
+	}
+
 }

+ 1 - 20
views/location_list.php

@@ -76,26 +76,7 @@ $user = Core::$user;
 				<td>
 					<?php
 					if($test) {
-						if($test->isPass()) {
-							?>
-							<i class="fa fa-fw fa-check-circle text-success"></i> Passed on <?=$user->formatDate($test->getDateTimeStart())?>
-							<?php
-						}
-						elseif($test->isVoid()) {
-							?>
-							<i class="fa fa-fw fa-minus-circle text-secondary"></i> Void on <?=$user->formatDate($test->getDateTimeStart())?>
-							<?php
-						}
-						elseif($test->isFail()) {
-							?>
-							<i class="fa fa-fw fa-times-circle text-danger"></i> Failed on <?=$user->formatDate($test->getDateTimeStart())?>
-							<?php
-						}
-						else {
-							?>
-							None
-							<?php
-						}
+						$test->renderTestStatus($user);
 					}
 					else {
 						?>

+ 19 - 1
views/project_form.php

@@ -9,6 +9,8 @@
  * @var Template $template
  */
 
+$user = Core::$user;
+
 // Get test counts for current year cycle
 $tests = Test::query([
 	"status" => Constraint::notEquals(Test::STATUS_CANCELLED),
@@ -27,6 +29,8 @@ foreach($tests as $test) {
 	}
 }
 
+$latest_tests = $customer->getLatestTestByLocation();
+
 $dt_start = $project->getDateTimeStart();
 $dt_deadline = $project->getDateTimeDeadline();
 
@@ -54,7 +58,7 @@ $deselected_locations = array_filter($locations, static function(Location $l) us
  * @param bool $selected
  * @return void
  */
-$output_locations = static function(array $locations, bool $selected) use ($location_test, $test_counts, $customer) {
+$output_locations = static function(array $locations, bool $selected) use ($location_test, $test_counts, $customer, $latest_tests, $user) {
 	foreach($locations as $location) {
 		$address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
 
@@ -100,6 +104,20 @@ $output_locations = static function(array $locations, bool $selected) use ($loca
 						?>
 					</div>
 					<small><?=htmlspecialchars($address)?></small><br />
+					<small>
+						<strong>Last Test:</strong>
+						<?php
+						$test = $latest_tests[$location->id] ?? null;
+						if($test) {
+							$test->renderTestStatus($user);
+						}
+						else {
+							?>
+							None
+							<?php
+						}
+						?>
+					</small><br />
 					<small title="<?=htmlspecialchars(__("Number of tests completed between %s", $customer->getDisplayYearCycle()))?>">
 						<strong>Completed:</strong>
 						<?=htmlspecialchars(sprintf("%d / %d", $test_counts[$location->id] ?? 0, $location->annual_test_count))?>