Merge branch 'feat/wiki' into 'main'

Feat/wiki

See merge request jjimenez/safekat!581
This commit is contained in:
Alvaro
2025-03-02 09:25:35 +00:00
54 changed files with 14061 additions and 7 deletions

View File

@ -0,0 +1,74 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class WikiSectionsMigration extends Migration
{
protected array $COLUMNS = [
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'order' => [
'type' => 'INT',
'unsigned' => true,
'null'=> true,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'slug' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'icon' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => true,
],
'parent_section_id' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
],
];
public function up()
{
$this->forge->addField($this->COLUMNS);
$currenttime = new RawSql('CURRENT_TIMESTAMP');
$this->forge->addField([
'created_at' => [
'type' => 'TIMESTAMP',
'default' => $currenttime,
],
'updated_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
'deleted_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('parent_section_id','wiki_sections','id');
$this->forge->createTable("wiki_sections");
}
public function down()
{
$this->forge->dropTable("wiki_sections");
}
}

View File

@ -0,0 +1,51 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class WikiPagesMigration extends Migration
{
protected array $COLUMNS = [
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'section_id' => [
'type' => 'INT',
'unsigned' => true,
],
];
public function up()
{
$this->forge->addField($this->COLUMNS);
$currenttime = new RawSql('CURRENT_TIMESTAMP');
$this->forge->addField([
'created_at' => [
'type' => 'TIMESTAMP',
'default' => $currenttime,
],
'updated_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
'deleted_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('section_id','wiki_sections','id');
$this->forge->createTable("wiki_pages");
}
public function down()
{
$this->forge->dropTable("wiki_pages");
}
}

View File

@ -0,0 +1,83 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class WikiContentsMigration extends Migration
{
protected array $COLUMNS = [
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'locale' => [
'type' => 'VARCHAR',
'constraint' => 255,
'default' => 'es',
],
'page_id' => [
'type' => 'INT',
'unsigned' => true,
],
'editor_data' => [
'type' => 'LONGTEXT',
'null' => true,
],
'published_data' => [
'type' => 'LONGTEXT',
'null' => true,
],
'published_by' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
'constraint' => 10,
],
'last_edit_by' => [
'type' => 'INT',
'unsigned' => true,
'null' => true,
'constraint' => 10,
],
];
public function up()
{
$this->forge->addField($this->COLUMNS);
$currenttime = new RawSql('CURRENT_TIMESTAMP');
$this->forge->addField([
'published_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
'created_at' => [
'type' => 'TIMESTAMP',
'default' => $currenttime,
],
'updated_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
'deleted_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('page_id','wiki_pages','id');
$this->forge->addForeignKey('published_by','users','id');
$this->forge->addForeignKey('last_edit_by','users','id');
$this->forge->createTable("wiki_contents");
}
public function down()
{
$this->forge->dropTable("wiki_contents");
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class WikiFilesMigration extends Migration
{
protected array $COLUMNS = [
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'content_id' => [
'type' => 'INT',
'unsigned' => true,
],
'path' => [
'type' => 'LONGTEXT',
'null' => true,
],
];
public function up()
{
$this->forge->addField($this->COLUMNS);
$currenttime = new RawSql('CURRENT_TIMESTAMP');
$this->forge->addField([
'created_at' => [
'type' => 'TIMESTAMP',
'default' => $currenttime,
],
'updated_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
'deleted_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('content_id','wiki_contents','id');
$this->forge->createTable("wiki_files");
}
public function down()
{
$this->forge->dropTable("wiki_files");
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class WikiSectionRolesMigration extends Migration
{
protected array $COLUMNS = [
'id' => [
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'wiki_section_id' => [
'type' => 'INT',
'unsigned' => true,
],
'role' => [
'type' => 'VARCHAR',
'constraint' => 255,
'default' => 'admin'
],
];
public function up()
{
$this->forge->addField($this->COLUMNS);
$currenttime = new RawSql('CURRENT_TIMESTAMP');
$this->forge->addField([
'created_at' => [
'type' => 'TIMESTAMP',
'default' => $currenttime,
],
'updated_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
'deleted_at' => [
'type' => 'TIMESTAMP',
'null' => true,
],
]);
$this->forge->addPrimaryKey('id');
$this->forge->addForeignKey('wiki_section_id','wiki_sections','id');
$this->forge->createTable("wiki_section_roles");
}
public function down()
{
$this->forge->dropTable("wiki_section_roles");
}
}

View File

@ -0,0 +1,165 @@
<?php
namespace App\Database\Seeds;
use App\Models\Configuracion\ConfigVariableModel;
use App\Models\Wiki\WikiSectionModel;
use App\Models\Wiki\WikiSectionRoleModel;
use CodeIgniter\Database\Seeder;
class WikiSectionSeeder extends Seeder
{
protected array $dataAdmin = [
[
"name" => 'Introducción',
"slug" => 'intro-admin',
"icon" => 'ti ti-home-2',
"roles" => [
"admin",
],
],
[
"name" => 'Presupuesto',
"slug" => 'presupuesto-admin',
"icon" => 'ti ti-currency-dollar',
"roles" => [
"admin",
],
],
[
"name" => 'Pedidos',
"slug" => 'pedidos-admin',
"icon" => 'ti ti-file-description',
"roles" => [
"admin",
],
],
[
"name" => 'Facturación',
"slug" => 'facturacion-admin',
"icon" => 'ti ti-file-dollar',
"roles" => [
"admin",
],
],
[
"name" => 'Logística',
"slug" => 'logistica-admin',
"icon" => 'ti ti-truck',
"roles" => [
"admin",
],
],
[
"name" => 'Tarifas',
"slug" => 'tarifas-admin',
"icon" => 'ti ti-receipt',
"roles" => [
"admin",
],
],
[
"name" => 'Configuración',
"slug" => 'config-admin',
"icon" => 'ti ti-adjustments-horizontal',
"roles" => [
"admin",
],
],
[
"name" => 'Mensajería',
"slug" => 'messages-admin',
"icon" => 'ti ti-message',
"roles" => [
"admin",
],
]
];
protected array $dataCliente = [
[
"name" => 'Introducción',
"slug" => 'intro-cliente',
"icon" => 'ti ti-home-2',
"roles" => [
"cliente-admin",
"cliente-editor",
]
],
[
"name" => 'Presupuesto(Cliente)',
"slug" => 'presupuesto-cliente',
"role" => 'cliente',
"icon" => 'ti ti-currency-dollar',
"roles" => [
"cliente-admin",
"cliente-editor",
]
],
[
"name" => 'Pedidos(Cliente)',
"slug" => 'pedidos-cliente',
"icon" => 'ti ti-file-description',
"roles" => [
"cliente-admin",
"cliente-editor",
]
],
[
"name" => 'Facturación (Cliente)',
"slug" => 'facturacion-cliente',
"icon" => 'ti ti-file-dollar',
"roles" => [
"cliente-admin",
"cliente-editor",
]
],
[
"name" => 'Tarifas (Cliente)',
"slug" => 'tarifas-cliente',
"icon" => 'ti ti-receipt',
"roles" => [
"cliente-admin",
"cliente-editor",
]
],
[
"name" => 'Mensajería (Cliente)',
"slug" => 'messages-cliente',
"icon" => 'ti ti-message',
"roles" => [
"cliente-admin",
"cliente-editor",
]
]
];
public function run()
{
$wikiSectionModel = model(WikiSectionModel::class);
$wikiSectionRoleModel = model(WikiSectionRoleModel::class);
$section_order = 0;
foreach ($this->dataAdmin as $key => $row) {
$row['order'] = $section_order;
$wikiSectionId = $wikiSectionModel->insert($row);
$section_order++;
foreach ($row['roles'] as $key => $role) {
$wikiSectionRoleModel->insert(['wiki_section_id' => $wikiSectionId,"role" => $role]);
}
}
foreach ($this->dataCliente as $key => $row) {
$row['order'] = $section_order;
$wikiSectionId = $wikiSectionModel->insert($row);
$section_order++;
foreach ($row['roles'] as $key => $role) {
$wikiSectionRoleModel->insert(['wiki_section_id' => $wikiSectionId,"role" => $role]);
}
}
}
}