mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'feat/wiki' into 'main'
Feat/wiki See merge request jjimenez/safekat!581
This commit is contained in:
35
ci4/app/Entities/Wiki/WikiContentEntity.php
Normal file
35
ci4/app/Entities/Wiki/WikiContentEntity.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entities\Wiki;
|
||||
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class WikiContentEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"locale" => null,
|
||||
"page_id" => null,
|
||||
"editor_data" => null,
|
||||
"published_data" => null,
|
||||
"last_edit_by" => null,
|
||||
"published_by" => null,
|
||||
"published_at" => null,
|
||||
];
|
||||
protected $casts = [
|
||||
"locale" => "string",
|
||||
"page_id" => "int",
|
||||
"editor_data" => "string",
|
||||
"published_data" => "string",
|
||||
"last_edit_by" => "int",
|
||||
"published_by" => "int",
|
||||
"published_at" => "string",
|
||||
];
|
||||
public function publish_by() : string
|
||||
{
|
||||
$m = model(UserModel::class);
|
||||
$user = $m->find($this->attributes['published_by']);
|
||||
return $user->first_name." ".$user->last_name;
|
||||
}
|
||||
|
||||
}
|
||||
17
ci4/app/Entities/Wiki/WikiFileEntity.php
Normal file
17
ci4/app/Entities/Wiki/WikiFileEntity.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace App\Entities\Wiki;
|
||||
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class WikiFileEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"content_id" => null,
|
||||
"path" => null,
|
||||
];
|
||||
protected $casts = [
|
||||
"content_id" => "int",
|
||||
"path" => "string",
|
||||
];
|
||||
|
||||
}
|
||||
18
ci4/app/Entities/Wiki/WikiPageEntity.php
Normal file
18
ci4/app/Entities/Wiki/WikiPageEntity.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace App\Entities\Wiki;
|
||||
|
||||
use App\Models\Usuarios\UserModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class WikiPageEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"section_id" => null,
|
||||
];
|
||||
protected $casts = [
|
||||
"section_id" => "int",
|
||||
];
|
||||
|
||||
|
||||
|
||||
}
|
||||
94
ci4/app/Entities/Wiki/WikiSectionEntity.php
Normal file
94
ci4/app/Entities/Wiki/WikiSectionEntity.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
namespace App\Entities\Wiki;
|
||||
|
||||
use App\Models\Wiki\WikiContentModel;
|
||||
use App\Models\Wiki\WikiPageModel;
|
||||
use App\Models\Wiki\WikiSectionRoleModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class WikiSectionEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"name" => null,
|
||||
"slug" => null,
|
||||
"role" => null,
|
||||
"order" => null,
|
||||
"icon" => null,
|
||||
"parent_id" => null
|
||||
];
|
||||
protected $casts = [
|
||||
"name" => "string",
|
||||
"slug" => "string",
|
||||
"role" => "string",
|
||||
"icon" => "string",
|
||||
"order" => "int",
|
||||
"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 withRoles(): self
|
||||
{
|
||||
$m = model(WikiSectionRoleModel::class);
|
||||
$this->attributes['roles'] = $this->roles();
|
||||
return $this;
|
||||
}
|
||||
public function withRolesArray(): self
|
||||
{
|
||||
$m = model(WikiSectionRoleModel::class);
|
||||
$this->attributes['roles_array'] = $this->roles_array();
|
||||
return $this;
|
||||
}
|
||||
public function withAll(string $locale = "es") : self
|
||||
{
|
||||
$this->withPage();
|
||||
$this->withContents($locale);
|
||||
$this->withRoles();
|
||||
$this->withRolesArray();
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
public function page(): ?WikiPageEntity
|
||||
{
|
||||
$m = model(WikiPageModel::class);
|
||||
return $m->where('section_id',$this->attributes['id'])->first();
|
||||
}
|
||||
public function roles_array(): ?array
|
||||
{
|
||||
$m = model(WikiSectionRoleModel::class);
|
||||
$section_roles = $m->where('wiki_section_id',$this->attributes['id'])->findAll();
|
||||
$roles = array_map(fn($r) => $r->role,$section_roles);
|
||||
return $roles;
|
||||
}
|
||||
public function roles(): ?array
|
||||
{
|
||||
$m = model(WikiSectionRoleModel::class);
|
||||
$section_roles = $m->where('wiki_section_id',$this->attributes['id'])->findAll();
|
||||
return $section_roles;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
28
ci4/app/Entities/Wiki/WikiSectionRoleEntity.php
Normal file
28
ci4/app/Entities/Wiki/WikiSectionRoleEntity.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace App\Entities\Wiki;
|
||||
|
||||
use App\Models\Wiki\WikiContentModel;
|
||||
use App\Models\Wiki\WikiPageModel;
|
||||
use App\Models\Wiki\WikiSectionModel;
|
||||
use CodeIgniter\Entity\Entity;
|
||||
|
||||
class WikiSectionRoleEntity extends Entity
|
||||
{
|
||||
protected $attributes = [
|
||||
"wiki_section_id" => null,
|
||||
"role" => null,
|
||||
];
|
||||
protected $casts = [
|
||||
"wiki_section_id" => "int",
|
||||
"role" => "string",
|
||||
];
|
||||
|
||||
public function page(): ?WikiSectionEntity
|
||||
{
|
||||
$m = model(WikiSectionModel::class);
|
||||
return $m->where('id',$this->attributes['section_id'])->first();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user