chart_generator.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. <?php
  2. /**
  3. * Class ChartGenerator
  4. */
  5. class ChartGenerator {
  6. public const COLOUR_GREEN = "#4CAF50";
  7. public const COLOUR_RED = "#F44336";
  8. public const COLOUR_YELLOW = "#FFEB3B";
  9. public const COLOUR_LIGHT_GREY = "#CCCCCC";
  10. public const COLOUR_LIGHT_RED = "#FFAB91";
  11. public const COLOUR_ORANGE = "#FBC02D";
  12. public const COLOUR_BLUE = "#2196F3";
  13. public const COLOUR_MAGENTA = "#E91E63";
  14. public const COLOUR_DARK_BLUE = "#3F51B5";
  15. public const COLOUR_PURPLE = "#9C27B0";
  16. public const COLOUR_GREY = "#9E9E9E";
  17. public const COLOUR_CYAN = "#00BCD4";
  18. /** @var object $totalData */
  19. private $totalData;
  20. /** @var array $periodicData */
  21. private $periodicData;
  22. /** @var string $dateRangeLabel */
  23. private $dateRangeLabel;
  24. /** @var string $resolutionName */
  25. private $resolutionName;
  26. /** @var string[] $xDataLabels */
  27. private $xDataLabels;
  28. /** @var string[] $periodKeys */
  29. private $periodKeys;
  30. /** @var string[] $periodLabels */
  31. private $periodLabels;
  32. /** @var array $regionData */
  33. private $regionData;
  34. /** @var array $areaManagerData */
  35. private $areaManagerData;
  36. /** @var array */
  37. private $brandData;
  38. /** @var Template $template */
  39. private $template;
  40. public static function getVenueTypePassFailChart(array $venue_type_data): Chart {
  41. $chart = new Chart();
  42. $chart->addXAxis([
  43. "type" => "category",
  44. "stacked" => true,
  45. ]);
  46. $chart->addYAxis([
  47. "id" => "y-axis-1",
  48. "tick_config" => ["min" => 0, "max" => 100],
  49. "stacked" => true,
  50. ]);
  51. $get_rates = static function(string $column) use ($venue_type_data) {
  52. return array_values(array_map(static function($d) use ($column) {
  53. if($d["testCount"] === 0) return 0;
  54. return round(($d[$column] / $d["testCount"]) * 100);
  55. }, $venue_type_data));
  56. };
  57. $pass_rates = $get_rates("passCount");
  58. $fail_rates = $get_rates("failCount");
  59. $chart->setType("bar");
  60. $chart->setTitle("Pass / Fail by Venue Type");
  61. $chart->setLabels(array_keys($venue_type_data));
  62. $chart->addDataset("Pass Rate (%)", $pass_rates, ["background_colours" => self::COLOUR_GREEN]);
  63. $chart->addDataset("Fail Rate (%)", $fail_rates, ["background_colours" => self::COLOUR_RED]);
  64. $chart->setDatalabelSuffixes("%", "%");
  65. return $chart;
  66. }
  67. public function getVenueTypeChallengeStageStackedBarChart(array $venue_type_data): ?Chart {
  68. $field = $this->template->getChallengeStageField();
  69. if(!$field) {
  70. return null;
  71. }
  72. $x_labels = $field->displayStrings;
  73. array_shift($x_labels); // Remove placeholder string
  74. $chart = new Chart();
  75. $chart->addXAxis([
  76. "type" => "category",
  77. "stacked" => true,
  78. ]);
  79. $chart->addYAxis([
  80. "id" => "y-axis-1",
  81. "tick_config" => ["min" => 0, "max" => 100],
  82. "stacked" => true,
  83. ]);
  84. $get_rates = static function(string $stage_index) use ($venue_type_data) {
  85. return array_values(array_map(static function($d) use ($stage_index) {
  86. $total_count = array_sum($d["stageCounts"]);
  87. if($total_count === 0) return 0;
  88. return round(($d["stageCounts"][$stage_index] / $total_count) * 100, 1);
  89. }, $venue_type_data));
  90. };
  91. $bg_colours = [
  92. self::COLOUR_GREEN,
  93. self::COLOUR_YELLOW,
  94. self::COLOUR_ORANGE,
  95. self::COLOUR_LIGHT_RED,
  96. self::COLOUR_RED,
  97. ];
  98. $chart->setType("bar");
  99. $chart->setTitle("Stages by Venue Type");
  100. $chart->setLabels(array_keys($venue_type_data));
  101. foreach($x_labels as $stage_index => $label) {
  102. $chart->addDataset("$label (%)", $get_rates($stage_index), ["background_colours" => $bg_colours[$stage_index]]);
  103. }
  104. $suffixes = array_fill(0, count($x_labels), "%");
  105. $chart->setDatalabelSuffixes(...$suffixes);
  106. return $chart;
  107. }
  108. public function getVenueTypeChallengeStagePieCharts(array $venue_type_data): array {
  109. $field = $this->template->getChallengeStageField();
  110. if(!$field) {
  111. return [];
  112. }
  113. $x_labels = $field->displayStrings;
  114. array_shift($x_labels); // Remove placeholder string
  115. $charts = [];
  116. foreach($venue_type_data as $venue_type => $data) {
  117. $values = $data["stageCounts"];
  118. $chart = new Chart();
  119. $chart->setType("pie");
  120. $chart->setTitle("Tests by Stage - $venue_type ({$this->dateRangeLabel})");
  121. $chart->setLabels($x_labels);
  122. $chart->addDataset("Counts", $values, [
  123. "background_colours" => [
  124. self::COLOUR_GREEN,
  125. self::COLOUR_YELLOW,
  126. self::COLOUR_ORANGE,
  127. self::COLOUR_LIGHT_RED,
  128. self::COLOUR_RED,
  129. ],
  130. "datalabels" => Chart::DATALABELS_BOX,
  131. ]);
  132. $charts[] = $chart;
  133. }
  134. return $charts;
  135. }
  136. public function __construct(object $total_data, array $periodic_data) {
  137. $this->totalData = $total_data;
  138. $this->periodicData = $periodic_data;
  139. $this->xDataLabels = array_values(array_map(static function($d) {
  140. return $d->label;
  141. }, $this->periodicData));
  142. }
  143. public function setDateRangeLabel(string $label): void {
  144. $this->dateRangeLabel = $label;
  145. }
  146. public function setResolutionName(string $name): void {
  147. $this->resolutionName = $name;
  148. }
  149. public function setPeriodKeysAndLabels(array $keys, array $labels): void {
  150. $this->periodKeys = $keys;
  151. $this->periodLabels = $labels;
  152. }
  153. public function setRegionData(array $data): void {
  154. ksort($data, SORT_NATURAL);
  155. $this->regionData = $data;
  156. }
  157. public function setAreaManagerData(array $data): void {
  158. ksort($data, SORT_NATURAL);
  159. $this->areaManagerData = $data;
  160. }
  161. public function setBrandData(array $data): void {
  162. $this->brandData = $data;
  163. }
  164. // Charts
  165. public function getTestsByStageChart(array $labels): Chart {
  166. $chart = new Chart;
  167. $chart->setType("doughnut");
  168. $chart->setTitle("Tests by Stage ({$this->dateRangeLabel})");
  169. $chart->setLabels($labels);
  170. $chart->addDataset("Tests", [
  171. $this->totalData->stage1Count,
  172. $this->totalData->stage2Count,
  173. $this->totalData->stage3Count,
  174. $this->totalData->stage4Count,
  175. $this->totalData->stage5Count,
  176. ], [
  177. "background_colours" => [
  178. self::COLOUR_GREEN,
  179. self::COLOUR_YELLOW,
  180. self::COLOUR_ORANGE,
  181. self::COLOUR_LIGHT_RED,
  182. self::COLOUR_RED,
  183. ],
  184. "datalabels" => Chart::DATALABELS_BOX,
  185. ]);
  186. $chart->setPrintSuffixes("");
  187. $chart->print = true;
  188. $chart->printPercentages = true;
  189. $chart->printTotalColumn = true;
  190. $chart->setPrintLabels(["Stage 1", "Stage 2", "Stage 3", "Stage 4", "Stage 5"]);
  191. return $chart;
  192. }
  193. public function getChallengerGenderChart(): Chart {
  194. $chart = new Chart;
  195. $chart->setType("pie");
  196. $chart->setTitle("Staff Gender ({$this->dateRangeLabel})");
  197. $chart->setLabels(["Male", "Female", "Unspecified"]);
  198. $chart->addDataset("Counts", [
  199. $this->totalData->maleChallengerCount,
  200. $this->totalData->femaleChallengerCount,
  201. $this->totalData->unspecifiedChallengerCount,
  202. ], [
  203. "background_colours" => [
  204. self::COLOUR_BLUE,
  205. self::COLOUR_MAGENTA,
  206. self::COLOUR_GREY,
  207. ],
  208. "datalabels" => Chart::DATALABELS_BOX,
  209. ]);
  210. return $chart;
  211. }
  212. public function getTesterGenderChart(): Chart {
  213. $chart = new Chart;
  214. $chart->setType("pie");
  215. $chart->setTitle("Tester Gender ({$this->dateRangeLabel})");
  216. $chart->setLabels(["Male", "Female"]);
  217. $chart->addDataset("Counts", [
  218. $this->totalData->maleTesterCount,
  219. $this->totalData->femaleTesterCount,
  220. ], [
  221. "background_colours" => [
  222. self::COLOUR_BLUE,
  223. self::COLOUR_MAGENTA,
  224. ],
  225. "datalabels" => Chart::DATALABELS_BOX,
  226. ]);
  227. return $chart;
  228. }
  229. public function getPassFailCountChart(): Chart {
  230. $data = $this->totalData;
  231. $dataset = [$data->passCount, $data->failCount];
  232. $labels = ["Pass", "Fail"];
  233. $colours = [self::COLOUR_GREEN, self::COLOUR_RED];
  234. if($data->voidCount > 0) {
  235. $dataset[] = $data->voidCount;
  236. $labels[] = "Void";
  237. $colours[] = self::COLOUR_GREY;
  238. }
  239. $chart = new Chart;
  240. $chart->setType("pie");
  241. $chart->setTitle("Pass / Fail ({$this->dateRangeLabel})");
  242. $chart->setLabels($labels);
  243. $chart->addDataset("Counts", $dataset, [
  244. "background_colours" => $colours,
  245. "datalabels" => Chart::DATALABELS_BOX,
  246. ]);
  247. return $chart;
  248. }
  249. public function getPeriodicPassFailRateChart(): Chart {
  250. $chart = new Chart;
  251. $chart->addXAxis([
  252. "type" => "category",
  253. "stacked" => true,
  254. ]);
  255. $chart->addYAxis([
  256. "id" => "y-axis-1",
  257. "tick_config" => ["min" => 0, "max" => 100],
  258. "stacked" => true,
  259. ]);
  260. $chart->setType("bar");
  261. $chart->setTitle("Pass / Fail by {$this->resolutionName}");
  262. $chart->setLabels($this->xDataLabels);
  263. $chart->addDataset("Pass Rate (%)", $this->getPeriodicPassRates(), [
  264. "background_colours" => self::COLOUR_GREEN
  265. ]);
  266. $chart->addDataset("Fail Rate (%)", $this->getPeriodicFailRates(), [
  267. "background_colours" => self::COLOUR_RED
  268. ]);
  269. $chart->setDatalabelSuffixes("%", "%");
  270. return $chart;
  271. }
  272. public function getPeriodicDoorSensorAlertPassRateChart(): Chart {
  273. return $this->getPeriodicPassRateChart(
  274. "Pass Rate by Door Sensor Alert",
  275. $this->getPeriodicPassRateByDoorSensorAlert(1),
  276. $this->getPeriodicPassRateByDoorSensorAlert(0),
  277. $this->getPeriodicPassRateByDoorSensorAlert(2)
  278. );
  279. }
  280. public function getPeriodicMachinePowerChart(): Chart {
  281. return $this->getPeriodicBooleanChart(
  282. "Machines Powered",
  283. $this->getMachinePowerRates()
  284. );
  285. }
  286. public function getPeriodicMachineSeatChart(): Chart {
  287. return $this->getPeriodicBooleanChart(
  288. "Machine Seating",
  289. $this->getMachineSeatRates()
  290. );
  291. }
  292. public function getPeriodicMachineTableChart(): Chart {
  293. return $this->getPeriodicBooleanChart(
  294. "Machine Table/Shelf",
  295. $this->getMachineTableRates()
  296. );
  297. }
  298. public function getPeriodicMachineAccessibleChart(): Chart {
  299. return $this->getPeriodicBooleanChart(
  300. "Machines Accessible",
  301. $this->getMachineAccessibleRates()
  302. );
  303. }
  304. public function getPeriodicEyeContactPassRateChart(): Chart {
  305. return $this->getPeriodicPassRateChart(
  306. "Pass Rate by Eye Contact",
  307. $this->getPeriodicPassRateByEyeContact(1),
  308. $this->getPeriodicPassRateByEyeContact(0),
  309. $this->getPeriodicPassRateByEyeContact(2)
  310. );
  311. }
  312. public function getPeriodicLineOfSightPassRateChart(): Chart {
  313. return $this->getPeriodicPassRateChart(
  314. "Pass Rate by Line of Sight",
  315. $this->getPeriodicPassRateByLineOfSight(1),
  316. $this->getPeriodicPassRateByLineOfSight(0),
  317. $this->getPeriodicPassRateByLineOfSight(2)
  318. );
  319. }
  320. public function getPeriodicBarPurchasePassRateChart(): Chart {
  321. return $this->getPeriodicPassRateChart(
  322. "Pass Rate by Bar Purchase",
  323. $this->getPeriodicPassRateByBarPurchase(1),
  324. $this->getPeriodicPassRateByBarPurchase(0),
  325. $this->getPeriodicPassRateByBarPurchase(2)
  326. );
  327. }
  328. public function getPeriodicAlcoholPassRateChart(): Chart {
  329. $pass_rates = [];
  330. $fail_rates = [];
  331. foreach($this->periodicData as $index => $data) {
  332. $pass_count = $data->alcoholCounts["pass"];
  333. $fail_count = $data->alcoholCounts["fail"];
  334. $test_count = $pass_count + $fail_count;
  335. if($test_count === 0) {
  336. $pass_rate = 0;
  337. $fail_rate = 0;
  338. }
  339. else {
  340. $pass_rate = round(($pass_count / $test_count) * 100);
  341. $fail_rate = 100 - $pass_rate;
  342. }
  343. $pass_rates[] = $pass_rate;
  344. $fail_rates[] = $fail_rate;
  345. }
  346. $chart = new Chart();
  347. $chart->addYAxis([
  348. "type" => "category",
  349. "stacked" => true,
  350. ]);
  351. $chart->addXAxis([
  352. "id" => "y-axis-1",
  353. "tick_config" => ["min" => 0, "max" => 100],
  354. "stacked" => true,
  355. ]);
  356. $chart->setType("horizontalBar");
  357. $chart->setTitle(__("Alcohol Pass Rate"));
  358. $chart->setLabels($this->xDataLabels);
  359. $chart->addDataset("Pass (%)", $pass_rates, ["background_colours" => self::COLOUR_GREEN]);
  360. $chart->addDataset("Fail (%)", $fail_rates, ["background_colours" => self::COLOUR_RED]);
  361. $chart->setDatalabelSuffixes("%", "%");
  362. return $chart;
  363. }
  364. public function getPeriodicBooleanPassRateChart(array $rates, string $title): Chart {
  365. $chart = new Chart();
  366. $chart->addXAxis([
  367. "type" => "category",
  368. "stacked" => true,
  369. ]);
  370. $chart->addYAxis([
  371. "id" => "y-axis-1",
  372. "tick_config" => ["min" => 0, "max" => 100],
  373. "stacked" => true,
  374. ]);
  375. $chart->setType("bar");
  376. $chart->setTitle($title);
  377. $chart->setLabels($this->xDataLabels);
  378. $chart->addDataset("Yes (%)", array_column($rates, "pass"), [
  379. "background_colours" => self::COLOUR_GREEN
  380. ]);
  381. $chart->addDataset("No (%)", array_column($rates, "fail"), [
  382. "background_colours" => self::COLOUR_RED
  383. ]);
  384. $chart->setDatalabelSuffixes("%", "%");
  385. return $chart;
  386. }
  387. public function getPeriodicEyeContactChart(): Chart {
  388. return $this->getPeriodicBooleanChart(
  389. "Eye Contact by {$this->resolutionName}",
  390. $this->getEyeContactRates()
  391. );
  392. }
  393. public function getPeriodicTotalsChart(): Chart {
  394. $test_counts = $this->getPeriodicTestCounts();
  395. $pass_rates = $this->getPeriodicPassRates();
  396. $pass_counts = $this->getPeriodicPassCounts();
  397. $fail_counts = $this->getPeriodicFailCounts();
  398. $chart = new Chart;
  399. $chart->setType("bar");
  400. $chart->setTitle("Totals by {$this->resolutionName}");
  401. $chart->setLabels($this->xDataLabels);
  402. $chart->addYAxis([
  403. "id" => "y-axis-1",
  404. "tick_config" => ["min" => 0, "max" => ceil(max($test_counts) / 10) * 10]
  405. ]);
  406. $chart->addYAxis([
  407. "position" => "right",
  408. "id" => "y-axis-2",
  409. "grid_lines" => false,
  410. "tick_config" => ["min" => 0, "max" => 100]
  411. ]);
  412. $chart->addDataset("Pass Rate (%)", $pass_rates, [
  413. "border_colours" => self::COLOUR_YELLOW,
  414. "background_colours" => "transparent",
  415. "type" => "line",
  416. "y_axis_id" => "y-axis-2",
  417. "datalabels" => [
  418. "display" => false
  419. ],
  420. "line_tension" => 0,
  421. ]);
  422. $chart->addDataset("Test Count", $test_counts, [
  423. "background_colours" => self::COLOUR_BLUE,
  424. "type" => "bar",
  425. "y_axis_id" => "y-axis-1",
  426. "datalabels" => [
  427. "display" => false
  428. ],
  429. ]);
  430. $chart->addDataset("Pass", $pass_counts, [
  431. "background_colours" => self::COLOUR_GREEN,
  432. "type" => "bar",
  433. "y_axis_id" => "y-axis-1",
  434. "datalabels" => [
  435. "display" => false
  436. ],
  437. ]);
  438. $chart->addDataset("Fail", $fail_counts, [
  439. "background_colours" => self::COLOUR_RED,
  440. "type" => "bar",
  441. "y_axis_id" => "y-axis-1",
  442. "datalabels" => [
  443. "display" => false
  444. ],
  445. ]);
  446. $chart->setDatalabelSuffixes("%", "", "", "");
  447. $chart->print = true;
  448. return $chart;
  449. }
  450. /**
  451. * @return Chart[]
  452. * @throws Exception
  453. */
  454. public function getPointOfChallengeCharts(string $title_format, array $labels = []): array {
  455. $charts = [];
  456. foreach($this->periodKeys as $index => $key) {
  457. $key_label = $this->periodLabels[$index];
  458. $period_data = $this->periodicData[$key];
  459. if($period_data->testCount === 0) continue;
  460. $chart = new Chart;
  461. $chart->setType("pie");
  462. $chart->setTitle(sprintf($title_format, $key_label));
  463. $chart->setLabels($labels);
  464. $chart->addDataset("Counts", [
  465. $period_data->stage1Count,
  466. $period_data->stage2Count,
  467. $period_data->stage3Count,
  468. $period_data->stage4Count,
  469. $period_data->stage5Count,
  470. ], [
  471. "background_colours" => [
  472. self::COLOUR_GREEN,
  473. self::COLOUR_YELLOW,
  474. self::COLOUR_ORANGE,
  475. self::COLOUR_LIGHT_RED,
  476. self::COLOUR_RED,
  477. ],
  478. "datalabels" => Chart::DATALABELS_BOX,
  479. ]);
  480. $charts[] = $chart;
  481. }
  482. return $charts;
  483. }
  484. public function getPeriodicTesterGenderChart(): Chart {
  485. $male_counts = $this->getPeriodicMaleTesterCount();
  486. $female_counts = $this->getPeriodicFemaleTesterCount();
  487. $counts = array_merge($male_counts, $female_counts);
  488. $chart = new Chart;
  489. $chart->addYAxis([
  490. "id" => "y-axis-1",
  491. "tick_config" => ["min" => 0, "max" => ceil(max($counts) / 10) * 10]
  492. ]);
  493. $chart->setType("bar");
  494. $chart->setTitle("Tester Gender by {$this->resolutionName}");
  495. $chart->setLabels($this->xDataLabels);
  496. $chart->addDataset("Male", $male_counts, [
  497. "background_colours" => self::COLOUR_BLUE
  498. ]);
  499. $chart->addDataset("Female", $female_counts, [
  500. "background_colours" => self::COLOUR_MAGENTA
  501. ]);
  502. return $chart;
  503. }
  504. public function getPeriodicTestCountChart(): Chart {
  505. $test_counts = $this->getPeriodicTestCounts();
  506. $chart = new Chart;
  507. $chart->addYAxis([
  508. "id" => "y-axis-1",
  509. "tick_config" => ["min" => 0, "max" => ceil(max($test_counts) / 10) * 10]
  510. ]);
  511. $chart->setType("bar");
  512. $chart->setTitle("Tests by {$this->resolutionName}");
  513. $chart->setLabels($this->xDataLabels);
  514. $chart->addDataset("Tests", $test_counts, [
  515. "background_colours" => self::COLOUR_BLUE
  516. ]);
  517. return $chart;
  518. }
  519. public function getGenderComparisonCharts(): array {
  520. $charts = [];
  521. $gender_keys = [
  522. "maleChallengeMale" => [
  523. "title" => "Male Challenge Male",
  524. "label" => "M Cha. M",
  525. ],
  526. "maleChallengeFemale" => [
  527. "title" => "Male Challenge Female",
  528. "label" => "M Cha. F",
  529. ],
  530. "femaleChallengeMale" => [
  531. "title" => "Female Challenge Male",
  532. "label" => "F Cha. M",
  533. ],
  534. "femaleChallengeFemale" => [
  535. "title" => "Female Challenge Female",
  536. "label" => "F Cha. F",
  537. ],
  538. "unknownChallenge" => [
  539. "title" => "Gender Not Specified",
  540. "label" => "Gender Not Specified",
  541. ],
  542. ];
  543. $gender_test_counts = [];
  544. foreach($gender_keys as $gk => $gv) {
  545. $gender_test_counts[] = array_sum(array_column($this->periodicData, "{$gk}Count"));
  546. }
  547. // Gender Comparison by Date Range
  548. $chart = new Chart;
  549. $chart->addYAxis([
  550. "id" => "y-axis-1",
  551. "tick_config" => ["min" => 0, "max" => ceil(max($gender_test_counts) / 10) * 10]
  552. ]);
  553. $chart->setType("bar");
  554. $chart->setTitle("Gender Comparison ({$this->dateRangeLabel})");
  555. $chart->setLabels(array_column($gender_keys, "label"));
  556. $chart->addDataset("Tests", $gender_test_counts, [
  557. "background_colours" => self::COLOUR_BLUE
  558. ]);
  559. $charts[] = $chart;
  560. // Gender Comparison by Resolution
  561. $mcm_counts = array_column($this->periodicData, "maleChallengeMaleCount");
  562. $mcf_counts = array_column($this->periodicData, "maleChallengeFemaleCount");
  563. $fcm_counts = array_column($this->periodicData, "femaleChallengeMaleCount");
  564. $fcf_counts = array_column($this->periodicData, "femaleChallengeFemaleCount");
  565. $ns_counts = array_column($this->periodicData, "unknownChallengeCount");
  566. $counts = array_merge($mcm_counts, $mcf_counts, $fcm_counts, $fcf_counts);
  567. $chart = new Chart;
  568. $chart->addYAxis([
  569. "id" => "y-axis-1",
  570. "tick_config" => ["min" => 0, "max" => ceil(max($counts) / 10) * 10]
  571. ]);
  572. $chart->setType("bar");
  573. $chart->setTitle("Gender Comparison by {$this->resolutionName}");
  574. $chart->setLabels($this->xDataLabels);
  575. $chart->addDataset("M Cha. M", $mcm_counts, ["background_colours" => self::COLOUR_BLUE]);
  576. $chart->addDataset("M Cha. F", $mcf_counts, ["background_colours" => self::COLOUR_DARK_BLUE]);
  577. $chart->addDataset("F Cha. M", $fcm_counts, ["background_colours" => self::COLOUR_PURPLE]);
  578. $chart->addDataset("F Cha. F", $fcf_counts, ["background_colours" => self::COLOUR_MAGENTA]);
  579. $chart->addDataset("Not Specified", $ns_counts, ["background_colours" => self::COLOUR_GREY]);
  580. $chart->print = true;
  581. $charts[] = $chart;
  582. // Gender Comparison Pass Rate by Resolution
  583. /** @noinspection PhpUnusedLocalVariableInspection */
  584. {
  585. $mcm_pass_counts = array_column($this->periodicData, "maleChallengeMalePassCount");
  586. $mcf_pass_counts = array_column($this->periodicData, "maleChallengeFemalePassCount");
  587. $fcm_pass_counts = array_column($this->periodicData, "femaleChallengeMalePassCount");
  588. $fcf_pass_counts = array_column($this->periodicData, "femaleChallengeFemalePassCount");
  589. $ns_pass_counts = array_column($this->periodicData, "unknownChallengePassCount");
  590. }
  591. /**
  592. * @var float $mcm_pass_rates
  593. * @var float $mcf_pass_rates
  594. * @var float $fcm_pass_rates
  595. * @var float $fcf_pass_rates
  596. * @var float $ns_pass_rates
  597. */
  598. foreach(["mcm", "mcf", "fcm", "fcf", "ns"] as $prefix) {
  599. $pass_rates = [];
  600. $pass_counts = ${$prefix . "_pass_counts"};
  601. $test_counts = ${$prefix . "_counts"};
  602. foreach($test_counts as $index => $test_count) {
  603. if($test_count === 0) {
  604. $pass_rates[] = 0;
  605. continue;
  606. }
  607. $pass_rates[] = number_format(($pass_counts[$index] * 100) / $test_count, 2);
  608. }
  609. ${$prefix . "_pass_rates"} = $pass_rates;
  610. }
  611. $chart = new Chart;
  612. $chart->addYAxis([
  613. "id" => "y-axis-1",
  614. "tick_config" => ["min" => 0, "max" => 100],
  615. ]);
  616. $chart->setType("bar");
  617. $chart->setTitle("Gender Comparison Pass Rate by {$this->resolutionName}");
  618. $chart->setLabels($this->xDataLabels);
  619. $chart->addDataset("M Cha. M", $mcm_pass_rates, ["background_colours" => self::COLOUR_BLUE, "datalabels" => ["display" => false], "line_tension" => 0]);
  620. $chart->addDataset("M Cha. F", $mcf_pass_rates, ["background_colours" => self::COLOUR_DARK_BLUE, "datalabels" => ["display" => false], "line_tension" => 0]);
  621. $chart->addDataset("F Cha. M", $fcm_pass_rates, ["background_colours" => self::COLOUR_PURPLE, "datalabels" => ["display" => false], "line_tension" => 0]);
  622. $chart->addDataset("F Cha. F", $fcf_pass_rates, ["background_colours" => self::COLOUR_MAGENTA, "datalabels" => ["display" => false], "line_tension" => 0]);
  623. $chart->addDataset("Not Specified", $ns_pass_rates, ["background_colours" => self::COLOUR_GREY, "datalabels" => ["display" => false], "line_tension" => 0]);
  624. $chart->print = true;
  625. $chart->setDatalabelSuffixes("%", "%", "%", "%", "%");
  626. $charts[] = $chart;
  627. // Gender Comparison Point of Challenge
  628. foreach($this->periodKeys as $index => $key) {
  629. $key_label = $this->periodLabels[$index];
  630. $period_data = $this->periodicData[$key];
  631. foreach($gender_keys as $prefix => $gv) {
  632. $title = $gv["label"];
  633. $test_count = $period_data->{$prefix . "Count"};
  634. $stage_data = $period_data->{$prefix . "Stages"};
  635. if($test_count === 0) continue;
  636. $chart = new Chart;
  637. $chart->setType("pie");
  638. $chart->setTitle("$key_label $title Point of Challenge");
  639. $chart->setLabels(["On Entry", "While Browsing", "During Play", "On Exit", "No Challenge"]);
  640. $chart->addDataset("Counts", $stage_data, [
  641. "background_colours" => [
  642. self::COLOUR_GREEN,
  643. self::COLOUR_YELLOW,
  644. self::COLOUR_ORANGE,
  645. self::COLOUR_LIGHT_RED,
  646. self::COLOUR_RED,
  647. ],
  648. "datalabels" => Chart::DATALABELS_BOX,
  649. ]);
  650. $charts[] = $chart;
  651. }
  652. }
  653. return $charts;
  654. }
  655. private function getDataPassRateChart(array $data, string $entity_name): Chart {
  656. $data_values = [];
  657. $test_counts = [];
  658. $pass_counts = [];
  659. $fail_counts = [];
  660. foreach($data as $datum) {
  661. $total_test_count = array_sum(array_column($datum, "testCount"));
  662. $total_pass_count = array_sum(array_column($datum, "passCount"));
  663. $test_counts[] = $total_test_count;
  664. $pass_counts[] = $total_pass_count;
  665. $fail_counts[] = $total_test_count - $total_pass_count;
  666. $data_values[] = ($total_test_count === 0) ? 0 : round(($total_pass_count * 100) / $total_test_count);
  667. }
  668. $chart = new Chart;
  669. $chart->addXAxis([
  670. "type" => "category",
  671. "scale_label_config" => [
  672. "display" => true,
  673. "labelString" => $entity_name,
  674. ]
  675. ]);
  676. $chart->addYAxis([
  677. "id" => "y-axis-1",
  678. "tick_config" => ["min" => 0, "max" => 100]
  679. ]);
  680. $chart->setType("bar");
  681. $chart->setTitle("{$entity_name} Pass Rate ({$this->dateRangeLabel})");
  682. $chart->setLabels(array_keys($data));
  683. $chart->addDataset("Pass %", $data_values , [
  684. "background_colours" => self::COLOUR_BLUE
  685. ]);
  686. $chart->addPrintDataset("Tests", $test_counts);
  687. $chart->addPrintDataset("Pass", $pass_counts);
  688. $chart->addPrintDataset("Fail", $fail_counts);
  689. $chart->setDatalabelSuffixes("%");
  690. $chart->print = true;
  691. $chart->printTotalColumn = true;
  692. return $chart;
  693. }
  694. public function getPeriodicDataPassRateChart(string $entity): Chart {
  695. switch($entity) {
  696. case "region":
  697. $data = $this->regionData;
  698. $entity_name = "Region";
  699. $entity_keys = $this->getRegionKeys();
  700. $x_labels = $this->getRegionXDataLabels();
  701. break;
  702. case "areaManager":
  703. $data = $this->areaManagerData;
  704. $entity_name = "Area Manager";
  705. $entity_keys = $this->getAreaManagerKeys();
  706. $x_labels = $this->getAreaManagerKeys();
  707. break;
  708. case "brand":
  709. $data = $this->brandData;
  710. $entity_name = "Brand";
  711. $entity_keys = $this->getBrandKeys();
  712. $x_labels = $this->getBrandKeys();
  713. break;
  714. default:
  715. throw new RuntimeException("Invalid entity passed to getPeriodicDataPassRateChart: $entity");
  716. }
  717. $chart = new Chart();
  718. $chart->addXAxis([
  719. "type" => "category",
  720. "scale_label_config" => [
  721. "display" => true,
  722. "labelString" => $entity_name,
  723. ]
  724. ]);
  725. $chart->addYAxis([
  726. "id" => "y-axis-1",
  727. "tick_config" => ["min" => 0, "max" => 100]
  728. ]);
  729. $chart->setType("bar");
  730. $chart->setTitle("{$entity_name} Pass Rate by {$this->resolutionName}");
  731. $chart->setLabels($x_labels);
  732. foreach($this->periodKeys as $index => $key) {
  733. $data_values = [];
  734. foreach($entity_keys as $entity_key) {
  735. $datum = $data[$entity_key][$key];
  736. $data_values[] = ($datum->testCount === 0) ? 0 : round(($datum->passCount * 100) / $datum->testCount);
  737. }
  738. $chart->addDataset($this->periodLabels[$index], $data_values, [
  739. "background_colours" => Chart::getColourByIndex($index),
  740. "datalabels" => [
  741. "display" => false
  742. ]
  743. ]);
  744. }
  745. $chart->setDatalabelSuffixes(...array_fill(0, count($this->periodKeys), "%"));
  746. $chart->print = true;
  747. return $chart;
  748. }
  749. public function hasRegionData(): bool {
  750. return $this->regionData !== null;
  751. }
  752. public function getRegionPassRateChart(): Chart {
  753. return $this->getDataPassRateChart($this->regionData, "Region");
  754. }
  755. public function getPeriodicRegionPassRateChart(): Chart {
  756. return $this->getPeriodicDataPassRateChart("region");
  757. }
  758. public function hasAreaManagerData(): bool {
  759. return $this->areaManagerData !== null;
  760. }
  761. public function getAreaManagerPassRateChart(): Chart {
  762. return $this->getDataPassRateChart($this->areaManagerData, "Area Manager");
  763. }
  764. public function getPeriodicAreaManagerPassRateChart(): Chart {
  765. return $this->getPeriodicDataPassRateChart("areaManager");
  766. }
  767. public function hasBrandData(): bool {
  768. return $this->brandData !== null;
  769. }
  770. public function getBrandPassRateChart(): Chart {
  771. return $this->getDataPassRateChart($this->brandData, "Brand");
  772. }
  773. public function getPeriodicBrandPassRateChart(): Chart {
  774. return $this->getPeriodicDataPassRateChart("brand");
  775. }
  776. public function getCleanlinessChart(): Chart {
  777. $chart = new Chart;
  778. $chart->setType("doughnut");
  779. $chart->setTitle("Tests by Cleanliness ({$this->dateRangeLabel})");
  780. $chart->setLabels(["Very dirty", "Dirty", "Adequate", "Clean", "Very Clean"]);
  781. $chart->addDataset("Tests", [
  782. $this->totalData->cleanlinessCounts[0],
  783. $this->totalData->cleanlinessCounts[1],
  784. $this->totalData->cleanlinessCounts[2],
  785. $this->totalData->cleanlinessCounts[3],
  786. $this->totalData->cleanlinessCounts[4],
  787. ], [
  788. "background_colours" => [
  789. self::COLOUR_RED,
  790. self::COLOUR_LIGHT_RED,
  791. self::COLOUR_ORANGE,
  792. self::COLOUR_YELLOW,
  793. self::COLOUR_GREEN,
  794. ],
  795. "datalabels" => Chart::DATALABELS_BOX,
  796. ]);
  797. $chart->setPrintSuffixes("");
  798. $chart->print = true;
  799. $chart->printTotalColumn = true;
  800. $chart->printPercentages = true;
  801. return $chart;
  802. }
  803. /**
  804. * @return Chart[]
  805. * @throws Exception
  806. */
  807. public function getPeriodicCleanlinessCharts(): array {
  808. $charts = [];
  809. foreach($this->periodKeys as $index => $key) {
  810. $key_label = $this->periodLabels[$index];
  811. $period_data = $this->periodicData[$key];
  812. if($period_data->testCount === 0) continue;
  813. $chart = new Chart;
  814. $chart->setType("pie");
  815. $chart->setTitle("$key_label Cleanliness");
  816. $chart->setLabels(["Very dirty", "Dirty", "Adequate", "Clean", "Very Clean"]);
  817. $chart->addDataset("Counts", [
  818. $period_data->cleanlinessCounts[0],
  819. $period_data->cleanlinessCounts[1],
  820. $period_data->cleanlinessCounts[2],
  821. $period_data->cleanlinessCounts[3],
  822. $period_data->cleanlinessCounts[4],
  823. ], [
  824. "background_colours" => [
  825. self::COLOUR_RED,
  826. self::COLOUR_LIGHT_RED,
  827. self::COLOUR_ORANGE,
  828. self::COLOUR_YELLOW,
  829. self::COLOUR_GREEN,
  830. ],
  831. "datalabels" => Chart::DATALABELS_BOX,
  832. ]);
  833. $charts[] = $chart;
  834. }
  835. return $charts;
  836. }
  837. public function getPeriodicStaffBadgeWornChart(): Chart {
  838. $staff_badge_worn_counts = array_column($this->periodicData, "staffBadgeWornCounts");
  839. $unknown_counts = array_column($staff_badge_worn_counts, 0);
  840. $no_counts = array_column($staff_badge_worn_counts, 1);
  841. $yes_counts = array_column($staff_badge_worn_counts, 2);
  842. $chart = new Chart;
  843. $chart->setType("bar");
  844. $chart->setTitle("Staff Badge Worn by {$this->resolutionName}");
  845. $chart->setLabels($this->xDataLabels);
  846. $chart->addDataset("No challenge", $unknown_counts, [
  847. "background_colours" => self::COLOUR_LIGHT_GREY
  848. ]);
  849. $chart->addDataset("No", $no_counts, [
  850. "background_colours" => self::COLOUR_RED
  851. ]);
  852. $chart->addDataset("Yes", $yes_counts, [
  853. "background_colours" => self::COLOUR_GREEN
  854. ]);
  855. return $chart;
  856. }
  857. public function getPeriodicStaffOfferedDrinkChart(): Chart {
  858. $counts = array_column($this->periodicData, "staffOfferedDrinkCounts");
  859. return $this->getPeriodicBooleanChart("Staff Offered Drink", $counts);
  860. }
  861. public function getPeriodicStaffOfferedPromotionChart(): Chart {
  862. $counts = array_column($this->periodicData, "staffOfferedPromotionCounts");
  863. return $this->getPeriodicBooleanChart("Staff Offered Promotion", $counts);
  864. }
  865. public function getPeriodicStaffOfferedHelpChart(): Chart {
  866. $counts = array_column($this->periodicData, "staffOfferedHelpCounts");
  867. return $this->getPeriodicBooleanChart("Staff Offered Help", $counts);
  868. }
  869. public function getPeriodicStaffBehaviourCharts(): array {
  870. $charts = [];
  871. foreach($this->periodKeys as $index => $key) {
  872. $key_label = $this->periodLabels[$index];
  873. $period_data = $this->periodicData[$key];
  874. if($period_data->testCount === 0) continue;
  875. $chart = new Chart;
  876. $chart->setType("pie");
  877. $chart->setTitle("$key_label Staff Behaviour");
  878. $chart->setLabels(["N/A", "Rude", "Slightly rude", "Neither rude or polite", "Polite", "Very polite"]);
  879. $chart->addDataset("Counts", [
  880. $period_data->staffBehaviourCounts[0],
  881. $period_data->staffBehaviourCounts[1],
  882. $period_data->staffBehaviourCounts[2],
  883. $period_data->staffBehaviourCounts[3],
  884. $period_data->staffBehaviourCounts[4],
  885. $period_data->staffBehaviourCounts[5],
  886. ], [
  887. "background_colours" => [
  888. self::COLOUR_LIGHT_GREY,
  889. self::COLOUR_RED,
  890. self::COLOUR_LIGHT_RED,
  891. self::COLOUR_ORANGE,
  892. self::COLOUR_YELLOW,
  893. self::COLOUR_GREEN,
  894. ],
  895. "datalabels" => Chart::DATALABELS_BOX,
  896. ]);
  897. $charts[] = $chart;
  898. }
  899. return $charts;
  900. }
  901. public function getPeriodicStaffUniformChart(): Chart {
  902. $counts = array_column($this->periodicData, "staffUniformCounts");
  903. return $this->getPeriodicBooleanChart("Staff Uniform", $counts);
  904. }
  905. // Private methods
  906. private function getPeriodicPassRates(): array {
  907. return array_values(array_map(static function($d) {
  908. if($d->testCount === 0) return 0;
  909. return round(($d->passCount / $d->testCount) * 100);
  910. }, $this->periodicData));
  911. }
  912. private function getPeriodicFailRates(): array {
  913. return array_values(array_map(static function($d) {
  914. if($d->testCount === 0) return 0;
  915. $pass_rate = round(($d->passCount / $d->testCount) * 100);
  916. return 100 - $pass_rate;
  917. }, $this->periodicData));
  918. }
  919. private function getPeriodicPassRate(string $prefix, int $index): array {
  920. $pass_field = $prefix . "PassCounts";
  921. $fail_field = $prefix . "FailCounts";
  922. return array_values(array_map(static function($data) use ($pass_field, $fail_field, $index) {
  923. if(!$data) return null;
  924. if(!isset($data->$pass_field)) return null;
  925. if(!isset($data->$fail_field)) return null;
  926. $test_count = $data->$pass_field[$index] + $data->$fail_field[$index];
  927. if($test_count === 0) {
  928. return null;
  929. }
  930. return round(($data->$pass_field[$index] / $test_count) * 100);
  931. }, $this->periodicData));
  932. }
  933. private function getPeriodicPassRateByDoorSensorAlert(int $index): array {
  934. return $this->getPeriodicPassRate("doorSensorAlert", $index);
  935. }
  936. private function getPeriodicPassRateByEyeContact(int $index): array {
  937. return $this->getPeriodicPassRate("eyeContact", $index);
  938. }
  939. private function getPeriodicPassRateByLineOfSight(int $index): array {
  940. return $this->getPeriodicPassRate("lineOfSight", $index);
  941. }
  942. private function getPeriodicPassRateByBarPurchase(int $index): array {
  943. return $this->getPeriodicPassRate("barPurchase", $index);
  944. }
  945. private function getMachinePowerRates(): array {
  946. return $this->getBooleanRates("machinePowerCounts");
  947. }
  948. private function getMachineSeatRates(): array {
  949. return $this->getBooleanRates("machineSeatCounts");
  950. }
  951. private function getMachineTableRates(): array {
  952. return $this->getBooleanRates("machineTableCounts");
  953. }
  954. private function getMachineAccessibleRates(): array {
  955. return $this->getBooleanRates("machineAccessibleCounts");
  956. }
  957. private function getBooleanRates(string $field): array {
  958. return array_values(array_map(static function($period) use ($field) {
  959. if($period->testCount === 0) {
  960. return [0, 0, 0];
  961. }
  962. $yes = round(($period->$field[0] / $period->testCount) * 100);
  963. $no = 100 - $yes;
  964. $na = 0;
  965. return [$yes, $no, $na];
  966. }, $this->periodicData));
  967. }
  968. private function getEyeContactRates(): array {
  969. return $this->getBooleanRates("eyeContactCounts");
  970. }
  971. private function getPeriodicTestCounts(): array {
  972. return array_column($this->periodicData, "testCount");
  973. }
  974. private function getPeriodicPassCounts(): array {
  975. return array_column($this->periodicData, "passCount");
  976. }
  977. private function getPeriodicFailCounts(): array {
  978. return array_column($this->periodicData, "failCount");
  979. }
  980. private function getPeriodicMaleTesterCount(): array {
  981. return array_values(array_map(static function($d) {
  982. return $d->maleTesterCount;
  983. }, $this->periodicData));
  984. }
  985. private function getPeriodicFemaleTesterCount(): array {
  986. return array_values(array_map(static function($d) {
  987. return $d->femaleTesterCount;
  988. }, $this->periodicData));
  989. }
  990. private function getRegionKeys(): array {
  991. if(!$this->regionData) return [];
  992. return array_keys($this->regionData);
  993. }
  994. private function getRegionXDataLabels(): array {
  995. return array_map(static function($key) {
  996. return "Region $key";
  997. }, $this->getRegionKeys());
  998. }
  999. private function getAreaManagerKeys(): array {
  1000. if(!$this->areaManagerData) return [];
  1001. return array_keys($this->areaManagerData);
  1002. }
  1003. private function getBrandKeys(): array {
  1004. if(!$this->brandData) return [];
  1005. return array_keys($this->brandData);
  1006. }
  1007. private function getAreaManagerXDataLabels(): array {
  1008. return $this->getAreaManagerKeys();
  1009. }
  1010. private function getPeriodicBooleanChart(string $title, array $values): Chart {
  1011. $no_counts = array_column($values, 0);
  1012. $yes_counts = array_column($values, 1);
  1013. $chart = new Chart;
  1014. $chart->setType("bar");
  1015. $chart->setTitle("{$title} by {$this->resolutionName}");
  1016. $chart->setLabels($this->xDataLabels);
  1017. $chart->addDataset("Yes", $yes_counts, [
  1018. "background_colours" => self::COLOUR_GREEN
  1019. ]);
  1020. $chart->addDataset("No", $no_counts, [
  1021. "background_colours" => self::COLOUR_RED
  1022. ]);
  1023. $chart->setDatalabelSuffixes("%", "%");
  1024. return $chart;
  1025. }
  1026. private function getPeriodicPassRateChart(string $title, array $yes_rates, array $no_rates, ?array $null_rates = null): Chart {
  1027. $chart = new Chart;
  1028. $chart->addYAxis([
  1029. "tick_config" => ["min" => 0, "max" => 100],
  1030. ]);
  1031. $chart->setType("bar");
  1032. $chart->setTitle($title);
  1033. $chart->setLabels($this->xDataLabels);
  1034. $chart->setDatalabelSuffixes("%", "%");
  1035. $chart->addDataset("Yes", $yes_rates, [
  1036. "background_colours" => self::COLOUR_GREEN,
  1037. "border_colours" => self::COLOUR_GREEN,
  1038. "line_tension" => 0,
  1039. "datalabels" => ["display" => false],
  1040. ]);
  1041. $chart->addDataset("No", $no_rates, [
  1042. "background_colours" => self::COLOUR_RED,
  1043. "border_colours" => self::COLOUR_RED,
  1044. "line_tension" => 0,
  1045. "datalabels" => ["display" => false],
  1046. ]);
  1047. if($null_rates !== null) {
  1048. $chart->addDataset("No challenge", $null_rates, [
  1049. "background_colours" => self::COLOUR_CYAN,
  1050. "border_colours" => self::COLOUR_CYAN,
  1051. "line_tension" => 0,
  1052. "datalabels" => ["display" => false],
  1053. ]);
  1054. $chart->setDatalabelSuffixes("%", "%", "%");
  1055. }
  1056. $chart->print = true;
  1057. return $chart;
  1058. }
  1059. /**
  1060. * @param Template $template
  1061. */
  1062. public function setTemplate(Template $template): void {
  1063. $this->template = $template;
  1064. }
  1065. }