Explorar o código

Add support for custom entity display names

Alan Lam %!s(int64=2) %!d(string=hai) anos
pai
achega
cb81b5bc18

+ 1 - 0
controllers/customer_edit.php

@@ -31,6 +31,7 @@ if($submit) {
 		$customer->email_locations_after_test = http::value("email_locations_after_test", "int");
 		$customer->year_cycle_month = http::value("year_cycle_month", "int");
 		$customer->show_in_map_overview = (int) http::value("show_in_map_overview", "int");
+		$customer->config_json = http::value("config_json", "trim");
 
 		if(empty($customer->name)) $form_exception->addError("Name is required.");
 

+ 1 - 0
controllers/reports.php

@@ -517,6 +517,7 @@ if($submit) {
 		$generator->setAreaManagerData($area_manager_data);
 		$generator->setOperationsManagerData($operations_manager_data);
 		$generator->setTemplate($template);
+		$generator->setCustomer($customer);
 
 		// Build charts hook
 		require $template->getProcessingFilePath("reports_build_charts.php");

+ 11 - 0
db/migrations/20240429224732_add_config_json_field_to_customer_table.php

@@ -0,0 +1,11 @@
+<?php
+
+use Phinx\Migration\AbstractMigration;
+
+class AddConfigJsonFieldToCustomerTable extends AbstractMigration {
+	public function change() {
+		$this->table("customer")
+			->addColumn("config_json", "text", ["null" => true])
+			->update();
+	}
+}

+ 14 - 8
engine/chart_generator.php

@@ -57,6 +57,8 @@ class ChartGenerator {
 	/** @var Template $template */
 	private $template;
 
+	private ?Customer $customer = null;
+
 	public static function getVenueTypePassFailChart(array $venue_type_data): Chart {
 		$chart = new Chart();
 		$chart->addXAxis([
@@ -957,25 +959,25 @@ class ChartGenerator {
 		switch($entity) {
 			case "region":
 				$data = $this->regionData;
-				$entity_name = "Region";
+				$entity_name = $this->customer->getRegionLabel(1);
 				$entity_keys = $this->getRegionKeys();
 				$x_labels = $this->getRegionXDataLabels();
 				break;
 			case "areaManager":
 				$data = $this->areaManagerData;
-				$entity_name = "Area Manager";
+				$entity_name = $this->customer->getAreaManagerLabel(1);
 				$entity_keys = $this->getAreaManagerKeys();
 				$x_labels = $this->getAreaManagerKeys();
 				break;
 			case "brand":
 				$data = $this->brandData;
-				$entity_name = "Brand";
+				$entity_name = $this->customer->getBrandLabel(1);
 				$entity_keys = $this->getBrandKeys();
 				$x_labels = $this->getBrandKeys();
 				break;
 			case "operationsManager":
 				$data = $this->operationsManagerData;
-				$entity_name = "Operations Manager";
+				$entity_name = $this->customer->getOperationsManagerLabel(1);
 				$entity_keys = $x_labels = $this->getOperationsManagerKeys();
 				break;
 			default:
@@ -1023,7 +1025,7 @@ class ChartGenerator {
 	}
 
 	public function getRegionPassRateChart(): Chart {
-		return $this->getDataPassRateChart($this->regionData, "Region");
+		return $this->getDataPassRateChart($this->regionData, $this->customer->getRegionLabel(1));
 	}
 
 	public function getPeriodicRegionPassRateChart(): Chart {
@@ -1035,7 +1037,7 @@ class ChartGenerator {
 	}
 
 	public function getAreaManagerPassRateChart(): Chart {
-		return $this->getDataPassRateChart($this->areaManagerData, "Area Manager");
+		return $this->getDataPassRateChart($this->areaManagerData, $this->customer->getAreaManagerLabel(1));
 	}
 
 	public function getPeriodicAreaManagerPassRateChart(): Chart {
@@ -1047,7 +1049,7 @@ class ChartGenerator {
 	}
 
 	public function getBrandPassRateChart(): Chart {
-		return $this->getDataPassRateChart($this->brandData, "Brand");
+		return $this->getDataPassRateChart($this->brandData, $this->customer->getBrandLabel(1));
 	}
 
 	public function getPeriodicBrandPassRateChart(): Chart {
@@ -1059,7 +1061,7 @@ class ChartGenerator {
 	}
 
 	public function getOperationsManagerPassRateChart(): Chart {
-		return $this->getDataPassRateChart($this->operationsManagerData, "Operations Manager");
+		return $this->getDataPassRateChart($this->operationsManagerData, $this->customer->getOperationsManagerLabel(1));
 	}
 
 	public function getPeriodicOperationsManagerPassRateChart(): Chart {
@@ -1427,4 +1429,8 @@ class ChartGenerator {
 		$this->template = $template;
 	}
 
+	public function setCustomer(?Customer $customer): void {
+		$this->customer = $customer;
+	}
+
 }

+ 42 - 0
engine/customer.php

@@ -21,6 +21,7 @@ use Carbon\CarbonImmutable;
  * @property string $area_manager_field_name
  * @property int $year_cycle_month
  * @property int $show_in_map_overview
+ * @property string $config_json
  */
 
 class Customer extends Model {
@@ -34,6 +35,7 @@ class Customer extends Model {
 		"internal_id_field_name", "region_field_name", "area_manager_field_name",
 		"year_cycle_month",
 		"show_in_map_overview",
+		"config_json",
 	];
 
 	// Static methods
@@ -256,4 +258,44 @@ class Customer extends Model {
 		return $this->getLocationFieldValues("operations_manager_name");
 	}
 
+	public function getConfig(): object {
+		return json_decode($this->config_json) ?: new stdClass();
+	}
+
+	public function getBrandLabel(int $count): string {
+		$default_labels = [__("Brand"), __("Brands")];
+		$index = ($count === 1) ? 0 : 1;
+		return $this->getConfig()->brandLabels[$index] ?? $default_labels[$index];
+	}
+
+	public function getRegionLabel(int $count): string {
+		$default_labels = [__("Region"), __("Regions")];
+		$index = ($count === 1) ? 0 : 1;
+		return $this->getConfig()->regionLabels[$index] ?? $default_labels[$index];
+	}
+
+	public function getAreaManagerLabel(int $count): string {
+		$default_labels = [__("Area Manager"), __("Area Managers")];
+		$index = ($count === 1) ? 0 : 1;
+		return $this->getConfig()->areaManagerLabels[$index] ?? $default_labels[$index];
+	}
+
+	public function getOperationsManagerLabel(int $count): string {
+		$default_labels = [__("Operations Manager"), __("Operations Managers")];
+		$index = ($count === 1) ? 0 : 1;
+		return $this->getConfig()->operationsManagerLabels[$index] ?? $default_labels[$index];
+	}
+
+	public function getGamingManagerLabel(int $count): string {
+		$default_labels = [__("Gaming Manager"), __("Gaming Managers")];
+		$index = ($count === 1) ? 0 : 1;
+		return $this->getConfig()->gamingManagerLabels[$index] ?? $default_labels[$index];
+	}
+
+	public function getSeniorGamingManagerLabel(int $count): string {
+		$default_labels = [__("Senior Gaming Manager"), __("Senior Gaming Managers")];
+		$index = ($count === 1) ? 0 : 1;
+		return $this->getConfig()->seniorGamingManagerLabels[$index] ?? $default_labels[$index];
+	}
+
 }

+ 10 - 1
views/customer_form.php

@@ -74,7 +74,7 @@
 		</div>
 
         <div class="row form-group">
-            <label  class="col-sm-4 col-form-label" for="year-cycle-month">
+            <label class="col-sm-4 col-form-label" for="year-cycle-month">
                 Year Cycle Month
             </label>
             <div class="col-sm">
@@ -93,6 +93,15 @@
             </div>
         </div>
 
+		<div class="row form-group">
+			<label class="col-sm-4 col-form-label" for="config-json">
+				Config JSON
+			</label>
+			<div class="col-sm">
+				<textarea class="form-control text-monospace" name="config_json" id="config-json" rows="8"><?=htmlspecialchars($customer->config_json)?></textarea>
+			</div>
+		</div>
+
 
 		<div class="row my-3">
 			<div class="col-sm offset-sm-4">

+ 10 - 10
views/reports.php

@@ -259,12 +259,12 @@ let projectData = <?=json_encode($project_table_data)?>;
 			<div class="col-md">
 
 				<?php
-				$render_location_entity_filter("brands[]", "brands", __("Brands"), $brands);
-				$render_location_entity_filter("operations_managers[]", "operation_managers", __("Operations Managers"), $operations_managers);
-				$render_location_entity_filter("regions[]", "regions", __("Regions"), $regions);
-				$render_location_entity_filter("area_managers[]", "area_managers", __("Area Managers"), $area_managers);
-				$render_location_entity_filter("senior_gaming_managers[]", "senior_gaming_managers", __("Senior Gaming Managers"), $senior_gaming_managers);
-				$render_location_entity_filter("gaming_managers[]", "gaming_managers", __("Gaming Managers"), $gaming_managers);
+				$render_location_entity_filter("brands[]", "brands", $customer->getBrandLabel(2), $brands);
+				$render_location_entity_filter("operations_managers[]", "operation_managers", $customer->getOperationsManagerLabel(2), $operations_managers);
+				$render_location_entity_filter("regions[]", "regions", $customer->getRegionLabel(2), $regions);
+				$render_location_entity_filter("area_managers[]", "area_managers", $customer->getAreaManagerLabel(2), $area_managers);
+				$render_location_entity_filter("senior_gaming_managers[]", "senior_gaming_managers", $customer->getSeniorGamingManagerLabel(2), $senior_gaming_managers);
+				$render_location_entity_filter("gaming_managers[]", "gaming_managers", $customer->getGamingManagerLabel(2), $gaming_managers);
 				?>
 
 				<div class="form-group">
@@ -514,19 +514,19 @@ let projectData = <?=json_encode($project_table_data)?>;
 
 			$tables = [
 				(object) [
-					"name" => "Region",
+					"name" => $customer->getRegionLabel(1),
 					"data" => $region_data
 				],
 				(object) [
-					"name" => "Area Manager",
+					"name" => $customer->getAreaManagerLabel(1),
 					"data" => $area_manager_data
 				],
 				(object) [
-					"name" => "Operations Manager",
+					"name" => $customer->getOperationsManagerLabel(1),
 					"data" => $operations_manager_data
 				],
 				(object) [
-					"name" => "Brand",
+					"name" => $customer->getBrandLabel(1),
 					"data" => $brand_data
 				],
 			]