Files
CABM-IT/app/Models/Document.php
T
mrKamooandClaude Sonnet 5 c1c6d56d1e Ajoute dossiers et association de site aux schémas d'infrastructure
- Navigation par dossiers dans la section Infrastructure (créer, parcourir,
  fil d'ariane), isolée du navigateur Documents comme les schémas eux-mêmes.
- Un schéma peut être associé à un site de l'organisation, avec filtre par
  site dans la liste.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-24 07:57:45 +02:00

103 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use App\Contracts\Linkable;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use League\CommonMark\CommonMarkConverter;
#[Fillable(['organization_id', 'folder_id', 'location_id', 'name', 'type', 'is_folder', 'content', 'file_path', 'office_extension', 'office_key', 'current_version', 'created_by'])]
class Document extends Model implements Linkable
{
use SoftDeletes;
protected function casts(): array
{
return [
'is_folder' => 'boolean',
];
}
public function isOffice(): bool
{
return $this->type === 'office';
}
public function isMarkdown(): bool
{
return $this->type === 'markdown';
}
public function isUpload(): bool
{
return $this->type === 'upload';
}
public function isDiagram(): bool
{
return $this->type === 'diagram';
}
public function renderedMarkdown(): string
{
return (new CommonMarkConverter())->convert($this->content ?? '')->getContent();
}
public function isFolder(): bool
{
return $this->is_folder || $this->children()->exists();
}
public function organization()
{
return $this->belongsTo(Organization::class);
}
public function folder()
{
return $this->belongsTo(Document::class, 'folder_id');
}
public function location()
{
return $this->belongsTo(Location::class);
}
public function children()
{
return $this->hasMany(Document::class, 'folder_id');
}
public function versions()
{
return $this->hasMany(DocumentVersion::class)->orderByDesc('version');
}
public function creator()
{
return $this->belongsTo(User::class, 'created_by');
}
public function relatedItems()
{
return RelatedItem::forItem($this);
}
public function linkableKind(): string
{
return 'Document';
}
public function linkableLabel(): string
{
return $this->name;
}
public function linkableUrl(): string
{
return route('organizations.documents.edit', [$this->organization_id, $this]);
}
}