Add check for Minimaldatensatz field set (http://minimaldatensatz.de)
This commit is contained in:
parent
f03bde7c50
commit
fe59eab399
133
src/Checks/Minimaldatensatz/MinimaldatensatzCheck.php
Normal file
133
src/Checks/Minimaldatensatz/MinimaldatensatzCheck.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?PHP
|
||||
/**
|
||||
* Since about 2022, a Germany-wide working group got together to work on a minimal
|
||||
* set of recommended and required fields for a basic object record. Primarily, this
|
||||
* targets import data for the German Digital Library.
|
||||
* This check is German-language only.
|
||||
*
|
||||
* @see http://minimaldatensatz.de
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Since about 2022, a Germany-wide working group got together to work on a minimal
|
||||
* set of recommended and required fields for a basic object record. Primarily, this
|
||||
* targets import data for the German Digital Library.
|
||||
* This check is German-language only.
|
||||
*/
|
||||
final class MinimaldatensatzCheck {
|
||||
|
||||
public bool $_has_title;
|
||||
public bool $_has_type;
|
||||
public bool $_has_topic_category;
|
||||
public bool $_has_inventory_number;
|
||||
public bool $_has_description;
|
||||
public bool $_has_material;
|
||||
public bool $_has_technique;
|
||||
public bool $_has_measurements;
|
||||
public bool $_has_event;
|
||||
public bool $_has_tag;
|
||||
public bool $_has_image;
|
||||
public bool $_has_image_license;
|
||||
public bool $_has_image_owner;
|
||||
|
||||
/**
|
||||
* Returns an evaluation message for a given required field.
|
||||
*
|
||||
* @param string $field Field to evaluate.
|
||||
* @param boolean $passed Sets whether the field is available and filled or not.
|
||||
* @param string $fieldname_de German language field name.
|
||||
*
|
||||
* @return array{field: string, passed: bool, text: string}
|
||||
*/
|
||||
private function _generateOutputMessageForRequiredField(string $field, bool $passed, string $fieldname_de):array {
|
||||
|
||||
return [
|
||||
'field' => $field,
|
||||
'required' => true,
|
||||
'passed' => $passed,
|
||||
'text' => match($passed) {
|
||||
true => 'Das Feld "' . $fieldname_de . '" ist vorhanden und ausgefüllt. Gut.',
|
||||
false => 'Das Pflichtfeld "' . $fieldname_de . '" ist nicht vorhanden oder nicht ausgefüllt.',
|
||||
},
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an evaluation message for a given optional field.
|
||||
*
|
||||
* @param string $field Field to evaluate.
|
||||
* @param boolean $passed Sets whether the field is available and filled or not.
|
||||
* @param string $fieldname_de German language field name.
|
||||
*
|
||||
* @return array{field: string, passed: bool, text: string}
|
||||
*/
|
||||
private function _generateOutputMessageForOptionalField(string $field, bool $passed, string $fieldname_de):array {
|
||||
|
||||
return [
|
||||
'field' => $field,
|
||||
'required' => false,
|
||||
'passed' => $passed,
|
||||
'text' => match($passed) {
|
||||
true => 'Das Feld "' . $fieldname_de . '" ist vorhanden und ausgefüllt. Gut.',
|
||||
false => 'Das Feld "' . $fieldname_de . '" ist nicht vorhanden oder nicht ausgefüllt. Es wird empfolen, diese Information mitzuliefern.',
|
||||
},
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of evaluations / checks for each field.
|
||||
*
|
||||
* @return array<array{field: string, required: bool, passed: bool, text: string}>
|
||||
*/
|
||||
public function evaluate():array {
|
||||
|
||||
$output = [];
|
||||
|
||||
if (!isset($this->_has_title)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Title has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForRequiredField("title", $this->_has_title, "Objekttitel oder -benennung");
|
||||
|
||||
if (!isset($this->_has_type)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Type has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForRequiredField("type", $this->_has_type, "Objekttyp oder -bezeichnung");
|
||||
|
||||
if (!isset($this->_has_topic_category)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Topic category has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForOptionalField("topic_category", $this->_has_topic_category, "Themenkategorie");
|
||||
|
||||
if (!isset($this->_has_inventory_number)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Inventory number has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForRequiredField("inventory_number", $this->_has_inventory_number, "Inventarnummer");
|
||||
|
||||
if (!isset($this->_has_description)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Description has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForOptionalField("description", $this->_has_description, "Objektbeschreibung");
|
||||
|
||||
if (!isset($this->_has_material)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Material has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForOptionalField("material", $this->_has_material, "Material");
|
||||
|
||||
if (!isset($this->_has_technique)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Technique has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForOptionalField("technique", $this->_has_technique, "Technik");
|
||||
|
||||
if (!isset($this->_has_measurements)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Measurements has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForOptionalField("measurements", $this->_has_measurements, "Maße");
|
||||
|
||||
if (!isset($this->_has_event)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Event has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForRequiredField("event", $this->_has_event, "Ereignis in der Objektgeschichte (Feldgruppe)");
|
||||
|
||||
if (!isset($this->_has_tag)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Tag has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForOptionalField("tag", $this->_has_tag, "Inhaltsschlagwort");
|
||||
|
||||
if (!isset($this->_has_image)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Image has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForRequiredField("image", $this->_has_image, "Mediendatei (Feldgruppe)");
|
||||
|
||||
if (!isset($this->_has_image_license)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Image license has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForRequiredField("image_license", $this->_has_image_license, "Nutzungsrechte Mediendatei");
|
||||
|
||||
if (!isset($this->_has_image_owner)) throw new MinimaldatensatzCheckIncompletelyImplementedException("Image owner has not been checked");
|
||||
$output[] = $this->_generateOutputMessageForRequiredField("image_owner", $this->_has_image_owner, "Rechteinhaber*in Mediendatei");
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?PHP
|
||||
/**
|
||||
* Custom exception class to be raised when not all fields have been set in the MinimaldatensatzCheck class.
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Custom exception class to be raised when not all fields have been set in the MinimaldatensatzCheck class.
|
||||
*/
|
||||
final class MinimaldatensatzCheckIncompletelyImplementedException extends Exception {
|
||||
/**
|
||||
* Error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorMessage() {
|
||||
//error message
|
||||
return 'Incompletely implemented check for Minimaldatensatz: ' . $this->getMessage();
|
||||
|
||||
}
|
||||
}
|
3
src/Checks/Minimaldatensatz/README.md
Normal file
3
src/Checks/Minimaldatensatz/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Checks for required and recommended fields according to the work of the Working Group "Minimaldatensatz" (Minimal Object Record)
|
||||
|
||||
See: http://minimaldatensatz.de
|
31
tests/MinimaldatensatzCheckTest.php
Normal file
31
tests/MinimaldatensatzCheckTest.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?PHP
|
||||
/**
|
||||
* Tests for check for Minimaldatensatz conformity.
|
||||
*
|
||||
* @see http://minimaldatensatz.de
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
require_once __DIR__ . '/../src/Checks/Minimaldatensatz/MinimaldatensatzCheck.php';
|
||||
require_once __DIR__ . '/../src/Checks/Minimaldatensatz/MinimaldatensatzCheckIncompletelyImplementedException.php';
|
||||
|
||||
/**
|
||||
* Tests for check for Minimaldatensatz conformity.
|
||||
*/
|
||||
final class MinimaldatensatzCheckTest extends TestCase {
|
||||
/**
|
||||
* Ensures that a warning is thrown, if a value has not been set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testImageNotChecked():void {
|
||||
|
||||
$check = new MinimaldatensatzCheck;
|
||||
$this->expectException(MinimaldatensatzCheckIncompletelyImplementedException::class);
|
||||
$check->evaluate();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user