forked from museum-digital/MDAllowedValueSets
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c680cd0f9a
|
|||
|
efbb62c6ae
|
|||
|
2fc774430c
|
|||
|
611e0bf54f
|
|||
|
a93d763ebb
|
2
l18n
2
l18n
Submodule l18n updated: ca88e040b6...4f8dab7948
146
src/enums/MDDbQueryAscDesc.php
Normal file
146
src/enums/MDDbQueryAscDesc.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a sort order option in DB queries (ASC, DESC).
|
||||
*/
|
||||
enum MDDbQueryAscDesc implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case ASC;
|
||||
case DESC;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDDbQueryAscDesc
|
||||
*/
|
||||
public static function fromString(string $input):MDDbQueryAscDesc {
|
||||
|
||||
return match($input) {
|
||||
'asc' => self::ASC,
|
||||
'ASC' => self::ASC,
|
||||
'desc' => self::DESC,
|
||||
'DESC' => self::DESC,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown sort order"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDDbQueryAscDesc
|
||||
*/
|
||||
public static function fromInt(int $input):MDDbQueryAscDesc {
|
||||
|
||||
return match($input) {
|
||||
1 => self::ASC,
|
||||
2 => self::DESC,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown sort order"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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::ASC => 1,
|
||||
self::DESC => 2,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL representation of the entity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toDbName():string {
|
||||
|
||||
return match ($this) {
|
||||
self::ASC => 'ASC',
|
||||
self::DESC => 'DESC',
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), "query_asc_desc", "query_asc_desc");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), "query_asc_desc", "query_asc_desc");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("query_asc_desc", "query_asc_desc", $this->name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,16 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
case length_blade;
|
||||
case height_blade;
|
||||
case width_blade;
|
||||
case length_handle;
|
||||
case height_handle;
|
||||
case width_handle;
|
||||
case length_scabbard;
|
||||
case height_scabbard;
|
||||
case width_scabbard;
|
||||
|
||||
case length_label;
|
||||
case height_label;
|
||||
case width_label;
|
||||
|
||||
case number_of_sheets;
|
||||
case number_of_double_pages;
|
||||
@@ -104,6 +114,15 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
'length_blade' => self::length_blade,
|
||||
'height_blade' => self::height_blade,
|
||||
'width_blade' => self::width_blade,
|
||||
'length_handle' => self::length_handle,
|
||||
'height_handle' => self::height_handle,
|
||||
'width_handle' => self::width_handle,
|
||||
'length_scabbard' => self::length_scabbard,
|
||||
'height_scabbard' => self::height_scabbard,
|
||||
'width_scabbard' => self::width_scabbard,
|
||||
'length_label' => self::length_label,
|
||||
'height_label' => self::height_label,
|
||||
'width_label' => self::width_label,
|
||||
'number_of_sheets' => self::number_of_sheets,
|
||||
'number_of_double_pages' => self::number_of_double_pages,
|
||||
'number_of_standalone_sheets' => self::number_of_standalone_sheets,
|
||||
@@ -170,6 +189,15 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
40 => self::height_of_base,
|
||||
41 => self::width_of_base,
|
||||
42 => self::diameter_of_base,
|
||||
43 => self::length_handle,
|
||||
44 => self::height_handle,
|
||||
45 => self::width_handle,
|
||||
46 => self::length_scabbard,
|
||||
47 => self::height_scabbard,
|
||||
48 => self::width_scabbard,
|
||||
49 => self::length_label,
|
||||
50 => self::height_label,
|
||||
51 => self::width_label,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
@@ -247,6 +275,15 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
self::height_of_base => self::height,
|
||||
self::width_of_base => self::width,
|
||||
self::diameter_of_base => self::diameter,
|
||||
self::length_handle => self::length,
|
||||
self::height_handle => self::height,
|
||||
self::width_handle => self::width,
|
||||
self::length_scabbard => self::length,
|
||||
self::height_scabbard => self::height,
|
||||
self::width_scabbard => self::width,
|
||||
self::length_label => self::length,
|
||||
self::height_label => self::height,
|
||||
self::width_label => self::width,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
@@ -302,6 +339,15 @@ enum MDMeasurementType implements MDValueEnumInterface, JsonSerializable {
|
||||
self::height_of_base => 40,
|
||||
self::width_of_base => 41,
|
||||
self::diameter_of_base => 42,
|
||||
self::length_handle => 43,
|
||||
self::height_handle => 44,
|
||||
self::width_handle => 45,
|
||||
self::length_scabbard => 46,
|
||||
self::height_scabbard => 47,
|
||||
self::width_scabbard => 48,
|
||||
self::length_label => 49,
|
||||
self::height_label => 50,
|
||||
self::width_label => 51,
|
||||
# default => throw new MDpageParameterNotFromListException("Unknown measurement type"),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user