79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Catalog;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ArticleRelease extends Model
|
|
{
|
|
protected $fillable = [
|
|
'license_article_id',
|
|
'number',
|
|
'change_kind',
|
|
'important',
|
|
'classification_note',
|
|
'status',
|
|
'block_reason',
|
|
'fallback_release_id',
|
|
'change_note',
|
|
'root_element_version_id',
|
|
'root_composition_version_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'important' => 'boolean',
|
|
'status' => ReleaseStatus::class,
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::updating(function (ArticleRelease $release): void {
|
|
$original = StatusValue::of($release->getOriginal('status'));
|
|
|
|
if (! in_array($original, [
|
|
ReleaseStatus::Veroeffentlicht->value,
|
|
ReleaseStatus::AbgeloestVerfuegbar->value,
|
|
], true)) {
|
|
return;
|
|
}
|
|
|
|
$dirty = array_diff(array_keys($release->getDirty()), ['status', 'updated_at']);
|
|
|
|
if ($dirty !== []) {
|
|
throw new DomainRuleException('Ein veröffentlichter Artikel-Stand ist unveränderlich.');
|
|
}
|
|
|
|
$next = StatusValue::of($release->status);
|
|
|
|
if ($original === ReleaseStatus::Veroeffentlicht->value && $next !== ReleaseStatus::AbgeloestVerfuegbar->value) {
|
|
throw new DomainRuleException('Ein veröffentlichter Artikel-Stand kann nur abgelöst werden.');
|
|
}
|
|
});
|
|
}
|
|
|
|
public function article(): BelongsTo
|
|
{
|
|
return $this->belongsTo(LicenseArticle::class, 'license_article_id');
|
|
}
|
|
|
|
public function contents(): HasMany
|
|
{
|
|
return $this->hasMany(ReleaseContent::class)->orderBy('position');
|
|
}
|
|
|
|
public function rootElementVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ContentElementVersion::class, 'root_element_version_id');
|
|
}
|
|
|
|
public function rootCompositionVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CompositionVersion::class, 'root_composition_version_id');
|
|
}
|
|
}
|