Add enums for appointments' attendence status and cancellation status

This commit is contained in:
Joshua Ramon Enslin 2022-12-26 00:52:22 +01:00
parent 15e983411b
commit 0f1458e7d4
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
3 changed files with 221 additions and 1 deletions

2
l18n

@ -1 +1 @@
Subproject commit ca22b133ecc12ad49b8d17519571cc2eb8a03df7 Subproject commit 04b1e8d678fbb37cac7d96b167be5822bab2491a

View File

@ -0,0 +1,110 @@
<?PHP
/**
* Represents a type of cancellation status for events / appointments.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a type of cancellation status for events / appointments.
*/
enum MDAppointmentCancellationStatus implements MDValueEnumInterface, JsonSerializable {
case scheduled_done;
case cancelled;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDAppointmentCancellationStatus
*/
public static function fromString(string $input):MDAppointmentCancellationStatus {
return match($input) {
'scheduled_done' => self::scheduled_done,
'cancelled' => self::cancelled,
default => throw new MDpageParameterNotFromListException("Unknown cancellation status"),
};
}
/**
* Returns the default status.
*
* @return MDAppointmentCancellationStatus
*/
public static function getDefault():MDAppointmentCancellationStatus {
return self::scheduled_done;
}
/**
* 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 {
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "appointment_cancellation_status_set", "appointment_cancellation_status_set");
}
/**
* 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(), "appointment_cancellation_status_set", "appointment_cancellation_status_set");
}
/**
* 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("appointment_cancellation_status_set", "appointment_cancellation_status_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}

View File

@ -0,0 +1,110 @@
<?PHP
/**
* Represents a type of attendance status for events / appointments: offline or online.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
*/
declare(strict_types = 1);
/**
* Represents a type of attendance status for events / appointments: offline or online.
*/
enum MDAttendanceStatus implements MDValueEnumInterface, JsonSerializable {
case online;
case offline;
/**
* Returns a value of this type based on a string.
*
* @param string $input Input to get a value from.
*
* @return MDAttendanceStatus
*/
public static function fromString(string $input):MDAttendanceStatus {
return match($input) {
'online' => self::online,
'offline' => self::offline,
default => throw new MDpageParameterNotFromListException("Unknown attendance status"),
};
}
/**
* Returns the default status.
*
* @return MDAttendanceStatus
*/
public static function getDefault():MDAttendanceStatus {
return self::offline;
}
/**
* 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 {
return MDValueSet::getTlUnsortedList($tlLoader, self::caseNames(), "attendance_status_set", "attendance_status_set");
}
/**
* 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(), "attendance_status_set", "attendance_status_set");
}
/**
* 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("attendance_status_set", "attendance_status_set", $this->name);
}
/**
* Provides the option to serialize as a string during json_encode().
*
* @return string
*/
public function jsonSerialize():string {
return $this->name;
}
}