mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
wiki
This commit is contained in:
59
ci4/app/Entities/Wiki/WikiSectionEntity.php
Normal file
59
ci4/app/Entities/Wiki/WikiSectionEntity.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace App\Entities\Wiki;
|
||||
|
||||
use App\Models\Wiki\WikiContentModel;
|
||||
use App\Models\Wiki\WikiPageModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class WikiSectionEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"name" => null,
|
||||
"slug" => null,
|
||||
"role" => null,
|
||||
"parent_id" => null
|
||||
];
|
||||
protected $casts = [
|
||||
"name" => "string",
|
||||
"slug" => "string",
|
||||
"role" => "string",
|
||||
"parent_id" => "int"
|
||||
];
|
||||
|
||||
public function withPage(): self
|
||||
{
|
||||
$this->attributes['pages'] = $this->page();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withContents(string $locale = "es"): self
|
||||
{
|
||||
$m = model(WikiContentModel::class);
|
||||
$this->attributes['contents'] = $this->content($locale);
|
||||
return $this;
|
||||
}
|
||||
public function withAll(string $locale = "es") : self
|
||||
{
|
||||
$this->withPage();
|
||||
$this->withContents($locale);
|
||||
return $this;
|
||||
|
||||
}
|
||||
public function page(): ?WikiPageEntity
|
||||
{
|
||||
$m = model(WikiPageModel::class);
|
||||
return $m->where('section_id',$this->attributes['id'])->first();
|
||||
}
|
||||
public function content(string $locale = "es"): ?WikiContentEntity
|
||||
{
|
||||
$page = $this->page();
|
||||
$content = null;
|
||||
$m = model(WikiContentModel::class);
|
||||
if($page){
|
||||
$content = $m->where('page_id',$page->id)
|
||||
->where('locale',$locale)
|
||||
->first();
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user