73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class DocumentoArchivioCartella extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'documento_archivio_cartelle';
|
|
|
|
protected $fillable = [
|
|
'stabile_id',
|
|
'parent_id',
|
|
'nome',
|
|
'slug',
|
|
'codice',
|
|
'percorso_logico',
|
|
'visibility_scope',
|
|
'visibility_roles',
|
|
'visibility_groups',
|
|
'allowed_user_ids',
|
|
'note',
|
|
'sort_order',
|
|
'is_active',
|
|
'created_by',
|
|
'updated_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'visibility_roles' => 'array',
|
|
'visibility_groups' => 'array',
|
|
'allowed_user_ids' => 'array',
|
|
'sort_order' => 'integer',
|
|
'is_active' => 'boolean',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
public function stabile(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Stabile::class, 'stabile_id');
|
|
}
|
|
|
|
public function parent(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'parent_id');
|
|
}
|
|
|
|
public function children(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order')->orderBy('nome');
|
|
}
|
|
|
|
public function documenti(): HasMany
|
|
{
|
|
return $this->hasMany(Documento::class, 'cartella_archivio_id');
|
|
}
|
|
|
|
public function getDisplayPathAttribute(): string
|
|
{
|
|
$parts = array_filter([
|
|
trim((string) ($this->parent?->display_path ?? '')),
|
|
trim((string) ($this->nome ?? '')),
|
|
]);
|
|
|
|
return $parts === [] ? (string) ($this->nome ?? '') : implode(' / ', $parts);
|
|
}
|
|
}
|