feat: add config variable menu

This commit is contained in:
amazuecos
2024-10-02 18:32:52 +00:00
parent 8617553dea
commit 8b10aa655a
14 changed files with 599 additions and 3 deletions

View File

@ -0,0 +1,61 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
use CodeIgniter\Database\RawSql;
class ConfigVariablesApp extends Migration
{
protected array $COLUMNS = [
"id" => [
"type" => "INT",
"unsigned" => true,
"auto_increment" => true
],
"name" => [
"type" => "VARCHAR",
"constraint" => '45',
"unique" => true,
],
"value" => [
"type" => "VARCHAR",
"constraint" => '255',
"null" => true
],
"description" => [
"type" => "TEXT",
"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->createTable("config_variables_app", true);
}
public function down()
{
$this->forge->dropTable("config_variables_app");
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Database\Seeds;
use App\Models\Configuracion\ConfigVariableModel;
use CodeIgniter\Database\Seeder;
class DefaultConfigVariablesSeeder extends Seeder
{
protected array $data = [
[
"name" => "tamanio_solapas_min",
"value" => 50,
"description" => "Mínimo tamaño solapas"
],
[
"name" => "tamanio_solapas_max",
"value" => 150,
"description" => "Máximo tamaño solapas"
],
[
"name" => "limite_produccion_diaria",
"value" => 6000,
"description" => "Número de libros máximos que se puede producir al día"
],
];
public function run()
{
$variableModel = model(ConfigVariableModel::class);
foreach ($this->data as $row) {
if($variableModel->where("name",$row["name"])->first() == null){
$variableModel->insert($row);
}
}
}
}