Files
MDAllowedValueSets/src/enums/MDObjectRecordStatus.php

222 lines
5.5 KiB
PHP

<?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 archived;
/**
* 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):MDObjectRecordStatus {
return match($input) {
'unlocked' => self::unlocked,
'locked' => self::locked,
'revision' => self::revision,
'archived' => self::archived,
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):MDObjectRecordStatus {
return match($input) {
0 => self::unlocked,
1 => self::locked,
2 => self::revision,
3 => self::archived,
default => throw new MDpageParameterNotFromListException("Unknown object record status"),
};
}
/**
* Returns the default status.
*
* @return MDObjectRecordStatus
*/
public static function getDefault():MDObjectRecordStatus {
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 object record status.
*
* @return integer
*/
public function toInt():int {
return match($this) {
self::unlocked => 0,
self::locked => 1,
self::revision => 2,
self::archived => 3,
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
};
}
/**
* Returns string representation of object record status.
*
* @return string
*/
public function toString():string {
return match($this) {
self::unlocked => "unlocked",
self::locked => "locked",
self::revision => "revision",
self::archived => "archived",
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
};
}
/**
* Returns CSS icon class for record status.
*
* @return string
*/
public function toCssIconClass():string {
return match($this) {
self::unlocked => "iconsLockOpen",
self::locked => "iconsLock",
self::revision => "iconsFolderDelete",
self::archived => "iconsEmojiSymbols",
// 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);
}
/**
* Returns whether the status permits an updating of the object record.
*
* @return boolean
*/
public function checkWritingIsEnabled():bool {
return match($this) {
self::unlocked => true,
self::locked => false,
self::revision => false,
self::archived => false,
# default => throw new MDpageParameterNotFromListException("Unknown object record status"),
};
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}