diff --git a/l18n b/l18n index c154279..82eac57 160000 --- a/l18n +++ b/l18n @@ -1 +1 @@ -Subproject commit c154279255a9e6dc1d0a79aea7eb286c5d0fcd14 +Subproject commit 82eac5766eb1b6aa1c85b36cd02b52e029b7687c diff --git a/src/enums/MDUserRole.php b/src/enums/MDUserRole.php new file mode 100644 index 0000000..4c1536c --- /dev/null +++ b/src/enums/MDUserRole.php @@ -0,0 +1,204 @@ + 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 + */ + 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 + */ + 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 + */ + public static function getSortedList(MDTlLoader $tlLoader):array { + + $output = self::getUnsortedList($tlLoader); + asort($output); + return $output; + + } + + /** + * Lists all available names. + * + * @return array + */ + 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(); + + } +}