*/ declare(strict_types = 1); /** * Represents a measurement type. */ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable { // Main types case length; case height; case width; case weight; case diameter; case wall; case die_axis; case number_of_copies; // copies, specimen case number_of_parts; // Sub-types case length_socle; case height_socle; case width_socle; case length_sheet_size; case height_sheet_size; case width_sheet_size; case length_image_size; case height_image_size; case width_image_size; case length_frame; case height_frame; case width_frame; /** * Returns a value of this type based on a string. * * @param string $input Input to get a value from. * * @return MDMeasurementType */ public static function fromString(string $input):MDMeasurementType { return match($input) { 'length' => self::length, 'height' => self::height, 'width' => self::width, 'number_of_copies' => self::number_of_copies, 'weight' => self::weight, 'diameter' => self::diameter, 'wall' => self::wall, '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, 'length_sheet_size' => self::length_sheet_size, 'height_sheet_size' => self::height_sheet_size, 'width_sheet_size' => self::width_sheet_size, 'length_image_size' => self::length_image_size, 'height_image_size' => self::height_image_size, 'width_image_size' => self::width_image_size, 'length_frame' => self::length_frame, 'height_frame' => self::height_frame, 'width_frame' => self::width_frame, default => throw new MDpageParameterNotFromListException("Unknown measurement type"), }; } /** * Returns a value of this type based on an integer. * * @param integer $input Input to get a value from. * * @return MDMeasurementType */ public static function fromInt(int $input):MDMeasurementType { return match($input) { 1 => self::length, 2 => self::height, 3 => self::width, 4 => self::number_of_copies, 5 => self::weight, 6 => self::diameter, 7 => self::wall, 8 => self::number_of_parts, 9 => self::die_axis, 10 => self::length_socle, 11 => self::height_socle, 12 => self::width_socle, 13 => self::length_sheet_size, 14 => self::height_sheet_size, 15 => self::width_sheet_size, 16 => self::length_image_size, 17 => self::height_image_size, 18 => self::width_image_size, 19 => self::length_frame, 20 => self::height_frame, 21 => self::width_frame, default => throw new MDpageParameterNotFromListException("Unknown measurement type"), }; } /** * */ /** * Lists all available names. * * @return array */ public static function caseNames():array { $output = []; $cases = self::cases(); foreach ($cases as $case) { $output[] = $case->name; } return $output; } /** * Returns the highest level measurement type relative to the provided one. * * @return MDMeasurementType */ 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, self::length_sheet_size => self::length, self::height_sheet_size => self::height, self::width_sheet_size => self::width, self::length_image_size => self::length, self::height_image_size => self::height, self::width_image_size => self::width, self::length_frame => self::length, self::height_frame => self::height, self::width_frame => self::width, # default => throw new MDpageParameterNotFromListException("Unknown measurement type"), }; } /** * Returns an integer representation of the collective (for storage in DB). * * @return integer */ public function toInt():int { return match($this) { self::length => 1, self::height => 2, self::width => 3, self::number_of_copies => 4, self::weight => 5, self::diameter => 6, self::wall => 7, self::number_of_parts => 8, self::die_axis => 9, self::length_socle => 10, self::height_socle => 11, self::width_socle => 12, self::length_sheet_size => 13, self::height_sheet_size => 14, self::width_sheet_size => 15, self::length_image_size => 16, self::height_image_size => 17, self::width_image_size => 18, self::length_frame => 19, self::height_frame => 20, self::width_frame => 21, # 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 */ 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 */ 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(). * * @return string */ public function jsonSerialize():string { return $this->name; } }