Explorar o código

Add more options when exporting users

Alan Lam %!s(int64=3) %!d(string=hai) anos
pai
achega
c74ff81d42

+ 1 - 1
controllers/users.php

@@ -73,8 +73,8 @@ Core::$page_count = $pagination_object->pageCount;
 
 $users = array_slice($users, $pagination_object->offset, $pagination_object->pageSize);
 
-
 View::includeOnce("header", compact("page_title"));
 View::include("users", compact("users", "pagination_object", "filter_count", "id", "first_name", "last_name", "archived", "email", "level", "customer_id", "location_id", "sort", "sorts"));
 View::includeOnce("modal_page_jump");
+View::includeOnce("modals/user_export");
 View::includeOnce("footer");

+ 20 - 0
controllers/users_export.php

@@ -4,6 +4,8 @@
  * @var string $type
  */
 
+use Carbon\CarbonImmutable;
+
 switch($type) {
 
 	case "email":
@@ -24,11 +26,29 @@ switch($type) {
 			$nvp["level"] = $level;
 		}
 
+		$max_age = http::value("max_age", "int");
+
+		$dt_max = null;
+		$no_tests_after = http::value("no_tests_after");
+		if($no_tests_after) {
+			$dt_max = CarbonImmutable::parse($no_tests_after, TIMEZONE);
+		}
+
 		$users = User::query($nvp);
 
 		foreach($users as $user) {
 			$dt_start = $user->getDateTimeLastTest();
 
+			// If user is older than the maximum age allowed, skip it
+			if($max_age && $user->getAge() > $max_age) {
+				continue;
+			}
+
+			// If user has done a test after the specified
+			if($dt_start && $dt_max && $dt_start > $dt_max) {
+				continue;
+			}
+
 			$date_last_test = null;
 			if($dt_start) {
 				$date_last_test = $dt_start->setTimezone(TIMEZONE)->format("d/m/Y");

+ 1 - 1
engine/html_helper.php

@@ -10,7 +10,7 @@ class HtmlHelper {
 		return ((string) $value === (string) $selected) ? "selected" : "";
 	}
 
-	public static function renderOptions(array $options, ?string $selected): void {
+	public static function renderOptions(array $options, ?string $selected = null): void {
 		foreach($options as $value => $display) {
 			?>
 			<option value="<?=$value?>" <?=self::selected($value, $selected)?>>

+ 11 - 0
views/modals/header.php

@@ -0,0 +1,11 @@
+<?php
+/**
+ * @var string $title
+ */
+?>
+<div class="modal-header">
+	<h5 class="modal-title"><strong><?=htmlspecialchars($title)?></strong></h5>
+	<button type="button" class="close" data-dismiss="modal" aria-label="Close">
+		<span aria-hidden="true">&times;</span>
+	</button>
+</div>

+ 43 - 0
views/modals/user_export.php

@@ -0,0 +1,43 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+$level_options = [
+	User::LEVEL_REGISTERED => __("Registered"),
+	User::LEVEL_UNVERIFIED => __("Pending Verification"),
+	User::LEVEL_TESTER => __("Testers"),
+];
+?>
+<div class="modal fade" role="dialog" tabindex="-1" data-backdrop="static" id="user-export-modal">
+	<div class="modal-dialog modal-lg">
+		<form class="modal-content" method="get" action="/account/users/export/email">
+			<?php
+			View::include("modals/header", ["title" => __("Export Users")]);
+			?>
+			<div class="modal-body">
+				<div class="form-group">
+					<label for="export-users-level"><?=htmlspecialchars(__("User Level"))?></label>
+					<select class="form-control" name="level" id="export-users-level">
+						<?php
+						HtmlHelper::renderOptions($level_options);
+						?>
+					</select>
+				</div>
+				<div class="form-group">
+					<label for="export-users-max-age"><?=htmlspecialchars(__("Maximum Age"))?></label>
+					<input class="form-control" type="number" name="max_age" id="export-users-max-age" placeholder="<?=htmlspecialchars(__("Type max age"))?>" />
+				</div>
+				<div class="form-group">
+					<label for="export-users-no-tests-after"><?=htmlspecialchars(__("No Test After"))?></label>
+					<input class="form-control" type="date" name="no_tests_after" id="export-users-no-tests-after" placeholder="<?=htmlspecialchars(__("Enter date"))?>" />
+				</div>
+				
+			</div>
+			<div class="modal-footer">
+				<button type="button" class="btn btn-secondary" data-dismiss="modal">
+					<?=htmlspecialchars(__("Close"))?>
+				</button>
+				<button type="submit" class="btn btn-success">
+					<?=htmlspecialchars(__("Export"))?>
+				</button>
+			</div>
+		</form>
+	</div>
+</div>

+ 4 - 8
views/users.php

@@ -31,14 +31,10 @@ $filter_show = $filter_count > 0 ? "show" : "";
 				if(Core::$user->isAdmin()) {
 					?>
 					<div class="col-auto mr-3">
-						<div class="dropdown">
-							<button class="btn btn-outline-primary dropdown-toggle" type="button" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Actions</button>
-							<div class="dropdown-menu" aria-labelledby="actions-button">
-								<a class="dropdown-item" href="/account/users/export/email?level=<?=User::LEVEL_REGISTERED?>">Export Emails (Registered)</a>
-								<a class="dropdown-item" href="/account/users/export/email?level=<?=User::LEVEL_UNVERIFIED?>">Export Emails (Pending Verification)</a>
-								<a class="dropdown-item" href="/account/users/export/email?level=<?=User::LEVEL_TESTER?>">Export Emails (Tester)</a>
-							</div>
-						</div>
+						<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#user-export-modal">
+							<i class="fa fa-fw fa-file-export"></i>
+							<?=htmlspecialchars(__("Export"))?>
+						</button>
 					</div>
 					<?php
 				}