1
0
cms11/app/Classes/Term.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2024-04-26 13:47:36 +02:00
<?php
namespace App\Classes;
use Illuminate\Support\Str;
class Term
{
protected Bundle $bundle;
protected string $slug;
protected Link $link;
protected string $path;
public function __construct(
protected string $term,
protected string $subCategory,
protected Bundle $source
) {
$this->slug = Str::slug($term);
$this->path = sprintf('/termes/%s', $this->slug);
$this->bundle = new Bundle($this->path, $source->getDisk());
2024-05-09 21:52:57 +02:00
//$this->link = new Link($this->path, $term, $source);
2024-04-26 13:47:36 +02:00
2024-04-26 13:59:42 +02:00
$this->bundle->load();
2024-04-26 13:47:36 +02:00
$currentRelations = $this->bundle->metadata('relations')->get($subCategory, []);
if (!in_array($source->getPath(), $currentRelations)) {
$currentRelations[] = $source->getPath();
$this->bundle->metadata('relations')->set($subCategory, collect($currentRelations)->unique()->toArray());
}
2024-04-26 13:59:42 +02:00
if (empty($this->bundle->markdown()->get())) {
$this->bundle->markdown()->set('');
}
if (empty($this->bundle->metadata()->get('title'))) {
$this->bundle->metadata()->set('title', $term);
}
2024-04-26 13:47:36 +02:00
$this->bundle->save();
}
public function render()
{
2024-05-09 21:52:57 +02:00
return sprintf('<a href="%s">%s</a>', $this->path, $this->term);
2024-04-26 13:47:36 +02:00
}
public static function register(string $term, string $subCategory, Bundle $source)
{
return new static($term, $subCategory, $source);
}
}