|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
-
- namespace domain\Config\Unit;
-
- use domain\_\AbstractSolver;
-
- class UnitSolver extends AbstractSolver
- {
- protected UnitDefinition $unitDefinition;
-
- public function loadDependencies(): void
- {
- $this->unitDefinition = $this->loadService(UnitDefinition::class);
- }
-
- public function getUnit(string $idUnit): ?array
- {
- $unitsArray = $this->unitDefinition->getUnits();
- if(isset($unitsArray[$idUnit])) {
- return $unitsArray[$idUnit];
- }
-
- return null;
- }
-
- // getRefUnit
- public function getUnitReference(string $idUnit): string
- {
- $unit = $this->getUnit($idUnit);
-
- if ($unit && isset($unit['ref_unit'])) {
- return $unit['ref_unit'];
- }
-
- return $idUnit;
- }
-
- public function getUnitCoefficient(string $idUnit): int
- {
- $unit = $this->getUnit($idUnit);
-
- if($unit) {
- return $unit['coefficient'];
- }
-
- return 1;
- }
-
- /**
- * Retourne le libellé d'une unité.
- */
- public function strUnit(string $idUnit, $format = UnitDefinition::WORDING_SHORT, bool $unitReference = false): string
- {
- if ($unitReference) {
- $idUnit = $this->getUnitReference($idUnit);
- }
-
- $unit = $this->getUnit($idUnit);
- if ($unit && isset($unit[$format])) {
- return $unit[$format];
- }
-
- return '';
- }
- }
|