Add MDObjectRecordStatus to track record status
This commit is contained in:
parent
65bbd03e2e
commit
10b9c58a1b
2
l18n
2
l18n
|
@ -1 +1 @@
|
|||
Subproject commit 5ba11ffba98cf0d702eb583e1d2d46b6995a8d7b
|
||||
Subproject commit 992922cb369c10ac7e6ffdad22c5a9dea800b28c
|
170
src/enums/MDObjectRecordStatus.php
Normal file
170
src/enums/MDObjectRecordStatus.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?PHP
|
||||
/**
|
||||
* Represents a status an object record is currently in, e.g. for determining
|
||||
* whether the object record can be edited or is locked.
|
||||
*
|
||||
* @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 MDObjectRecordStatus implements MDValueEnumInterface, JsonSerializable {
|
||||
|
||||
case unlocked;
|
||||
case locked;
|
||||
case revision;
|
||||
case deleted;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDObjectRecordStatus
|
||||
*/
|
||||
public static function fromString(string $input):MDTagRelationType {
|
||||
|
||||
return match($input) {
|
||||
'unlocked' => self::unlocked,
|
||||
'locked' => self::locked,
|
||||
'revision' => self::revision,
|
||||
'deleted' => self::deleted,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on an integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDObjectRecordStatus
|
||||
*/
|
||||
public static function fromInt(int $input):MDTagRelationType {
|
||||
|
||||
return match($input) {
|
||||
0 => self::unlocked,
|
||||
1 => self::locked,
|
||||
2 => self::revision,
|
||||
3 => self::deleted,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown object record status"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default status.
|
||||
*
|
||||
* @return MDObjectRecordStatus
|
||||
*/
|
||||
public static function getDefault():MDTagRelationType {
|
||||
|
||||
return self::unlocked;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<integer>
|
||||
*/
|
||||
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($this) {
|
||||
self::unlocked => 0,
|
||||
self::locked => 1,
|
||||
self::revision > 2,
|
||||
self::deleted => 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(), "object_record_status", "object_record_status");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(), "object_record_status", "object_record_status");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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("object_record_status", "object_record_status", $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