Alan Lam пре 3 година
родитељ
комит
c76485d39e
6 измењених фајлова са 61 додато и 26 уклоњено
  1. 8 2
      controllers/log.php
  2. 1 1
      controllers/tests_admin_list.php
  3. 1 1
      controllers/tests_completed.php
  4. 1 1
      controllers/users.php
  5. 2 4
      engine/util.php
  6. 48 17
      views/log.php

+ 8 - 2
controllers/log.php

@@ -5,11 +5,17 @@ $page_title = "Log";
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account/log", $page_title);
 Core::addBreadcrumb("/account/log", $page_title);
 
 
-$entries = LocationUpdateLogEntry::query([], ["sort" => "id", "order" => "desc", "limit" => 1000]);
+$count = LocationUpdateLogEntry::count();
+
+$pagination_object = Util::getPaginationObject($count);
+
+
+
+$entries = LocationUpdateLogEntry::query([], ["sort" => "id", "order" => "desc", "offset" => $pagination_object->offset, "limit" => $pagination_object->pageSize]);
 
 
 User::load(array_column($entries, "user_id"));
 User::load(array_column($entries, "user_id"));
 Location::load(array_column($entries, "location_id"));
 Location::load(array_column($entries, "location_id"));
 
 
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));
-View::include("log", ["entries" => $entries]);
+View::include("log", compact("entries", "pagination_object"));
 View::includeOnce("footer");
 View::includeOnce("footer");

+ 1 - 1
controllers/tests_admin_list.php

@@ -232,7 +232,7 @@ switch($custom) {
 $filter_count += $filter_count_offset;
 $filter_count += $filter_count_offset;
 if(!$filter_count) $filter_count = "";
 if(!$filter_count) $filter_count = "";
 
 
-$pagination_object = Util::getPaginationObject($tests);
+$pagination_object = Util::getPaginationObject(count($tests));
 $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
 $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
 
 
 $testers = User::load(array_column($tests, "tester_id"));
 $testers = User::load(array_column($tests, "tester_id"));

+ 1 - 1
controllers/tests_completed.php

@@ -10,7 +10,7 @@ Core::addBreadcrumb("/account/tests/completed", $page_title);
 
 
 $tests = Core::$user->getCompletedTests();
 $tests = Core::$user->getCompletedTests();
 
 
-$pagination_object = Util::getPaginationObject($tests);
+$pagination_object = Util::getPaginationObject(count($tests));
 
 
 $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
 $tests = array_slice($tests, $pagination_object->offset, $pagination_object->pageSize);
 
 

+ 1 - 1
controllers/users.php

@@ -71,7 +71,7 @@ switch($sort) {
 
 
 $users = User::query($nvp, $query_options);
 $users = User::query($nvp, $query_options);
 
 
-$pagination_object = Util::getPaginationObject($users);
+$pagination_object = Util::getPaginationObject(count($users));
 
 
 Core::$page = $pagination_object->page;
 Core::$page = $pagination_object->page;
 Core::$page_count = $pagination_object->pageCount;
 Core::$page_count = $pagination_object->pageCount;

+ 2 - 4
engine/util.php

@@ -38,14 +38,12 @@ class Util {
 	}
 	}
 
 
 	/**
 	/**
-	 * @param array $items
+	 * @param int $item_count
 	 * @param int $page_size
 	 * @param int $page_size
 	 * @return object
 	 * @return object
 	 * @throws Exception
 	 * @throws Exception
 	 */
 	 */
-	public static function getPaginationObject(array $items, int $page_size = 25) {
-		$item_count = count($items);
-
+	public static function getPaginationObject(int $item_count, int $page_size = 25): object {
 		$page = http::value("page");
 		$page = http::value("page");
 		if($page < 1) $page = 1;
 		if($page < 1) $page = 1;
 
 

+ 48 - 17
views/log.php

@@ -2,6 +2,7 @@
 
 
 /**
 /**
  * @var LocationUpdateLogEntry[] $entries
  * @var LocationUpdateLogEntry[] $entries
+ * @var object $pagination_object
  */
  */
 
 
 ?>
 ?>
@@ -9,15 +10,19 @@
 
 
 	<h2>Log</h2>
 	<h2>Log</h2>
 
 
+	<div class="mb-3">
+		<?php
+		View::include("pagination", compact("pagination_object"));
+		?>
+	</div>
+
 	<table class="table table-sm table-bordered">
 	<table class="table table-sm table-bordered">
 		<thead>
 		<thead>
 		<tr>
 		<tr>
-			<th>Location</th>
 			<th>Date/Time</th>
 			<th>Date/Time</th>
+			<th>Location</th>
 			<th>User</th>
 			<th>User</th>
-			<th>Field</th>
-			<th>Before</th>
-			<th>After</th>
+			<th>Changes</th>
 		</tr>
 		</tr>
 		</thead>
 		</thead>
 		<tbody>
 		<tbody>
@@ -26,23 +31,49 @@
 			$location = $entry->getLocation();
 			$location = $entry->getLocation();
 			$user = $entry->getUser();
 			$user = $entry->getUser();
 			$dts = Util::getDisplayDateTimeFromUTC($entry->dts);
 			$dts = Util::getDisplayDateTimeFromUTC($entry->dts);
-			$modifications = $entry->getModifications();
-			foreach($modifications as $modification) {
-				?>
-				<tr>
-					<td><?=htmlspecialchars($dts)?></td>
-					<td><a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a></td>
-					<td><a href="<?=htmlspecialchars($user->getURL())?>"><?=htmlspecialchars($user->email)?></a></td>
-					<td class="text-monospace"><?=htmlspecialchars($modification->field)?></td>
-					<td class="text-monospace"><?=htmlspecialchars($modification->before)?></td>
-					<td class="text-monospace"><?=htmlspecialchars($modification->after)?></td>
-				</tr>
-				<?php
-			}
+
 			?>
 			?>
+			<tr>
+				<td><?=htmlspecialchars($dts)?></td>
+				<td><a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a></td>
+				<td><a href="<?=htmlspecialchars($user->getURL())?>"><?=htmlspecialchars($user->email)?></a></td>
+				<td>
+					<table class="table-sm table-bordered w-100">
+						<colgroup>
+							<col style="width: 33%"/>
+							<col style="width: 33%"/>
+							<col style="width: 33%"/>
+						</colgroup>
+						<thead>
+						<tr>
+							<th>Field</th>
+							<th>Before</th>
+							<th>After</th>
+						</tr>
+						</thead>
+						<tbody>
+						<?php
+						foreach($entry->getModifications() as $modification) {
+							?>
+							<tr>
+								<td class="text-monospace"><?=htmlspecialchars($modification->field)?></td>
+								<td class="text-monospace"><?=htmlspecialchars($modification->before)?></td>
+								<td class="text-monospace"><?=htmlspecialchars($modification->after)?></td>
+							</tr>
+							<?php
+						}
+						?>
+						</tbody>
+					</table>
+				</td>
+			</tr>
 			<?php
 			<?php
 		}
 		}
 		?>
 		?>
 		</tbody>
 		</tbody>
 	</table>
 	</table>
+
+	<?php
+	View::include("pagination", compact("pagination_object"));
+	?>
 </div>
 </div>