Restructure MDPlausiForLegalStatus to take image rights from the
constructor on, add translations Close #2
This commit is contained in:
@ -25,6 +25,8 @@ final class MDPlausiForLegalStatus {
|
||||
|
||||
/** @var array<MDPlausiEvent> */
|
||||
private array $_events;
|
||||
/** @var array<array{name: string, license: string}> */
|
||||
private array $_representations;
|
||||
|
||||
# private string $_latest_production_name;
|
||||
private int $_latest_production;
|
||||
@ -90,7 +92,9 @@ final class MDPlausiForLegalStatus {
|
||||
# $this->_production->latest_time_name = $event->actor_death;
|
||||
}
|
||||
|
||||
// Actors who have not yet died
|
||||
// Actors who have not yet died will have their birth set as the last
|
||||
// possible time. This is a bit hacky, but should work for all
|
||||
// actors who have not lived beyond 100 years.
|
||||
if (
|
||||
$event->actor_death_normalized === false
|
||||
&& $event->actor_birth_normalized !== false
|
||||
@ -111,11 +115,9 @@ final class MDPlausiForLegalStatus {
|
||||
* Evaluates a range of representations and returns a simple answer without translations.
|
||||
* For translations, use the wrapper function $this->evaluate().
|
||||
*
|
||||
* @param array<array{name: string, license: string}> $representations Representations of the object.
|
||||
*
|
||||
* @return array{has_warning: bool, msgs: array<array{name: string, license: string, type: string, additional?: array{representation: MDCopyrightCollective}}>}
|
||||
* @return array{has_warning: bool, msgs: array<array{name: string, license: string, reason: MDPlausiLegalCheckReason, type: MDPlausiLegalCheckResultType, additional?: array{representation: MDCopyrightCollective}}>}
|
||||
*/
|
||||
public function evaluateSimple(array $representations):array {
|
||||
public function evaluateSimple():array {
|
||||
|
||||
if ($this->_expected_status === 'any') {
|
||||
return ['has_warning' => false, 'msgs' => []];
|
||||
@ -126,7 +128,7 @@ final class MDPlausiForLegalStatus {
|
||||
}
|
||||
|
||||
$msgs = [];
|
||||
foreach ($representations as $representation) {
|
||||
foreach ($this->_representations as $representation) {
|
||||
|
||||
|
||||
if ($this->_expected_status === 'pd'
|
||||
@ -135,7 +137,8 @@ final class MDPlausiForLegalStatus {
|
||||
$msgs[] = [
|
||||
'name' => $representation['name'],
|
||||
'license' => $representation['license'],
|
||||
'type' => 'expect_public_domain',
|
||||
'reason' => MDPlausiLegalCheckReason::creator_dead_for_years,
|
||||
'type' => MDPlausiLegalCheckResultType::expect_public_domain,
|
||||
];
|
||||
}
|
||||
|
||||
@ -147,7 +150,8 @@ final class MDPlausiForLegalStatus {
|
||||
$msgs[] = [
|
||||
'name' => $representation['name'],
|
||||
'license' => $representation['license'],
|
||||
'type' => 'expect_restricted_legal_status',
|
||||
'reason' => MDPlausiLegalCheckReason::creator_recently_or_not_dead,
|
||||
'type' => MDPlausiLegalCheckResultType::expect_restricted_legal_status,
|
||||
'additional' => [
|
||||
'representation' => $collective
|
||||
],
|
||||
@ -157,7 +161,8 @@ final class MDPlausiForLegalStatus {
|
||||
$msgs[] = [
|
||||
'name' => $representation['name'],
|
||||
'license' => $representation['license'],
|
||||
'type' => 'expect_restricted_legal_status',
|
||||
'reason' => MDPlausiLegalCheckReason::creator_recently_or_not_dead,
|
||||
'type' => MDPlausiLegalCheckResultType::expect_restricted_legal_status,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -170,18 +175,39 @@ final class MDPlausiForLegalStatus {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Formulates a human-readable, translated text message for a notice.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
* @param array{name: string, license: string, reason: MDPlausiLegalCheckReason, type: MDPlausiLegalCheckResultType, additional?: array{representation: MDCopyrightCollective}} $msg Input message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _formulateText(MDTlLoader $tlLoader, array $msg):string {
|
||||
|
||||
$output = $tlLoader->tl("basis", "basis", "image") . ' "' . $msg['name'] . '": ' . $msg['reason']->getTl($tlLoader) . ' ' . $msg['type']->getTl($tlLoader);
|
||||
|
||||
$output .= ' ' . $tlLoader->tl("quality", "quality", "current_license") . ': ' . $msg['license'] . '.';
|
||||
|
||||
if (!empty($msg['additional'])) {
|
||||
$output .= ' ' . $tlLoader->tl("quality", "quality", "creator_represented_by_copyright_collective") . ': ' . $msg['additional']['representation']->getName() . '.';
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates an object's representations' legal / licensing status based on
|
||||
* the expected values.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
* @param array<array{name: string, license: string}> $representations Representations of the object.
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return array{has_warning: bool, msgs: array<array{name: string, license: string, type: string, text: string}>}
|
||||
* @return array{has_warning: bool, msgs: array<array{name: string, license: string, reason: MDPlausiLegalCheckReason, type: MDPlausiLegalCheckResultType, text: string, link: string}>}
|
||||
*/
|
||||
public function evaluate(MDTlLoader $tlLoader, array $representations):array {
|
||||
public function evaluate(MDTlLoader $tlLoader):array {
|
||||
|
||||
$evaluation = $this->evaluateSimple($representations);
|
||||
$evaluation = $this->evaluateSimple();
|
||||
if ($evaluation['has_warning'] === false) {
|
||||
return ['has_warning' => false, 'msgs' => []];
|
||||
}
|
||||
@ -189,11 +215,18 @@ final class MDPlausiForLegalStatus {
|
||||
$output = [];
|
||||
foreach ($evaluation['msgs'] as $msg) {
|
||||
|
||||
throw new Exception("To be implemented");
|
||||
if (!empty($msg['additional'])) {
|
||||
$link = $msg['additional']['representation']->getContactForm();
|
||||
}
|
||||
else $link = '';
|
||||
|
||||
$output[] = [
|
||||
'name' => $msg['name'],
|
||||
'license' => $msg['license'],
|
||||
'reason' => $msg['reason'],
|
||||
'type' => $msg['type'],
|
||||
'text' => $this->_formulateText($tlLoader, $msg),
|
||||
'link' => $link,
|
||||
];
|
||||
|
||||
}
|
||||
@ -221,13 +254,15 @@ final class MDPlausiForLegalStatus {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array<MDPlausiEvent> $events Events.
|
||||
* @param array<MDPlausiEvent> $events Events.
|
||||
* @param array<array{name: string, license: string}> $representations Representations of the object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $events) {
|
||||
public function __construct(array $events, array $representations) {
|
||||
|
||||
$this->_events = $events;
|
||||
$this->_representations = $representations;
|
||||
|
||||
$this->_categorizeEvents();
|
||||
$this->_expected_status = $this->_determineExpectedStatus();
|
||||
|
119
src/Checks/PlausiForLegalStatus/MDPlausiLegalCheckReason.php
Normal file
119
src/Checks/PlausiForLegalStatus/MDPlausiLegalCheckReason.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Describes a reason for a notice on why the provided copyright status of
|
||||
* an object or its representations is invalid.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a possible status for to-dos.
|
||||
*/
|
||||
enum MDPlausiLegalCheckReason implements JsonSerializable {
|
||||
|
||||
case creator_dead_for_years;
|
||||
case creator_recently_or_not_dead;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDPlausiLegalCheckReason
|
||||
*/
|
||||
public static function fromString(string $input):MDPlausiLegalCheckReason {
|
||||
|
||||
return match($input) {
|
||||
'creator_dead_for_years' => self::creator_dead_for_years,
|
||||
'creator_recently_or_not_dead' => self::creator_recently_or_not_dead,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown reason"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDPlausiLegalCheckReason
|
||||
*/
|
||||
public static function fromInt(int $input):MDPlausiLegalCheckReason {
|
||||
|
||||
return match($input) {
|
||||
1 => self::creator_dead_for_years,
|
||||
2 => self::creator_recently_or_not_dead,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown reason"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric representation of the type, e.g. for efficient storage in a DB.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function toInt():int {
|
||||
|
||||
return match($this) {
|
||||
self::creator_dead_for_years => 1,
|
||||
self::creator_recently_or_not_dead => 2,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a translation for the entry.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTl(MDTlLoader $tlLoader):string {
|
||||
|
||||
$tl = $tlLoader->tl("quality", "quality", "legal_check_reason_" . $this->name);
|
||||
|
||||
$toReplaceWith = (string)match($this) {
|
||||
self::creator_dead_for_years => MDPlausiForLegalStatus::YEARS_AFTER_DEATH_TO_PUBLIC_DOMAIN,
|
||||
self::creator_recently_or_not_dead => MDPlausiForLegalStatus::YEARS_AFTER_DEATH_TO_PUBLIC_DOMAIN_CERTAIN,
|
||||
};
|
||||
|
||||
if (str_contains($tl, "[placeholder_copyright_expiry]") === false) {
|
||||
throw new Exception("Error in translating. Language " . $tlLoader->getLang() . " is missing placeholder [placeholder_copyright_expiry].");
|
||||
}
|
||||
|
||||
return str_replace("[placeholder_copyright_expiry]", $toReplaceWith, $tl);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the option to serialize as a string during json_encode().
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function jsonSerialize():string {
|
||||
|
||||
return $this->name;
|
||||
|
||||
}
|
||||
}
|
108
src/Checks/PlausiForLegalStatus/MDPlausiLegalCheckResultType.php
Normal file
108
src/Checks/PlausiForLegalStatus/MDPlausiLegalCheckResultType.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Describes a suggestion / warning for possible invalid legal statuses of an object's
|
||||
* or its representations legal status.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Represents a possible status for to-dos.
|
||||
*/
|
||||
enum MDPlausiLegalCheckResultType implements JsonSerializable {
|
||||
|
||||
case expect_public_domain;
|
||||
case expect_restricted_legal_status;
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a string.
|
||||
*
|
||||
* @param string $input Input to get a value from.
|
||||
*
|
||||
* @return MDPlausiLegalCheckResultType
|
||||
*/
|
||||
public static function fromString(string $input):MDPlausiLegalCheckResultType {
|
||||
|
||||
return match($input) {
|
||||
'expect_public_domain' => self::expect_public_domain,
|
||||
'expect_restricted_legal_status' => self::expect_restricted_legal_status,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown result type"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value of this type based on a integer.
|
||||
*
|
||||
* @param integer $input Input to get a value from.
|
||||
*
|
||||
* @return MDPlausiLegalCheckResultType
|
||||
*/
|
||||
public static function fromInt(int $input):MDPlausiLegalCheckResultType {
|
||||
|
||||
return match($input) {
|
||||
1 => self::expect_public_domain,
|
||||
2 => self::expect_restricted_legal_status,
|
||||
default => throw new MDpageParameterNotFromListException("Unknown result type"),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numeric representation of the type, e.g. for efficient storage in a DB.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function toInt():int {
|
||||
|
||||
return match($this) {
|
||||
self::expect_public_domain => 1,
|
||||
self::expect_restricted_legal_status => 2,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a translation for the entry.
|
||||
*
|
||||
* @param MDTlLoader $tlLoader Translation loader.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTl(MDTlLoader $tlLoader):string {
|
||||
|
||||
return $tlLoader->tl("quality", "quality", "legal_check_msg_type_" . $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