diff --git a/src/enums/MDPhoneType.php b/src/enums/MDPhoneType.php new file mode 100644 index 0000000..5ac16f6 --- /dev/null +++ b/src/enums/MDPhoneType.php @@ -0,0 +1,188 @@ + self::work, + "home" => self::home, + "mobile" => self::mobile, + "work mobile", + "work_mobile" => self::work_mobile, + "fax" => self::fax, + "fax work", + "fax_work" => self::fax_work, + default => throw new MDpageParameterNotFromListException("Unknown phone type"), + }; + + } + + /** + * Returns a value of this type based on an integer. + * + * @param integer $input Input to get a value from. + * + * @return MDPhoneType + */ + public static function fromInt(int $input):MDPhoneType { + + return match($input) { + 0 => self::work, + 1 => self::home, + 2 => self::mobile, + 3 => self::work_mobile, + 4 => self::fax, + 5 => self::fax_work, + default => throw new MDpageParameterNotFromListException("Unknown phone type"), + }; + + } + + /** + * 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("phone_types", "phone_types", $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::work => 0, + self::home => 1, + self::mobile => 2, + self::work_mobile => 3, + self::fax => 4, + self::fax_work => 5, + }; + + } + + /** + * Returns canonical string representation of object record status. + * + * @return string + */ + public function toString():string { + + return match($this) { + self::work => "work", + self::home => "home", + self::mobile => "mobile", + self::work_mobile => "work mobile", + self::fax => "fax", + self::fax_work => "fax work", + }; + + } + + /** + * 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("phone_types", "phone_types", $this->toString()); + + } + + /** + * Provides the option to serialize as a string during json_encode(). + * + * @return string + */ + public function jsonSerialize():string { + + return $this->toString(); + + } +}