Add MDTagRelationType
This commit is contained in:
parent
077eaeb3e3
commit
a437f1b57b
2
l18n
2
l18n
|
@ -1 +1 @@
|
||||||
Subproject commit 524eadbbd27906ae85911b758acd5af0d5534ac7
|
Subproject commit 64e2ae642a90aa1ecee9cd17abde3a8cf55b54d9
|
170
src/enums/MDTagRelationType.php
Normal file
170
src/enums/MDTagRelationType.php
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
<?PHP
|
||||||
|
/**
|
||||||
|
* Represents a type of link between tag and object (e.g. the tag being the object
|
||||||
|
* type, a material used for creating the object, etc.).
|
||||||
|
*
|
||||||
|
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||||
|
*/
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a type of link between tag and object (e.g. the tag being the object
|
||||||
|
* type, a material used for creating the object, etc.).
|
||||||
|
*/
|
||||||
|
enum MDTagRelationType implements MDValueEnumInterface, JsonSerializable {
|
||||||
|
|
||||||
|
case tag;
|
||||||
|
case object_type;
|
||||||
|
case material;
|
||||||
|
case technique;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value of this type based on a string.
|
||||||
|
*
|
||||||
|
* @param string $input Input to get a value from.
|
||||||
|
*
|
||||||
|
* @return MDTagRelationType
|
||||||
|
*/
|
||||||
|
public static function fromString(string $input):MDTagRelationType {
|
||||||
|
|
||||||
|
return match($input) {
|
||||||
|
'tag' => self::tag,
|
||||||
|
'object_type' => self::object_type,
|
||||||
|
'material' => self::material,
|
||||||
|
'technique' => self::technique,
|
||||||
|
default => throw new MDpageParameterNotFromListException("Unknown tag relation type"),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value of this type based on an integer.
|
||||||
|
*
|
||||||
|
* @param string $input Input to get a value from.
|
||||||
|
*
|
||||||
|
* @return MDTagRelationType
|
||||||
|
*/
|
||||||
|
public static function fromInt(int $input):MDTagRelationType {
|
||||||
|
|
||||||
|
return match($input) {
|
||||||
|
0 => self::tag,
|
||||||
|
1 => self::object_type,
|
||||||
|
2 => self::material,
|
||||||
|
3 => self::technique,
|
||||||
|
default => throw new MDpageParameterNotFromListException("Unknown tag relation type"),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default status.
|
||||||
|
*
|
||||||
|
* @return MDTagRelationType
|
||||||
|
*/
|
||||||
|
public static function getDefault():MDTagRelationType {
|
||||||
|
|
||||||
|
return self::tag;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all available names.
|
||||||
|
*
|
||||||
|
* @return array<string>
|
||||||
|
*/
|
||||||
|
public static function caseInts():array {
|
||||||
|
|
||||||
|
$output = [];
|
||||||
|
|
||||||
|
$cases = self::cases();
|
||||||
|
foreach ($cases as $case) {
|
||||||
|
$output[] = $case->toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns integer representation of tag relations.
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function toInt():int {
|
||||||
|
|
||||||
|
return match(self) {
|
||||||
|
self::tag => 0,
|
||||||
|
self::object_type => 1,
|
||||||
|
self::material => 2,
|
||||||
|
self::technique => 3,
|
||||||
|
default => throw new MDpageParameterNotFromListException("Unknown tag relation 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(), "tag_relation_type", "tag_relation_type");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(), "tag_relation_type", "tag_relation_type");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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("tag_relation_type", "tag_relation_type", $this->name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the option to serialize as a string during json_encode().
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function jsonSerialize():string {
|
||||||
|
|
||||||
|
return $this->name;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user