Add enums for marking type and weight unit

This commit is contained in:
2026-08-21 14:05:56 +02:00
parent ce3b4e436f
commit efecadb199
3 changed files with 424 additions and 5 deletions
+222
View File
@@ -0,0 +1,222 @@
<?PHP
declare(strict_types = 1);
/**
* Represents a marking position.
*/
enum MDMarkingPosition implements MDValueEnumInterface, JsonSerializable, MDMeasurementUnitInterface {
case front_front;
case left;
case top_left;
case top;
case top_right;
case right;
case bottom_right;
case bottom;
case bottom_left;
case center;
case rear_side;
case rear_left;
case rear_top_left;
case rear_top;
case rear_top_right;
case rear_right;
case rear_bottom_right;
case rear_bottom;
case rear_bottom_left;
case rear_center;
case underside;
case topside;
case edge;
case inside;
case other;
case mock_title;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDMarkingPosition
*/
public static function fromString(string $input):MDMarkingPosition {
return match($input) {
'front_front' => self::front_front,
'left' => self::left,
'top_left' => self::top_left,
'top' => self::top,
'top_right' => self::top_right,
'right' => self::right,
'bottom_right' => self::bottom_right,
'bottom' => self::bottom,
'bottom_left' => self::bottom_left,
'center' => self::center,
'rear_side' => self::rear_side,
'rear_left' => self::rear_left,
'rear_top_left' => self::rear_top_left,
'rear_top' => self::rear_top,
'rear_top_right' => self::rear_top_right,
'rear_right' => self::rear_right,
'rear_bottom_right' => self::rear_bottom_right,
'rear_bottom' => self::rear_bottom,
'rear_bottom_left' => self::rear_bottom_left,
'rear_center' => self::rear_center,
'underside' => self::underside,
'topside' => self::topside,
'edge' => self::edge,
'inside' => self::inside,
'other' => self::other,
'mock_title' => self::mock_title,
default => throw new MDpageParameterNotFromListException("Unknown marking type"),
};
}
/**
* Returns a value of this type based on an integer.
*
* @param integer $input Input to get a value from.
*
* @return MDMarkingPosition
*/
public static function fromInt(int $input):MDMarkingPosition {
return match($input) {
1 => self::front_front,
2 => self::left,
3 => self::top_left,
4 => self::top,
5 => self::top_right,
6 => self::right,
7 => self::bottom_right,
8 => self::bottom,
9 => self::bottom_left,
10 => self::center,
11 => self::rear_side,
12 => self::rear_left,
13 => self::rear_top_left,
14 => self::rear_top,
15 => self::rear_top_right,
16 => self::rear_right,
17 => self::rear_bottom_right,
18 => self::rear_bottom,
19 => self::rear_bottom_left,
20 => self::rear_center,
21 => self::underside,
22 => self::topside,
23 => self::edge,
24 => self::inside,
25 => self::other,
26 => self::mock_title,
default => throw new MDpageParameterNotFromListException("Unknown marking type"),
};
}
/**
* 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::front_front => 1,
self::left => 2,
self::top_left => 3,
self::top => 4,
self::top_right => 5,
self::right => 6,
self::bottom_right => 7,
self::bottom => 8,
self::bottom_left => 9,
self::center => 10,
self::rear_side => 11,
self::rear_left => 12,
self::rear_top_left => 13,
self::rear_top => 14,
self::rear_top_right => 15,
self::rear_right => 16,
self::rear_bottom_right => 17,
self::rear_bottom => 18,
self::rear_bottom_left => 19,
self::rear_center => 20,
self::underside => 21,
self::topside => 22,
self::edge => 23,
self::inside => 24,
self::other => 25,
self::mock_title => 26,
# 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(), "position_set", "position_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(), "position_set", "position_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("position_set", "position_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}
+202
View File
@@ -0,0 +1,202 @@
<?PHP
declare(strict_types = 1);
/**
* Represents a marking types.
*/
enum MDMarkingType implements MDValueEnumInterface, JsonSerializable, MDMeasurementUnitInterface {
case signature;
case engraving;
case watermark;
case scratch;
case stamp;
case overprint;
case embossing;
case handwritten;
case screwed;
case burnt_in;
case riveted;
case nailed;
case punched;
case hallmarked;
case scarified;
case cast;
case sewn;
case glued;
case painted;
case drawn;
case embroidered;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDMarkingType
*/
public static function fromString(string $input):MDMarkingType {
return match($input) {
'signature' => self::signature,
'engraving' => self::engraving,
'watermark' => self::watermark,
'scratch' => self::scratch,
'stamp' => self::stamp,
'overprint' => self::overprint,
'embossing' => self::embossing,
'handwritten' => self::handwritten,
'screwed' => self::screwed,
'burnt_in' => self::burnt_in,
'riveted' => self::riveted,
'nailed' => self::nailed,
'punched' => self::punched,
'hallmarked' => self::hallmarked,
'scarified' => self::scarified,
'cast' => self::cast,
'sewn' => self::sewn,
'glued' => self::glued,
'painted' => self::painted,
'drawn' => self::drawn,
'embroidered' => self::embroidered,
default => throw new MDpageParameterNotFromListException("Unknown marking type"),
};
}
/**
* Returns a value of this type based on an integer.
*
* @param integer $input Input to get a value from.
*
* @return MDMarkingType
*/
public static function fromInt(int $input):MDMarkingType {
return match($input) {
1 => self::signature,
2 => self::engraving,
3 => self::watermark,
4 => self::scratch,
5 => self::stamp,
6 => self::overprint,
7 => self::embossing,
8 => self::handwritten,
9 => self::screwed,
10 => self::burnt_in,
11 => self::riveted,
12 => self::nailed,
13 => self::punched,
14 => self::hallmarked,
15 => self::scarified,
16 => self::cast,
17 => self::sewn,
18 => self::glued,
19 => self::painted,
20 => self::drawn,
21 => self::embroidered,
default => throw new MDpageParameterNotFromListException("Unknown marking type"),
};
}
/**
* 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::signature => 1,
self::engraving => 2,
self::watermark => 3,
self::scratch => 4,
self::stamp => 5,
self::overprint => 6,
self::embossing => 7,
self::handwritten => 8,
self::screwed => 9,
self::burnt_in => 10,
self::riveted => 11,
self::nailed => 12,
self::punched => 13,
self::hallmarked => 14,
self::scarified => 15,
self::cast => 16,
self::sewn => 17,
self::glued => 18,
self::painted => 19,
self::drawn => 20,
self::embroidered => 21,
# 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(), "marking_types", "marking_types");
}
/**
* 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(), "marking_types", "marking_types");
}
/**
* 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("marking_types", "marking_types", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}
-5
View File
@@ -1,9 +1,4 @@
<?PHP
/**
* Represents a measurement type.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**