Add enum MDUserRole for user roles in musdb
This commit is contained in:
+1
-1
Submodule l18n updated: c154279255...82eac5766e
@@ -0,0 +1,204 @@
|
|||||||
|
<?PHP
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a user role.
|
||||||
|
*/
|
||||||
|
enum MDUserRole implements MDValueEnumInterface, JsonSerializable {
|
||||||
|
|
||||||
|
case admin;
|
||||||
|
case regional_admin;
|
||||||
|
case museum_director;
|
||||||
|
case staff;
|
||||||
|
case input_only;
|
||||||
|
case visiting_scientist;
|
||||||
|
case specifically_determined;
|
||||||
|
case frontend_only_user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value of this type based on a string.
|
||||||
|
*
|
||||||
|
* @param string $input Input to get a value from.
|
||||||
|
*
|
||||||
|
* @return MDUserRole
|
||||||
|
*/
|
||||||
|
public static function fromString(string $input):MDUserRole {
|
||||||
|
|
||||||
|
return match($input) {
|
||||||
|
"0",
|
||||||
|
"admin" => self::admin,
|
||||||
|
"1",
|
||||||
|
"regional_admin" => self::regional_admin,
|
||||||
|
"2",
|
||||||
|
"museum_director" => self::museum_director,
|
||||||
|
"3",
|
||||||
|
"staff" => self::staff,
|
||||||
|
"4",
|
||||||
|
"input_only" => self::input_only,
|
||||||
|
"5",
|
||||||
|
"visiting_scientist" => self::visiting_scientist,
|
||||||
|
"6",
|
||||||
|
"specifically_determined" => self::specifically_determined,
|
||||||
|
"7",
|
||||||
|
"frontend_only_user" => self::frontend_only_user,
|
||||||
|
default => throw new MDpageParameterNotFromListException("Unknown user role"),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a value of this type based on an integer.
|
||||||
|
*
|
||||||
|
* @param integer $input Input to get a value from.
|
||||||
|
*
|
||||||
|
* @return MDUserRole
|
||||||
|
*/
|
||||||
|
public static function fromInt(int $input):MDUserRole {
|
||||||
|
|
||||||
|
return match($input) {
|
||||||
|
0 => self::admin,
|
||||||
|
1 => self::regional_admin,
|
||||||
|
2 => self::museum_director,
|
||||||
|
3 => self::staff,
|
||||||
|
4 => self::input_only,
|
||||||
|
5 => self::visiting_scientist,
|
||||||
|
6 => self::specifically_determined,
|
||||||
|
7 => self::frontend_only_user,
|
||||||
|
default => throw new MDpageParameterNotFromListException("Unknown user role"),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
|
||||||
|
$output = [];
|
||||||
|
foreach (self::cases() as $case) {
|
||||||
|
$output[$case->toString()] = $tlLoader->tl("user_roles", "user_roles", $case->toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
|
||||||
|
$output = self::getUnsortedList($tlLoader);
|
||||||
|
asort($output);
|
||||||
|
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::admin => 0,
|
||||||
|
self::regional_admin => 1,
|
||||||
|
self::museum_director => 2,
|
||||||
|
self::staff => 3,
|
||||||
|
self::input_only => 4,
|
||||||
|
self::visiting_scientist => 5,
|
||||||
|
self::specifically_determined => 6,
|
||||||
|
self::frontend_only_user => 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns canonical string representation of object record status.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function toString():string {
|
||||||
|
|
||||||
|
return match($this) {
|
||||||
|
self::admin => "admin",
|
||||||
|
self::regional_admin => "regional_admin",
|
||||||
|
self::museum_director => "museum_director",
|
||||||
|
self::staff => "staff",
|
||||||
|
self::input_only => "input_only",
|
||||||
|
self::visiting_scientist => "visiting_scientist",
|
||||||
|
self::specifically_determined => "specifically_determined",
|
||||||
|
self::frontend_only_user => "frontend_only_user",
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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("user_roles", "user_roles", $this->toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the option to serialize as a string during json_encode().
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function jsonSerialize():string {
|
||||||
|
|
||||||
|
return $this->toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user