Extend MDMeasurement with surrounding enums to cover measurements of

objects
This commit is contained in:
2024-11-21 21:46:24 +01:00
parent fa8bc6dac0
commit 7fc57353a8
9 changed files with 968 additions and 14 deletions

View File

@ -9,17 +9,25 @@ declare(strict_types = 1);
/**
* Represents a measurement type.
*/
enum MDMeasurementType implements JsonSerializable {
enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
// Main types
case length;
case height;
case width;
case number_of_pieces;
case weight;
case diameter;
case wall;
case number_of_pages;
case die_axis;
case number_of_copies; // copies, specimen
case number_of_parts;
// Sub-types
case length_socle;
case height_socle;
case width_socle;
/**
* Returns a value of this type based on a string.
@ -34,12 +42,15 @@ enum MDMeasurementType implements JsonSerializable {
'length' => self::length,
'height' => self::height,
'width' => self::width,
'number_of_pieces' => self::number_of_pieces,
'number_of_copies' => self::number_of_copies,
'weight' => self::weight,
'diameter' => self::diameter,
'wall' => self::wall,
'number_of_pages' => self::number_of_pages,
'number_of_parts' => self::number_of_parts,
'die_axis' => self::die_axis,
'length_socle' => self::length_socle,
'height_socle' => self::height_socle,
'width_socle' => self::width_socle,
default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
};
@ -58,12 +69,15 @@ enum MDMeasurementType implements JsonSerializable {
1 => self::length,
2 => self::height,
3 => self::width,
4 => self::number_of_pieces,
4 => self::number_of_copies,
5 => self::weight,
6 => self::diameter,
7 => self::wall,
8 => self::number_of_pages,
8 => self::number_of_parts,
9 => self::die_axis,
10 => self::length_socle,
11 => self::height_socle,
12 => self::width_socle,
default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
};
@ -92,15 +106,26 @@ enum MDMeasurementType implements JsonSerializable {
}
/**
* Returns the human-readable name of the measurement type.
* Returns the highest level measurement type relative to the provided one.
*
* @return string
* @return MDMeasurementType
*/
public function getName():string {
public function getHighestSuperordinate():MDMeasurementType {
return match($this) {
self::length => self::length,
self::height => self::height,
self::width => self::width,
self::number_of_copies => self::number_of_copies,
self::weight => self::weight,
self::diameter => self::diameter,
self::wall => self::wall,
self::number_of_parts => self::number_of_parts,
self::die_axis => self::die_axis,
self::length_socle => self::length,
self::height_socle => self::height,
self::width_socle => self::width,
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
default => throw new MDpageParameterNotFromListException("To be implemented"),
};
}
@ -116,17 +141,79 @@ enum MDMeasurementType implements JsonSerializable {
self::length => 1,
self::height => 2,
self::width => 3,
self::number_of_pieces => 4,
self::number_of_copies => 4,
self::weight => 5,
self::diameter => 6,
self::wall => 7,
self::number_of_pages => 8,
self::number_of_parts => 8,
self::die_axis => 9,
self::length_socle => 10,
self::height_socle => 11,
self::width_socle => 12,
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
};
}
/**
* Returns suitable measurement type.
*
* @return class-string
*/
public function getMeasurementUnit():string {
return match($this->getHighestSuperordinate()) {
self::length,
self::height,
self::width,
self::wall,
self::diameter => MDLengthUnit::Class,
self::number_of_copies => MDCountCopiesUnit::Class,
self::weight => MDWeightUnit::Class,
self::number_of_parts => MDCountPartsUnit::Class,
self::die_axis => MDDieAxisUnit::Class,
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
};
}
/**
* 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(), "measurement_type_set", "measurement_type_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(), "measurement_type_set", "measurement_type_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("measurement_type_set", "measurement_type_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*