Add enums for object damage status and type
This commit is contained in:
		
							
								
								
									
										2
									
								
								l18n
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								l18n
									
									
									
									
									
								
							 Submodule l18n updated: 7aae0b8edb...ca22b133ec
									
								
							
							
								
								
									
										107
									
								
								src/enums/MDObjectDamageStatus.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								src/enums/MDObjectDamageStatus.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,107 @@
 | 
			
		||||
<?PHP
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a type of status that can be assigned to an object in the process
 | 
			
		||||
 * from identification to fixing or recognizing it is permanent.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Joshua Ramon Enslin <joshua@museum-digital.de>
 | 
			
		||||
 */
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a type of status that can be assigned to an object in the process
 | 
			
		||||
 * from identification to fixing or recognizing it is permanent.
 | 
			
		||||
 */
 | 
			
		||||
enum MDObjectDamageStatus implements MDValueEnumInterface, JsonSerializable {
 | 
			
		||||
 | 
			
		||||
    case identified;
 | 
			
		||||
    case repair_possible;
 | 
			
		||||
    case repair_scheduled; // By conservator
 | 
			
		||||
    case repaired;
 | 
			
		||||
    case irreparable;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a value of this type based on a string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $input Input to get a value from.
 | 
			
		||||
     *
 | 
			
		||||
     * @return MDObjectDamageType
 | 
			
		||||
     */
 | 
			
		||||
    public static function fromString(string $input):MDObjectDamageType {
 | 
			
		||||
 | 
			
		||||
        return match($input) {
 | 
			
		||||
            'identified' => self::identified,
 | 
			
		||||
            'repair_possible' => self::repair_possible,
 | 
			
		||||
            'repair_scheduled' => self::repair_scheduled,
 | 
			
		||||
            'repaired' => self::repaired,
 | 
			
		||||
            'irreparable' => self::irreparable,
 | 
			
		||||
            default => throw new MDpageParameterNotFromListException("Unknown damage type"),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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(), "object_damage_status_set", "object_damage_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(), "object_damage_status_set", "object_damage_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("object_damage_status_set", "object_damage_status_set", $this->name);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Provides the option to serialize as a string during json_encode().
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    public function jsonSerialize():string {
 | 
			
		||||
 | 
			
		||||
        return $this->name;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										99
									
								
								src/enums/MDObjectDamageType.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								src/enums/MDObjectDamageType.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,99 @@
 | 
			
		||||
<?PHP
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a type of damage an object may be subject to.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Joshua Ramon Enslin <joshua@museum-digital.de>
 | 
			
		||||
 */
 | 
			
		||||
declare(strict_types = 1);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a type of damage an object may be subject to.
 | 
			
		||||
 */
 | 
			
		||||
enum MDObjectDamageType implements MDValueEnumInterface, JsonSerializable {
 | 
			
		||||
 | 
			
		||||
    case water_damage;
 | 
			
		||||
    case breakage;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a value of this type based on a string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param string $input Input to get a value from.
 | 
			
		||||
     *
 | 
			
		||||
     * @return MDObjectDamageType
 | 
			
		||||
     */
 | 
			
		||||
    public static function fromString(string $input):MDObjectDamageType {
 | 
			
		||||
 | 
			
		||||
        return match($input) {
 | 
			
		||||
            'water_damage' => self::water_damage,
 | 
			
		||||
            'breakage' => self::breakage,
 | 
			
		||||
            default => throw new MDpageParameterNotFromListException("Unknown damage type"),
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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(), "object_damage_types_set", "object_damage_types_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(), "object_damage_types_set", "object_damage_types_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("object_damage_types_set", "object_damage_types_set", $this->name);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Provides the option to serialize as a string during json_encode().
 | 
			
		||||
     *
 | 
			
		||||
     * @return string
 | 
			
		||||
     */
 | 
			
		||||
    public function jsonSerialize():string {
 | 
			
		||||
 | 
			
		||||
        return $this->name;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user