Alan Lam 3 лет назад
Родитель
Сommit
efa55c7729

+ 2 - 0
controllers/register.php

@@ -37,6 +37,8 @@ try {
 		$user->gender = HTTP::value("gender", "trim");
 		$user->date_of_birth = HTTP::value("date_of_birth");
 		$user->phone = HTTP::value("phone", "trim");
+		$user->has_driving_licence = (int) HTTP::value("has_driving_licence", "int");
+		$user->has_car = (int) HTTP::value("has_car", "int");
 		$user->terms_accepted = HTTP::value("terms_accepted", "int") ? 1 : 0;
 		$user->newsletter_consent = HTTP::value("newsletter_content", "int") ? 1 : 0;
 		$user->dts_registered = gmdate("Y-m-d H:i:s");

+ 3 - 0
controllers/settings.php

@@ -30,6 +30,9 @@ if($submit) {
 		$user->email = http::value("email", "email");
 		$user->phone = http::value("phone", "trim");
 
+		$user->has_driving_licence = (int) http::value("has_driving_licence", "int");
+		$user->has_car = (int) http::value("has_car", "int");
+
 		$user->locale = http::value("locale", "trim");
 
 		$user->newsletter_consent = http::value("newsletter_content", "int");

+ 2 - 0
controllers/user_edit.php

@@ -51,6 +51,8 @@ if($submit) {
 		$user->gender = HTTP::value("gender", "trim");
 		$user->activated = HTTP::value("activated", "int");
 		$user->can_claim = HTTP::value("can_claim", "int");
+		$user->has_driving_licence = (int) HTTP::value("has_driving_licence", "int");
+		$user->has_car = (int) HTTP::value("has_car", "int");
 
 		$user_customer_link->delete();
 

+ 6 - 1
controllers/users.php

@@ -26,6 +26,9 @@ $level = http::value("level", "int");
 $customer_id = http::value("customer_id", "int");
 $location_id = http::value("location_id", "int");
 
+$has_driving_licence = HTTP::value("has_driving_licence", "int");
+$has_car = HTTP::value("has_car", "int");
+
 $nvp = [];
 if($id !== null) $nvp["id"] = $id;
 if(strlen($first_name) > 0) $nvp["first_name"] = ((new Constraint("CONTAINS"))->setValues($first_name));
@@ -33,6 +36,8 @@ if(strlen($last_name) > 0) $nvp["last_name"] = ((new Constraint("CONTAINS"))->se
 if(strlen($email) > 0) $nvp["email"] = $email;
 if($level !== null) $nvp["level"] = $level;
 if(!$archived) $nvp["archived"] = 0;
+if($has_driving_licence) $nvp["has_driving_licence"] = 1;
+if($has_car) $nvp["has_car"] = 1;
 
 $filter_count = null;
 if($nvp) {
@@ -74,7 +79,7 @@ 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::include("users", compact("users", "pagination_object", "filter_count", "id", "first_name", "last_name", "archived", "email", "level", "customer_id", "location_id", "has_driving_licence", "has_car", "sort", "sorts"));
 View::includeOnce("modal_page_jump");
 View::includeOnce("modals/user_export");
 View::includeOnce("footer");

+ 12 - 0
db/migrations/20230302225237_add_driving_fields_to_user_table.php

@@ -0,0 +1,12 @@
+<?php
+
+use Phinx\Migration\AbstractMigration;
+
+class AddDrivingFieldsToUserTable extends AbstractMigration {
+	public function change() {
+		$this->table("user")
+			->addColumn("has_driving_licence", "boolean", ["signed" => false, "default" => 0, "after" => "phone"])
+			->addColumn("has_car", "boolean", ["signed" => false, "default" => 0, "after" => "has_driving_licence"])
+			->update();
+	}
+}

+ 18 - 1
engine/user.php

@@ -24,6 +24,8 @@ use Carbon\CarbonImmutable;
  * @property string $reported_comment
  * @property bool $can_claim
  * @property string $phone
+ * @property bool $has_driving_licence
+ * @property bool $has_car
  * @property string $verify_token
  * @property string $reset_token
  * @property bool $terms_accepted
@@ -45,7 +47,22 @@ class User extends Model {
 
 	protected static $table = "user";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["email", "old_id", "referrer_id", "password", "activated", "archived", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "locale", "reported", "reported_comment", "can_claim", "phone", "verify_token", "reset_token", "terms_accepted", "newsletter_consent", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "dts_deleted", "verifier_id", "verifier_notes"];
+	protected static $fillable_fields = [
+		"email", "old_id", "referrer_id",
+		"password", "activated", "archived",
+		"level", "score",
+		"title", "first_name", "last_name", "gender", "date_of_birth",
+		"locale",
+		"reported", "reported_comment",
+		"can_claim",
+		"phone",
+		"has_driving_licence", "has_car",
+		"verify_token", "reset_token",
+		"terms_accepted", "newsletter_consent",
+		"preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email",
+		"dts_registered", "dts_last_seen", "dts_verified", "dts_deleted",
+		"verifier_id", "verifier_notes"
+	];
 
 	// Constants
 	const LEVEL_BANNED = 0;

+ 16 - 0
views/register.php

@@ -129,6 +129,22 @@ $newsletter_consent_checked = ($user->newsletter_consent) ? "checked" : "";
 						</select>
 					</div>
 				</div>
+
+				<div class="row mb-1">
+					<div class="col-sm offset-sm-4">
+						<label>
+							<input type="checkbox" value="1" name="has_driving_licence" /> <?=htmlspecialchars("I have a driving licence")?>
+						</label>
+					</div>
+				</div>
+				<div class="row mb-1">
+					<div class="col-sm offset-sm-4">
+						<label>
+							<input type="checkbox" value="1" name="has_car" /> <?=htmlspecialchars("I have access to a car at either postal codes")?>
+						</label>
+					</div>
+				</div>
+
 				<div class="row mb-1">
 					<div class="col-sm offset-sm-4">
 						<label>

+ 25 - 0
views/settings.php

@@ -73,6 +73,31 @@ if(is_null($user->locale)) $user->locale = LOCALE;
 					</div>
 				</div>
 
+				<div class="card card-body mb-3">
+					<h3><?=htmlspecialchars(__("Driving"))?></h3>
+
+					<div class="row mb-1">
+						<label class="col-sm-4 col-form-label" for="has-driving-licence"><?=htmlspecialchars(__("Driving Licence"))?></label>
+						<div class="col-sm">
+							<select class="form-control" name="has_driving_licence" id="has-driving-licence">
+								<?php
+								HtmlHelper::renderOptions(Form::BOOLEAN_OPTIONS, $user->has_driving_licence);
+								?>
+							</select>
+						</div>
+					</div>
+					<div class="row mb-1">
+						<label class="col-sm-4 col-form-label" for="has-car"><?=htmlspecialchars(__("Car Access"))?></label>
+						<div class="col-sm">
+							<select class="form-control" name="has_car" id="has-car">
+								<?php
+								HtmlHelper::renderOptions(Form::BOOLEAN_OPTIONS, $user->has_car);
+								?>
+							</select>
+						</div>
+					</div>
+				</div>
+
 				<div class="card card-body mb-3">
 					<h3><?=htmlspecialchars(__("Language"))?></h3>
 

+ 2 - 0
views/user.php

@@ -14,6 +14,8 @@ $details = [
 	"Date of Birth" => $user->date_of_birth,
 	"Gender" => $user->getGenderText(),
 	"Contact Number" => $user->phone,
+	"Driving Licence" => $user->has_driving_licence ? "Yes" : "No",
+	"Car Access" => $user->has_car ? "Yes" : "No",
 	"Score" => number_format($user->score),
 	"Registered" => $user->dts_registered,
 	"Last Seen" => $user->dts_last_seen,

+ 25 - 0
views/user_edit_form.php

@@ -190,6 +190,31 @@ var userId = <?=$user->id?>;
 						</select>
 					</div>
 				</div>
+
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="has-driving-licence">
+						<?=htmlspecialchars(__("Driving Licence"))?>
+					</label>
+					<div class="col-sm">
+						<select class="form-control" name="has_driving_licence" id="has-driving-licence">
+							<?php
+							HtmlHelper::renderOptions(Form::BOOLEAN_OPTIONS, $user->has_driving_licence);
+							?>
+						</select>
+					</div>
+				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="has-car">
+						<?=htmlspecialchars(__("Car Access"))?>
+					</label>
+					<div class="col-sm">
+						<select class="form-control" name="has_car" id="has-car">
+							<?php
+							HtmlHelper::renderOptions(Form::BOOLEAN_OPTIONS, $user->has_car);
+							?>
+						</select>
+					</div>
+				</div>
 			</div>
 			<div class="col-lg-6 mb-3">
 

+ 39 - 1
views/users.php

@@ -6,6 +6,8 @@
  * @var string $sort
  * @var string $first_name
  * @var string $last_name
+ * @var int $has_driving_licence
+ * @var int $has_car
  * @var int $archived
  * @var int $id
  * @var int $level
@@ -108,6 +110,29 @@ $filter_show = $filter_count > 0 ? "show" : "";
 								</select>
 							</div>
 						</div>
+
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="has-driving-licence">Require Driving Licence</label>
+							<div class="col-sm">
+								<select class="form-control" name="has_driving_licence" id="has-driving-licence">
+									<?php
+									HtmlHelper::renderOptions(Form::BOOLEAN_OPTIONS, $has_driving_licence);
+									?>
+								</select>
+							</div>
+						</div>
+
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="has-car">Require Car Access</label>
+							<div class="col-sm">
+								<select class="form-control" name="has_car" id="has-car">
+									<?php
+									HtmlHelper::renderOptions(Form::BOOLEAN_OPTIONS, $has_car);
+									?>
+								</select>
+							</div>
+						</div>
+
 					</div>
 					<div class="col-lg">
 
@@ -187,8 +212,21 @@ $filter_show = $filter_count > 0 ? "show" : "";
 						<?=$user->id?>
 					</td>
 					<td class="align-middle">
-						<a href="/account/users/<?=$user->id?>"><?=htmlspecialchars($user->getDisplayName())?></a>
+						<a href="/account/users/<?=$user->id?>">
+							<?=htmlspecialchars($user->getDisplayName())?>
+						</a>
 						<?php
+						if($user->has_driving_licence) {
+							?>
+							<i class="fa fa-fw fa-id-card"></i>
+							<?php
+						}
+						if($user->has_car) {
+							?>
+							<i class="fa fa-fw fa-car"></i>
+							<?php
+						}
+
 						if($user->isArchived()) {
 							?>
 							<span class="badge badge-secondary">