7c865b7271
Close #37
165 lines
4.0 KiB
PHP
165 lines
4.0 KiB
PHP
<?PHP
|
|
/**
|
|
* Represents a measurement type.
|
|
*
|
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
|
*/
|
|
declare(strict_types = 1);
|
|
|
|
/**
|
|
* Represents a measurement type.
|
|
*/
|
|
enum MDCountPartsUnit implements MDValueEnumInterface, JsonSerializable, MDMeasurementUnitInterface {
|
|
|
|
case parts;
|
|
case sheets;
|
|
case pages;
|
|
case double_pages;
|
|
case standalone_sheets;
|
|
case written_pages;
|
|
|
|
/**
|
|
* Returns a value of this type based on a string.
|
|
*
|
|
* @param string $input Input to get a value from.
|
|
*
|
|
* @return MDCountPartsUnit
|
|
*/
|
|
public static function fromString(string $input):MDCountPartsUnit {
|
|
|
|
return match($input) {
|
|
'parts' => self::parts,
|
|
'pages' => self::pages,
|
|
'sheets' => self::sheets,
|
|
'double_pages' => self::double_pages,
|
|
'standalone_sheets' => self::standalone_sheets,
|
|
'written_pages' => self::written_pages,
|
|
default => throw new MDpageParameterNotFromListException("Unknown parts counting unit"),
|
|
};
|
|
|
|
}
|
|
|
|
/**
|
|
* Returns a value of this type based on an integer.
|
|
*
|
|
* @param integer $input Input to get a value from.
|
|
*
|
|
* @return MDCountPartsUnit
|
|
*/
|
|
public static function fromInt(int $input):MDCountPartsUnit {
|
|
|
|
return match($input) {
|
|
1 => self::parts,
|
|
2 => self::pages,
|
|
3 => self::sheets,
|
|
4 => self::double_pages,
|
|
5 => self::standalone_sheets,
|
|
6 => self::written_pages,
|
|
default => throw new MDpageParameterNotFromListException("Unknown parts counting unit"),
|
|
};
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* Lists all available names.
|
|
*
|
|
* @return array<string>
|
|
*/
|
|
public static function caseNames():array {
|
|
|
|
$output = [];
|
|
|
|
$cases = self::cases();
|
|
foreach ($cases as $case) {
|
|
$output[] = $case->name;
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
/**
|
|
* Returns an integer representation of the collective (for storage in DB).
|
|
*
|
|
* @return integer
|
|
*/
|
|
public function toInt():int {
|
|
|
|
return match($this) {
|
|
self::parts => 1,
|
|
self::pages => 2,
|
|
self::sheets => 3,
|
|
self::double_pages => 4,
|
|
self::standalone_sheets => 5,
|
|
self::written_pages => 6,
|
|
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
|
};
|
|
|
|
}
|
|
|
|
/**
|
|
* Returns the measurement calculated down to the base unit.
|
|
*
|
|
* @param float $value Measurement value.
|
|
*
|
|
* @return float
|
|
*/
|
|
public function convertToBaseUnit(float $value):float {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
/**
|
|
* Gets an unsorted list of the entries in a translated version.
|
|
*
|
|
* @param MDTlLoader $tlLoader Translation loader.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public static function getUnsortedList(MDTlLoader $tlLoader):array {
|
|
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "units_count_parts_set", "units_count_parts_set");
|
|
|
|
}
|
|
|
|
/**
|
|
* Gets a sorted list of the entries in a translated version.
|
|
*
|
|
* @param MDTlLoader $tlLoader Translation loader.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public static function getSortedList(MDTlLoader $tlLoader):array {
|
|
return MDValueSet::getTlSortedList($tlLoader, self::caseNames(), "units_count_parts_set", "units_count_parts_set");
|
|
|
|
}
|
|
|
|
/**
|
|
* Returns the name of the current value in translation.
|
|
*
|
|
* @param MDTlLoader $tlLoader Translation loader.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getTledName(MDTlLoader $tlLoader):string {
|
|
|
|
return $tlLoader->tl("units_count_parts_set", "units_count_parts_set", $this->name);
|
|
|
|
}
|
|
|
|
/**
|
|
* Provides the option to serialize as a string during json_encode().
|
|
*
|
|
* @return string
|
|
*/
|
|
public function jsonSerialize():string {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
}
|