63 خطوط
2.0 KiB
PHP
63 خطوط
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Taxonomy\Domain;
|
|
|
|
use App\Modules\Courses\Domain\CourseVersion;
|
|
use App\Modules\Courses\Domain\Enums\CourseVersionStatus;
|
|
use App\Modules\Taxonomy\Domain\Enums\MappableType;
|
|
use App\Modules\Taxonomy\Domain\Enums\MappingConfirmationStatus;
|
|
use App\Modules\Taxonomy\Domain\Enums\MappingSource;
|
|
use App\Modules\Taxonomy\Domain\Enums\MappingType;
|
|
use DomainException;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class ContentTaxonomyMapping extends Model
|
|
{
|
|
use HasUlids;
|
|
|
|
protected $fillable = [
|
|
'organization_id', 'course_version_id', 'mappable_type', 'mappable_id',
|
|
'taxonomy_node_id', 'mapping_type', 'mastery_level', 'weight', 'source', 'confidence',
|
|
'confirmation_status', 'confirmed_by', 'confirmed_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'mappable_type' => MappableType::class,
|
|
'mapping_type' => MappingType::class,
|
|
'source' => MappingSource::class,
|
|
'confirmation_status' => MappingConfirmationStatus::class,
|
|
'weight' => 'decimal:4',
|
|
'confidence' => 'decimal:4',
|
|
'confirmed_at' => 'immutable_datetime',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
$assertDraftVersion = function (self $mapping): void {
|
|
$version = CourseVersion::query()->findOrFail($mapping->course_version_id);
|
|
|
|
if ($version->status === CourseVersionStatus::Published) {
|
|
throw new DomainException('Mappings for published course versions are immutable.');
|
|
}
|
|
};
|
|
|
|
static::updating($assertDraftVersion);
|
|
static::deleting($assertDraftVersion);
|
|
}
|
|
|
|
public function courseVersion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CourseVersion::class);
|
|
}
|
|
|
|
public function taxonomyNode(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TaxonomyNode::class);
|
|
}
|
|
}
|