Ergänze das U1-Fachmodell für Inhalt, Paket und Angebot.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
2035c46edd
commit
2ded4b7fad
35 files changed
+2115
No files matched your search
@@ -0,0 +1,78 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user