Quellcode durchsuchen

Add annual test count field for locations

Alan Lam vor 3 Jahren
Ursprung
Commit
1ffbb45424

+ 7 - 1
controllers/location_edit.php

@@ -1,4 +1,8 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+/**
+ * @var int $id
+ */
 
 
 $page_title = "Edit Location";
 $page_title = "Edit Location";
 
 
@@ -42,6 +46,8 @@ if($submit) {
 		$location->area_manager = http::value("area_manager", "trim");
 		$location->area_manager = http::value("area_manager", "trim");
 		$location->area_manager_email = http::value("area_manager_email", "email");
 		$location->area_manager_email = http::value("area_manager_email", "email");
 
 
+		$location->annual_test_count = Util::clamp(http::value("annual_test_count", "int") ?: 1, 1, 200);
+
 		$location->do_not_test = http::value("do_not_test", "int") ? 1 : 0;
 		$location->do_not_test = http::value("do_not_test", "int") ? 1 : 0;
 		$location->closed = http::value("closed", "int") ? 1 : 0;
 		$location->closed = http::value("closed", "int") ? 1 : 0;
 		$location->archived = http::value("archived", "int") ? 1 : 0;
 		$location->archived = http::value("archived", "int") ? 1 : 0;

+ 12 - 0
db/migrations/20231121122450_add_annual_test_count_field_to_location_table.php

@@ -0,0 +1,12 @@
+<?php
+
+use Phinx\Db\Adapter\MysqlAdapter;
+use Phinx\Migration\AbstractMigration;
+
+class AddAnnualTestCountFieldToLocationTable extends AbstractMigration {
+	public function change() {
+		$this->table("location")
+			->addColumn("annual_test_count", "integer", ["limit" => MysqlAdapter::INT_TINY, "signed" => false, "default" => 1, "after" => "operations_manager_name"])
+			->update();
+	}
+}

+ 2 - 1
engine/location.php

@@ -26,6 +26,7 @@
  * @property string $area_manager_name
  * @property string $area_manager_name
  * @property string $area_manager_email
  * @property string $area_manager_email
  * @property string $operations_manager_name
  * @property string $operations_manager_name
+ * @property int $annual_test_count
  * @property bool $do_not_test
  * @property bool $do_not_test
  * @property bool $closed
  * @property bool $closed
  * @property bool $archived
  * @property bool $archived
@@ -38,7 +39,7 @@ class Location extends Model {
 
 
 	protected static $table = "location";
 	protected static $table = "location";
 	protected static $id_field = "id";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "notes", "shop_left", "shop_right", "brand", "region", "region_name", "internal_id", "area_manager", "area_manager_name", "area_manager_email", "operations_manager_name", "do_not_test", "closed", "archived", "latitude", "longitude", "dts_verified"];
+	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "notes", "shop_left", "shop_right", "brand", "region", "region_name", "internal_id", "area_manager", "area_manager_name", "area_manager_email", "operations_manager_name", "annual_test_count", "do_not_test", "closed", "archived", "latitude", "longitude", "dts_verified"];
 
 
 	// Object methods
 	// Object methods
 
 

+ 12 - 0
engine/util.php

@@ -388,4 +388,16 @@ class Util {
 		return $dts ? CarbonImmutable::parse($dts, "UTC") : null;
 		return $dts ? CarbonImmutable::parse($dts, "UTC") : null;
 	}
 	}
 
 
+	public static function clamp(int $value, int $min, int $max): int {
+		if($value < $min) {
+			return $min;
+		}
+
+		if($value > $max) {
+			return $max;
+		}
+
+		return $value;
+	}
+
 }
 }

+ 10 - 2
views/location_form.php

@@ -1,4 +1,4 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 
 
 /**
 /**
  * @var Location $location
  * @var Location $location
@@ -101,7 +101,9 @@ if($is_edit) {
 							<label class="col-sm-4 col-form-label" for="country">Country</label>
 							<label class="col-sm-4 col-form-label" for="country">Country</label>
 							<div class="col-sm">
 							<div class="col-sm">
 								<select class="form-control" name="country" id="country" required>
 								<select class="form-control" name="country" id="country" required>
-								<?=Form::renderCountryOptions($location->country)?>
+								<?php
+								Form::renderCountryOptions($location->country);
+								?>
 								</select>
 								</select>
 							</div>
 							</div>
 						</div>
 						</div>
@@ -220,6 +222,12 @@ if($is_edit) {
 								<input class="form-control" type="email" name="area_manager_email" id="area-manager-email" placeholder="Enter area manager email address" value="<?=htmlspecialchars($location->area_manager_email)?>" />
 								<input class="form-control" type="email" name="area_manager_email" id="area-manager-email" placeholder="Enter area manager email address" value="<?=htmlspecialchars($location->area_manager_email)?>" />
 							</div>
 							</div>
 						</div>
 						</div>
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="annual-test-count">Tests Per Year</label>
+							<div class="col-sm">
+								<input class="form-control" type="number" name="annual_test_count" id="annual-test-count" placeholder="Enter tests per year" value="<?=htmlspecialchars($location->annual_test_count)?>" min="1" max="200" />
+							</div>
+						</div>
 
 
 						<h3>Venue Types</h3>
 						<h3>Venue Types</h3>