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

Add "Overview" page for super-admins

Alan Lam 5 лет назад
Родитель
Сommit
3a73bb9b24
7 измененных файлов с 119 добавлено и 2 удалено
  1. 4 1
      controllers/account.php
  2. 31 0
      controllers/overview.php
  3. 6 0
      engine/constraint.php
  4. 11 0
      engine/html.php
  5. 1 1
      engine/project.php
  6. 3 0
      routes.php
  7. 63 0
      views/overview.php

+ 4 - 1
controllers/account.php

@@ -42,7 +42,6 @@ if($user->isCustomer()) {
 
 		$tests = $test_result_set->filterByDateRange($start, $end);
 
-
 		$test_count = count($tests);
 
 		if($test_count > 0) {
@@ -97,6 +96,10 @@ $tests_remaining = 0;
 
 $icons = [];
 
+if($user->isSuperAdmin()) {
+	$icons[] = new AccountIcon(__("Overview"), "/account/overview", "tasks-alt");
+}
+
 if($user->canAccessCustomers()) {
 	$icons[] = new AccountIcon(__("Customers"), "/account/customers", "warehouse");
 }

+ 31 - 0
controllers/overview.php

@@ -0,0 +1,31 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+use Carbon\CarbonImmutable;
+
+$page_title = __("Overview");
+
+$dt_now = CarbonImmutable::now(TIMEZONE);
+
+$ranges = [];
+
+$ranges[] = [
+	"name" => __("Year to Date"),
+	"start" => $dt_now->startOfYear(),
+	"end" =>  $dt_now->endOfYear()
+];
+
+$ranges[] = [
+	"name" => __("This Month"),
+	"start" => $dt_now->startOfMonth(),
+	"end" => $dt_now->endOfMonth(),
+];
+
+$ranges[] = [
+	"name" => __("Last Month"),
+	"start" => $dt_now->subMonthNoOverflow()->startOfMonth(),
+	"end" => $dt_now->subMonthNoOverflow()->endOfMonth(),
+];
+
+View::includeOnce("header", compact("page_title"));
+View::include("overview", compact("page_title", "ranges"));
+View::includeOnce("footer");

+ 6 - 0
engine/constraint.php

@@ -30,6 +30,12 @@ class Constraint {
 		return $constraint;
 	}
 
+	public static function between(string $start, string $end): Constraint {
+		$constraint = new Constraint("BETWEEN");
+		$constraint->setValues($start, $end);
+		return $constraint;
+	}
+
 	/**
 	 * Constraint constructor.
 	 * @param string $type

+ 11 - 0
engine/html.php

@@ -18,4 +18,15 @@ class HTML {
         <link rel="stylesheet" type="text/css" href="<?=htmlspecialchars($src)?>?<?=$modified_time?>" />
 		<?php
 	}
+
+	public static function renderStat(string $name, string $stat): void {
+		?>
+		<div class="card card-body mb-3">
+			<?=htmlspecialchars($name)?>
+			<div class="stat">
+				<?=htmlspecialchars($stat)?>
+			</div>
+		</div>
+		<?php
+	}
 }

+ 1 - 1
engine/project.php

@@ -108,7 +108,7 @@ class Project extends Model {
 	 */
 	public function getTests(): array {
 
-		if(!is_null($this->tests)) return $this->tests;
+		if($this->tests !== null) return $this->tests;
 
 		$nvp = [];
 		$nvp["project_id"] = $this->id;

+ 3 - 0
routes.php

@@ -147,4 +147,7 @@ $routes = [
 	"/^account\/reports$/" => ["controller" => "reports", "require_user_level" => User::LEVEL_VENUE, "require_data_tables" => true],
 	"/^account\/reports\/(export-odp|export-pptx)$/" => ["controller" => "reports", "params" => ["action"], "require_user_level" => User::LEVEL_VENUE],
 
+	// Overview
+	"/^account\/overview$/" => ["controller" => "overview", "require_user_level" => User::LEVEL_SUPERADMIN],
+
 ];

+ 63 - 0
views/overview.php

@@ -0,0 +1,63 @@
+<?php
+/**
+ * @var string $page_title
+ * @var array $ranges
+ */
+
+use Carbon\CarbonImmutable;
+
+?>
+<div class="container mt-3 py-4">
+
+	<h2><?=htmlspecialchars($page_title)?></h2>
+
+	<div class="row">
+		<?php
+		foreach($ranges as $range) {
+			$name = $range["name"];
+
+			/** @var CarbonImmutable $dt_start */
+			$dt_start = $range["start"];
+
+			/** @var CarbonImmutable $dt_end */
+			$dt_end = $range["end"];
+
+			$dts_start = $dt_start->utc()->format("Y-m-d H:i:s");
+			$dts_end = $dt_end->utc()->format("Y-m-d H:i:s");
+
+			$test_count = Test::count([
+				"dts_start" => Constraint::between($dts_start, $dts_end),
+				"status" => Test::STATUS_COMPLETED
+			]);
+
+			$projects = Project::query([
+				"dts_start" => Constraint::between($dts_start, $dts_end),
+			]);
+
+			?>
+			<div class="col-lg-4">
+				<h3><?=htmlspecialchars($name)?></h3>
+				<?php
+				Html::renderStat("Test Count", $test_count);
+
+				foreach($projects as $project) {
+					$percentage = $project->getCompletedPercentage();
+					?>
+					<div class="card card-body py-2">
+						<strong><?=htmlspecialchars($project->name)?></strong>
+						<div class="progress">
+							<div class="progress-bar" role="progressbar" aria-valuenow="<?=$percentage?>" aria-valuemin="0" aria-valuemax="100" style="width: <?=$percentage?>%">
+
+							</div>
+						</div>
+					</div>
+					<?php
+				}
+
+				?>
+			</div>
+			<?php
+		}
+		?>
+	</div>
+</div>