Merge branch 'mod/core_update' into 'main'

Mod/core update

See merge request jjimenez/safekat!230
This commit is contained in:
Ignacio Martinez Navajas
2024-05-07 08:17:21 +00:00
266 changed files with 6544 additions and 10103 deletions

View File

@ -1,20 +0,0 @@
<?php
namespace App\Models;
class ActivityModel extends BaseModel
{
protected $table = 'auth_activity';
protected $primaryKey = 'id_activity';
protected $allowedFields = [
'user',
'level',
'event',
'ip',
'os',
'browser',
'detail'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}

View File

@ -1,15 +0,0 @@
<?php
namespace App\Models;
class BackupModel extends BaseModel
{
protected $table = 'auth_backup';
protected $primaryKey = 'id_backup';
protected $allowedFields = [
'path',
'error'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}

253
ci4/app/Models/BaseModel.php Executable file → Normal file
View File

@ -1,16 +1,261 @@
<?php
/*
The MIT License (MIT)
Copyright (c) 2020 Gökhan Ozar (https://gokhan.ozar.net/)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace App\Models;
use CodeIgniter\Model;
class BaseModel extends Model
{
/**
* Description of BaseModel
*
* @author Gökhan Ozar
*/
abstract class BaseModel extends Model {
protected $afterFind = [
'escapeXSS'
'escapeXSS'
];
/**
* The name of the field (attribute) in this model which will be used to refer to as a human-friendly object name
*/
public static $labelField;
protected function escapeXSS($data)
{
return esc($data);
}
}
/**
* Returns the model's DB table name
*
* @return string
*/
public function getDbTableName() {
return $this->table;
}
/**
* Returns the model's DB table name (Alias of getDbTableName() )
*
* @return string
*/
public function getTableName() {
return $this->table;
}
/**
* Returns the model's name of primary key in the database
*
* @return string
*/
public function getPrimaryKeyName() {
return $this->primaryKey;
}
/**
* Returns the number of rows in the database table
*
* @return int
*/
public function getCount() {
$name = $this->table;
$count = $this->db->table($name)->countAll();
return $count;
}
/**
* @param string $columns2select
* @param string $resultSorting
* @param bool $onlyActiveOnes
* @param bool $alsoDeletedOnes
* @param array $additionalConditions
* @return array
*/
public function getAllForMenu($columns2select='*', $resultSorting='id', bool $onlyActiveOnes=false, bool $alsoDeletedOnes=true, $additionalConditions = []) {
$theseConditionsAreMet = [];
if ($onlyActiveOnes) {
if ( in_array('enabled', $this->allowedFields) ) {
$theseConditionsAreMet['enabled'] = true;
} elseif (in_array('active', $this->allowedFields)) {
$theseConditionsAreMet['active'] = true;
}
}
// This check is deprecated and left here only for backward compatibility and this method should be overridden in extending classes so as to check if the bound entity class has these attributes
if (!$alsoDeletedOnes) {
if (in_array('deleted_at', $this->allowedFields)) {
$theseConditionsAreMet['deleted_at'] = null;
}
if (in_array('deleted', $this->allowedFields) ) {
$theseConditionsAreMet['deleted'] = false;
}
if (in_array('date_time_deleted', $this->allowedFields)) {
$theseConditionsAreMet['date_time_deleted'] = null;
}
}
if (!empty($additionalConditions)) {
$theseConditionsAreMet = array_merge($theseConditionsAreMet, $additionalConditions);
}
$queryBuilder = $this->db->table($this->table);
$queryBuilder->select($columns2select);
if (!empty($theseConditionsAreMet)) {
$queryBuilder->where($theseConditionsAreMet);
}
$queryBuilder->orderBy($resultSorting);
$result = $queryBuilder->get()->getResult();
return $result;
}
/**
*
* @param mixed $columns2select either array or string
* @param mixed $sortResultsBy either string or array
* @param bool $onlyActiveOnes
* @param string $select1str e.g. 'Please select one...'
* @param bool $alsoDeletedOnes
* @param array $additionalConditions
* @return array for use in dropdown menus
*/
public function getAllForCiMenu( $columns2select = ['id', 'designation'], $sortResultsBy = 'id', bool $onlyActiveOnes=false, $selectionRequestLabel = 'Please select one...', bool $alsoDeletedOnes = true, $additionalConditions = []) {
$ciDropDownOptions = [];
if (is_array($columns2select) && count($columns2select) >= 2) {
$key = $columns2select[0];
$val = $columns2select[1];
$cols2selectStr = implode(',', $columns2select);
$valInd = strpos($val, ' AS ');
if ($valInd !== false) {
$val = substr($val, $valInd+4);
}
} elseif (is_string($columns2select) && strpos($columns2select,',')!==false) {
$cols2selectStr = $columns2select;
$arr = explode(",", $columns2select, 2);
$key = trim($arr[0]);
$val = trim($arr[1]);
} else {
return ['error'=>'Invalid argument for columns/fields to select'];
}
$resultList = $this->getAllForMenu($cols2selectStr, $sortResultsBy, $onlyActiveOnes, $alsoDeletedOnes, $additionalConditions);
if ($resultList != false) {
if (!empty($selectionRequestLabel)) {
$ciDropDownOptions[''] = $selectionRequestLabel;
}
foreach ($resultList as $res) {
if (isset($res->$key) && isset($res->$val)) {
$ciDropDownOptions[$res->$key] = $res->$val;
}
}
}
return $ciDropDownOptions;
}
/**
* @param array|string[] $columns2select
* @param null $resultSorting
* @param bool|bool $onlyActiveOnes
* @param null $searchStr
* @return array
*/
public function getSelect2MenuItems(array $columns2select = ['id', 'designation'], $resultSorting=null, bool $onlyActiveOnes=true, $searchStr = null, $isDeleteField=false) {
$theseConditionsAreMet = [];
$id = $columns2select[0].' AS id';
$text = $columns2select[1].' AS text';
if (empty($resultSorting)) {
$resultSorting = $this->getPrimaryKeyName();
}
if ($onlyActiveOnes) {
if ( in_array('enabled', $this->allowedFields) ) {
$theseConditionsAreMet['enabled'] = true;
} elseif (in_array('active', $this->allowedFields)) {
$theseConditionsAreMet['active'] = true;
}
}
//JJO
if($isDeleteField)
$theseConditionsAreMet['is_deleted'] = 0;
$queryBuilder = $this->db->table($this->table);
$queryBuilder->select([$id, $text]);
$queryBuilder->where($theseConditionsAreMet);
if (!empty($searchStr)) {
$queryBuilder->groupStart()
->like($columns2select[0], $searchStr)
->orLike($columns2select[1], $searchStr)
->groupEnd();
}
$queryBuilder->orderBy($resultSorting);
$result = $queryBuilder->get()->getResult();
return $result;
}
/**
* Custom method allowing you to add a form validation rule to the model on-the-fly
* @param string $fieldName
* @param string $rule
* @param string|null $msg
*/
public function addValidationRule(string $fieldName, string $rule, string $msg = null ) {
if (empty(trim($fieldName)) ||empty(trim($fieldName))) {
return;
}
if (!isset($this->validationRules[$fieldName]) || empty($this->validationRules[$fieldName])) {
$this->validationRules[$fieldName] = substr($rule, 0, 1) == '|' ? substr($rule, 1) : trim($rule);
} else if (isset($this->validationRules[$fieldName]['rules'])) {
$this->validationRules[$fieldName]['rules'] .= substr($rule, 0, 1) == '|' ? trim($rule) : '|' . trim($rule);
} else {
$this->validationRules[$fieldName] .= $rule;
}
if (isset($msg) && !empty(trim($msg))) {
$ruleKey = strtok($rule, '[');
if ($ruleKey === false) {
return;
}
$item = [$ruleKey => "'".$msg."'"];
if (!isset($this->validationMessages[$fieldName]) || empty(trim($this->validationMessages[$fieldName]))) {
$this->validationMessages[$fieldName] = $item;
} else {
$this->validationMessages[$fieldName][$ruleKey] = "'".$msg."'";
}
}
}
}

View File

@ -2,7 +2,7 @@
namespace App\Models\Clientes;
class ClienteContactoModel extends \App\Models\GoBaseModel
class ClienteContactoModel extends \App\Models\BaseModel
{
protected $table = "cliente_contactos";

View File

@ -2,7 +2,7 @@
namespace App\Models\Clientes;
class ClienteDireccionesModel extends \App\Models\GoBaseModel
class ClienteDireccionesModel extends \App\Models\BaseModel
{
protected $table = "cliente_direcciones";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Clientes;
class ClienteModel extends \App\Models\GoBaseModel
class ClienteModel extends \App\Models\BaseModel
{
protected $table = "clientes";
@ -249,9 +249,15 @@ class ClienteModel extends \App\Models\GoBaseModel
$sql =
"SELECT t1." .
$selcols .
", t2.nombre AS comunidad_autonoma_id, t3.nombre AS provincia, t4.nombre AS pais_id, t5.first_name AS comercial, t6.last_name AS soporte, t7.nombre AS forma_pago_id FROM " .
", t2.nombre AS comunidad_autonoma_id, t3.nombre AS provincia, t4.nombre AS pais_id, t5.first_name AS comercial,
t6.last_name AS soporte, t7.nombre AS forma_pago_id FROM " .
$this->table .
" t1 LEFT JOIN lg_comunidades_autonomas t2 ON t1.comunidad_autonoma_id = t2.id LEFT JOIN lg_provincias t3 ON t1.provincia_id = t3.id LEFT JOIN lg_paises t4 ON t1.pais_id = t4.id LEFT JOIN auth_user t5 ON t1.comercial_id = t5.id_user LEFT JOIN auth_user t6 ON t1.soporte_id = t6.id_user LEFT JOIN lg_formas_pago t7 ON t1.forma_pago_id = t7.id";
" t1 LEFT JOIN lg_comunidades_autonomas t2 ON t1.comunidad_autonoma_id = t2.id
LEFT JOIN lg_provincias t3 ON t1.provincia_id = t3.id
LEFT JOIN lg_paises t4 ON t1.pais_id = t4.id
LEFT JOIN users t5 ON t1.comercial_id = t5.id
LEFT JOIN users t6 ON t1.soporte_id = t6.id
LEFT JOIN lg_formas_pago t7 ON t1.forma_pago_id = t7.id";
if (!is_null($limit) && intval($limit) > 0) {
$sql .= " LIMIT " . intval($limit);
}
@ -280,7 +286,7 @@ class ClienteModel extends \App\Models\GoBaseModel
"t1.id AS id, t1.nombre AS nombre, t1.alias AS alias, t1.cif AS cif, t1.email AS email, t1.vencimiento AS vencimiento, t5.first_name AS comercial, t7.nombre AS forma_pago_id"
)
->where("is_deleted", 0);;
$builder->join("auth_user t5", "t1.comercial_id = t5.id_user", "left");
$builder->join("users t5", "t1.comercial_id = t5.id", "left");
$builder->join("lg_formas_pago t7", "t1.forma_pago_id = t7.id", "left");

View File

@ -2,7 +2,7 @@
namespace App\Models\Clientes;
class ClientePlantillaPreciosLineasModel extends \App\Models\GoBaseModel
class ClientePlantillaPreciosLineasModel extends \App\Models\BaseModel
{
protected $table = "cliente_plantilla_precios_lineas";
@ -137,7 +137,7 @@ class ClientePlantillaPreciosLineasModel extends \App\Models\GoBaseModel
t1.user_updated_id AS user_updated_id, t1.updated_at AS updated_at, CONCAT(t2.first_name, ' ', t2.last_name) AS user_updated"
);
$builder->join("auth_user t2", "t1.user_updated_id = t2.id_user", "left");
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
$builder->where('t1.is_deleted', 0);
$builder->where('t1.plantilla_id', $plantilla_id);

View File

@ -2,7 +2,7 @@
namespace App\Models\Clientes;
class ClientePlantillaPreciosModel extends \App\Models\GoBaseModel
class ClientePlantillaPreciosModel extends \App\Models\BaseModel
{
protected $table = "cliente_plantilla_precios";

View File

@ -2,7 +2,7 @@
namespace App\Models\Clientes;
class ClientePreciosModel extends \App\Models\GoBaseModel
class ClientePreciosModel extends \App\Models\BaseModel
{
protected $table = "cliente_precios";
@ -267,7 +267,7 @@ class ClientePreciosModel extends \App\Models\GoBaseModel
t1.user_updated_id AS user_updated_id, t1.updated_at AS updated_at, CONCAT(t2.first_name, ' ', t2.last_name) AS user_updated"
);
$builder->join("auth_user t2", "t1.user_updated_id = t2.id_user", "left");
$builder->join("users t2", "t1.user_updated_id = t2.id", "left");
$builder->where('t1.is_deleted', 0);
$builder->where('t1.cliente_id', $cliente_id);

View File

@ -2,7 +2,7 @@
namespace App\Models\Clientes;
class ClienteUsuariosModel extends \App\Models\GoBaseModel
class ClienteUsuariosModel extends \App\Models\BaseModel
{
protected $table = "auth_user";

View File

@ -0,0 +1,39 @@
<?php
namespace App\Models;
class CollectionModel
{
/**
* Generate a data table response.
*
* @param array $data The data to be displayed in the table.
* @param int $recordsTotal The total number of records without filtering.
* @param int $recordsFiltered The total number of records after filtering.
* @param string|null $error An optional error message to be included in the response.
* @return array The data table response containing the draw count, total records, filtered records,
* the data, and a CSRF token (in case it is regenerated).
*/
public static function datatable(array $data, int $recordsTotal, int $recordsFiltered, string $error = null)
{
$req = service('request');
$reqData = $req->getPostGet('data') ?? [];
$draw = $reqData['draw'] ?? $req->getPostGet('draw') ?? 1;
$response = [
'draw' => $draw,
'recordsTotal' => $recordsTotal,
'recordsFiltered' => $recordsFiltered,
'data' => $data,
'token' => csrf_hash(), // in case the CSRF token is regenerated
];
if (!empty($error)) {
$response['error'] = $error;
}
return $response;
}
}

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Compras;
class ProveedorModel extends \App\Models\GoBaseModel
class ProveedorModel extends \App\Models\BaseModel
{
protected $table = "lg_proveedores";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Compras;
class ProveedorTipoModel extends \App\Models\GoBaseModel
class ProveedorTipoModel extends \App\Models\BaseModel
{
protected $table = "lg_proveedores_tipos";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class ComunidadAutonomaModel extends \App\Models\GoBaseModel
class ComunidadAutonomaModel extends \App\Models\BaseModel
{
protected $table = "lg_comunidades_autonomas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class ConfiguracionSistemaModel extends \App\Models\GoBaseModel
class ConfiguracionSistemaModel extends \App\Models\BaseModel
{
protected $table = "configuracion_sistema";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class FormaPagoModel extends \App\Models\GoBaseModel
class FormaPagoModel extends \App\Models\BaseModel
{
protected $table = "lg_formas_pago";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class ImposicionModel extends \App\Models\GoBaseModel
class ImposicionModel extends \App\Models\BaseModel
{
protected $table = "lg_imposiciones";

View File

@ -2,7 +2,7 @@
namespace App\Models\Configuracion;
class MaquinaModel extends \App\Models\GoBaseModel
class MaquinaModel extends \App\Models\BaseModel
{
protected $table = "lg_maquinas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class MaquinasCallesModel extends \App\Models\GoBaseModel
class MaquinasCallesModel extends \App\Models\BaseModel
{
protected $table = "maquinas_calles";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class MaquinasDefectoModel extends \App\Models\GoBaseModel
class MaquinasDefectoModel extends \App\Models\BaseModel
{
protected $table = "lg_maquina_por_defecto";

View File

@ -3,7 +3,7 @@ namespace App\Models\Configuracion;
use CodeIgniter\Database\RawSql;
class MaquinasPapelesImpresionModel extends \App\Models\GoBaseModel
class MaquinasPapelesImpresionModel extends \App\Models\BaseModel
{
protected $table = "lg_maquina_papel_impresion";

View File

@ -2,7 +2,7 @@
namespace App\Models\Configuracion;
class MaquinasTarifasImpresionModel extends \App\Models\GoBaseModel
class MaquinasTarifasImpresionModel extends \App\Models\BaseModel
{
protected $table = "lg_maquinas_tarifas_impresion";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class PaisModel extends \App\Models\GoBaseModel
class PaisModel extends \App\Models\BaseModel
{
protected $table = "lg_paises";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class PapelFormatoModel extends \App\Models\GoBaseModel
class PapelFormatoModel extends \App\Models\BaseModel
{
protected $table = "lg_papel_formato";

View File

@ -2,7 +2,7 @@
namespace App\Models\Configuracion;
class PapelGenericoModel extends \App\Models\GoBaseModel
class PapelGenericoModel extends \App\Models\BaseModel
{
protected $table = "lg_papel_generico";

View File

@ -2,7 +2,7 @@
namespace App\Models\Configuracion;
class PapelImpresionMargenModel extends \App\Models\GoBaseModel
class PapelImpresionMargenModel extends \App\Models\BaseModel
{
protected $table = "papel_impresion_margenes";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class PapelImpresionModel extends \App\Models\GoBaseModel
class PapelImpresionModel extends \App\Models\BaseModel
{
protected $table = "lg_papel_impresion";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class PapelImpresionTipologiaModel extends \App\Models\GoBaseModel
class PapelImpresionTipologiaModel extends \App\Models\BaseModel
{
protected $table = "lg_papel_impresion_tipologias";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class ProvinciaModel extends \App\Models\GoBaseModel
class ProvinciaModel extends \App\Models\BaseModel
{
protected $table = "lg_provincias";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class TipoPresupuestoModel extends \App\Models\GoBaseModel
class TipoPresupuestoModel extends \App\Models\BaseModel
{
protected $table = "tipos_presupuestos";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Configuracion;
class TipologiasLibroModel extends \App\Models\GoBaseModel
class TipologiasLibroModel extends \App\Models\BaseModel
{
protected $table = "lg_tipologias_libros";

View File

@ -1,17 +0,0 @@
<?php
namespace App\Models;
class ConfirmationTokenModel extends BaseModel
{
protected $table = 'auth_confirmation_token';
protected $primaryKey = 'id_confirmation';
protected $allowedFields = [
'user',
'token',
'confirmed',
'type'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}

View File

@ -1,20 +0,0 @@
<?php
namespace App\Models;
class CountriesModel extends BaseModel
{
protected $table = 'auth_countries';
protected $primaryKey = 'id_country';
protected $allowedFields = [
'phone',
'code',
'name',
'symbol',
'capital',
'currency',
'continent',
'continent_code',
'alpha_3',
'data_lang'
];
}

View File

@ -1,15 +0,0 @@
<?php
namespace App\Models;
class CronTabModel extends BaseModel
{
protected $table = 'auth_crontab_history';
protected $primaryKey = 'id_crontab';
protected $allowedFields = [
'routine',
'error'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}

View File

@ -1,13 +0,0 @@
<?php
namespace App\Models;
class CurrencyModel extends BaseModel
{
protected $table = 'auth_currency';
protected $primaryKey = 'id_currency';
protected $allowedFields = [
'code',
'name',
'data_lang'
];
}

View File

@ -1,252 +0,0 @@
<?php
/*
The MIT License (MIT)
Copyright (c) 2020 Gökhan Ozar (https://gokhan.ozar.net/)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace App\Models;
use CodeIgniter\Model;
/**
* Description of GoBaseModel
*
* @author Gökhan Ozar
*/
abstract class GoBaseModel extends Model {
/**
* The name of the field (attribute) in this model which will be used to refer to as a human-friendly object name
*/
public static $labelField;
/**
* Returns the model's DB table name
*
* @return string
*/
public function getDbTableName() {
return $this->table;
}
/**
* Returns the model's DB table name (Alias of getDbTableName() )
*
* @return string
*/
public function getTableName() {
return $this->table;
}
/**
* Returns the model's name of primary key in the database
*
* @return string
*/
public function getPrimaryKeyName() {
return $this->primaryKey;
}
/**
* Returns the number of rows in the database table
*
* @return int
*/
public function getCount() {
$name = $this->table;
$count = $this->db->table($name)->countAll();
return $count;
}
/**
* @param string $columns2select
* @param string $resultSorting
* @param bool $onlyActiveOnes
* @param bool $alsoDeletedOnes
* @param array $additionalConditions
* @return array
*/
public function getAllForMenu($columns2select='*', $resultSorting='id', bool $onlyActiveOnes=false, bool $alsoDeletedOnes=true, $additionalConditions = []) {
$theseConditionsAreMet = [];
if ($onlyActiveOnes) {
if ( in_array('enabled', $this->allowedFields) ) {
$theseConditionsAreMet['enabled'] = true;
} elseif (in_array('active', $this->allowedFields)) {
$theseConditionsAreMet['active'] = true;
}
}
// This check is deprecated and left here only for backward compatibility and this method should be overridden in extending classes so as to check if the bound entity class has these attributes
if (!$alsoDeletedOnes) {
if (in_array('deleted_at', $this->allowedFields)) {
$theseConditionsAreMet['deleted_at'] = null;
}
if (in_array('deleted', $this->allowedFields) ) {
$theseConditionsAreMet['deleted'] = false;
}
if (in_array('date_time_deleted', $this->allowedFields)) {
$theseConditionsAreMet['date_time_deleted'] = null;
}
}
if (!empty($additionalConditions)) {
$theseConditionsAreMet = array_merge($theseConditionsAreMet, $additionalConditions);
}
$queryBuilder = $this->db->table($this->table);
$queryBuilder->select($columns2select);
if (!empty($theseConditionsAreMet)) {
$queryBuilder->where($theseConditionsAreMet);
}
$queryBuilder->orderBy($resultSorting);
$result = $queryBuilder->get()->getResult();
return $result;
}
/**
*
* @param mixed $columns2select either array or string
* @param mixed $sortResultsBy either string or array
* @param bool $onlyActiveOnes
* @param string $select1str e.g. 'Please select one...'
* @param bool $alsoDeletedOnes
* @param array $additionalConditions
* @return array for use in dropdown menus
*/
public function getAllForCiMenu( $columns2select = ['id', 'designation'], $sortResultsBy = 'id', bool $onlyActiveOnes=false, $selectionRequestLabel = 'Please select one...', bool $alsoDeletedOnes = true, $additionalConditions = []) {
$ciDropDownOptions = [];
if (is_array($columns2select) && count($columns2select) >= 2) {
$key = $columns2select[0];
$val = $columns2select[1];
$cols2selectStr = implode(',', $columns2select);
$valInd = strpos($val, ' AS ');
if ($valInd !== false) {
$val = substr($val, $valInd+4);
}
} elseif (is_string($columns2select) && strpos($columns2select,',')!==false) {
$cols2selectStr = $columns2select;
$arr = explode(",", $columns2select, 2);
$key = trim($arr[0]);
$val = trim($arr[1]);
} else {
return ['error'=>'Invalid argument for columns/fields to select'];
}
$resultList = $this->getAllForMenu($cols2selectStr, $sortResultsBy, $onlyActiveOnes, $alsoDeletedOnes, $additionalConditions);
if ($resultList != false) {
if (!empty($selectionRequestLabel)) {
$ciDropDownOptions[''] = $selectionRequestLabel;
}
foreach ($resultList as $res) {
if (isset($res->$key) && isset($res->$val)) {
$ciDropDownOptions[$res->$key] = $res->$val;
}
}
}
return $ciDropDownOptions;
}
/**
* @param array|string[] $columns2select
* @param null $resultSorting
* @param bool|bool $onlyActiveOnes
* @param null $searchStr
* @return array
*/
public function getSelect2MenuItems(array $columns2select = ['id', 'designation'], $resultSorting=null, bool $onlyActiveOnes=true, $searchStr = null, $isDeleteField=false) {
$theseConditionsAreMet = [];
$id = $columns2select[0].' AS id';
$text = $columns2select[1].' AS text';
if (empty($resultSorting)) {
$resultSorting = $this->getPrimaryKeyName();
}
if ($onlyActiveOnes) {
if ( in_array('enabled', $this->allowedFields) ) {
$theseConditionsAreMet['enabled'] = true;
} elseif (in_array('active', $this->allowedFields)) {
$theseConditionsAreMet['active'] = true;
}
}
//JJO
if($isDeleteField)
$theseConditionsAreMet['is_deleted'] = 0;
$queryBuilder = $this->db->table($this->table);
$queryBuilder->select([$id, $text]);
$queryBuilder->where($theseConditionsAreMet);
if (!empty($searchStr)) {
$queryBuilder->groupStart()
->like($columns2select[0], $searchStr)
->orLike($columns2select[1], $searchStr)
->groupEnd();
}
$queryBuilder->orderBy($resultSorting);
$result = $queryBuilder->get()->getResult();
return $result;
}
/**
* Custom method allowing you to add a form validation rule to the model on-the-fly
* @param string $fieldName
* @param string $rule
* @param string|null $msg
*/
public function addValidationRule(string $fieldName, string $rule, string $msg = null ) {
if (empty(trim($fieldName)) ||empty(trim($fieldName))) {
return;
}
if (!isset($this->validationRules[$fieldName]) || empty($this->validationRules[$fieldName])) {
$this->validationRules[$fieldName] = substr($rule, 0, 1) == '|' ? substr($rule, 1) : trim($rule);
} else if (isset($this->validationRules[$fieldName]['rules'])) {
$this->validationRules[$fieldName]['rules'] .= substr($rule, 0, 1) == '|' ? trim($rule) : '|' . trim($rule);
} else {
$this->validationRules[$fieldName] .= $rule;
}
if (isset($msg) && !empty(trim($msg))) {
$ruleKey = strtok($rule, '[');
if ($ruleKey === false) {
return;
}
$item = [$ruleKey => "'".$msg."'"];
if (!isset($this->validationMessages[$fieldName]) || empty(trim($this->validationMessages[$fieldName]))) {
$this->validationMessages[$fieldName] = $item;
} else {
$this->validationMessages[$fieldName][$ruleKey] = "'".$msg."'";
}
}
}
}

View File

@ -1,21 +0,0 @@
<?php
namespace App\Models;
class NotificationModel extends BaseModel
{
protected $table = 'auth_notification';
protected $primaryKey = 'id_notification';
protected $allowedFields = [
'user_sender',
'user_recipient',
'title',
'body',
'is_read',
'is_send_email',
'send_email_notification',
'token'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}

View File

@ -1,17 +0,0 @@
<?php
namespace App\Models;
class PasswordRecoveryModel extends BaseModel
{
protected $table = 'auth_password_recovery';
protected $primaryKey = 'id_pass_recovery';
protected $allowedFields = [
'user',
'token',
'changed'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
}

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class BuscadorModel extends \App\Models\GoBaseModel
class BuscadorModel extends \App\Models\BaseModel
{
protected $table = "presupuestos";
@ -132,7 +132,7 @@ class BuscadorModel extends \App\Models\GoBaseModel
t6.estado AS estado"
);
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
$builder->join("auth_user t3", "t1.user_update_id = t3.id_user", "left");
$builder->join("users t3", "t1.user_update_id = t3.id", "left");
$builder->join("lg_paises t5", "t1.pais_id = t5.id", "left");
$builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left");
$builder->join("tipos_presupuestos t7", "t1.tipo_impresion_id = t7.id", "left");

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoAcabadosModel extends \App\Models\GoBaseModel
class PresupuestoAcabadosModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_acabados";

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoDireccionesModel extends \App\Models\GoBaseModel
class PresupuestoDireccionesModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_direcciones";

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoEncuadernacionesModel extends \App\Models\GoBaseModel
class PresupuestoEncuadernacionesModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_encuadernaciones";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Presupuestos;
class PresupuestoEstadoModel extends \App\Models\GoBaseModel
class PresupuestoEstadoModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_estados";

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoLineaModel extends \App\Models\GoBaseModel
class PresupuestoLineaModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_linea";

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoManipuladosModel extends \App\Models\GoBaseModel
class PresupuestoManipuladosModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_manipulados";

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoModel extends \App\Models\GoBaseModel
class PresupuestoModel extends \App\Models\BaseModel
{
protected $table = "presupuestos";
@ -205,8 +205,8 @@ class PresupuestoModel extends \App\Models\GoBaseModel
t6 ON t1.pais_id = t6.id = t7.id LEFT JOIN presupuesto_estados
t7 ON t1.estado_id = t8.id LEFT JOIN lg_papel_formato
t8 ON t1.papel_formato_id = t9.id LEFT JOIN lg_papel_generico
t9 ON t1.total_confirmado_user_id = t26.id_user LEFT JOIN auth_user
t10 ON t1.aprobado_user_id = t27.id_user LEFT JOIN auth_user";
t9 ON t1.total_confirmado_user_id = t26.id LEFT JOIN users
t10 ON t1.aprobado_user_id = t27.id LEFT JOIN users";
if (!is_null($limit) && intval($limit) > 0) {
$sql .= " LIMIT " . intval($limit);
@ -239,7 +239,7 @@ class PresupuestoModel extends \App\Models\GoBaseModel
t1.total_presupuesto AS total_presupuesto, t1.total_presupuesto AS total_presupuesto, t6.estado AS estado"
);
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
$builder->join("auth_user t3", "t1.user_update_id = t3.id_user", "left");
$builder->join("users t3", "t1.user_update_id = t3.id", "left");
$builder->join("lg_paises t5", "t1.pais_id = t5.id", "left");
$builder->join("presupuesto_estados t6", "t1.estado_id = t6.id", "left");
@ -299,7 +299,7 @@ class PresupuestoModel extends \App\Models\GoBaseModel
CONCAT(t4.ancho, 'x', t4.alto) AS formato"
);
$builder->join("clientes t2", "t1.cliente_id = t2.id", "left");
$builder->join("auth_user t3", "t1.user_update_id = t3.id_user", "left");
$builder->join("users t3", "t1.user_update_id = t3.id", "left");
$builder->join("lg_papel_formato t4", "t1.papel_formato_id = t4.id", "left");
$builder->where("t1.is_deleted", 0);

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoPreimpresionesModel extends \App\Models\GoBaseModel
class PresupuestoPreimpresionesModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_preimpresiones";

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class PresupuestoServiciosExtraModel extends \App\Models\GoBaseModel
class PresupuestoServiciosExtraModel extends \App\Models\BaseModel
{
protected $table = "presupuesto_serviciosExtra";

View File

@ -2,7 +2,7 @@
namespace App\Models\Presupuestos;
class TipoPresupuestoServiciosDefectoModel extends \App\Models\GoBaseModel
class TipoPresupuestoServiciosDefectoModel extends \App\Models\BaseModel
{
protected $table = "tipos_presupuestos_servicios_defecto";

View File

@ -1,82 +0,0 @@
<?php
namespace App\Models;
class SettingsModel extends BaseModel
{
protected $table = 'auth_settings';
protected $primaryKey = 'id_settings';
protected $allowedFields = [
'title',
'activate_frontend',
'logo',
'icon',
'default_language',
'default_role',
'default_date_format',
'default_hour_format',
'default_currency',
'default_currency_position',
'default_currency_separation',
'default_country',
'default_theme',
'default_theme_front',
'default_timezone',
'seo_description',
'seo_keywords',
'email_gateway',
'email_name',
'email_address',
'email_smtp',
'email_port',
'email_pass',
'email_cert',
'email_account_id',
'email_auth_token',
'email_info_add',
'captcha_gateway',
'captcha_site_key',
'captcha_secret_key',
'captcha_register',
'captcha_login',
'captcha_recovery',
'registration',
'terms_conditions',
'terms_conditions_text',
'email_confirmation',
'send_user_register',
'send_email_register',
'send_notification_register',
'send_email_welcome',
'remember_me',
'forgot_password',
'two_factor_auth',
'throttle_auth',
'throttle_auth_max_attempts',
'throttle_auth_lockour_time',
'jwt_token_lifetime',
'jwt_private_key',
'group_api',
'block_external_api',
'ip_allowed_api',
'enable_api',
'remove_log',
'remove_log_time',
'remove_log_latest',
'storage_gateway',
'aws_endpoint',
'aws_key',
'aws_secret',
'aws_region',
'aws_bucket',
'backup_storage',
'backup_table',
'backup_email',
'backup_notification_email',
'backup_automatic',
'backup_time',
'backup_latest',
'purchase_code'
];
protected $useTimestamps = true;
protected $updatedField = 'updated_at';
}

View File

@ -0,0 +1,100 @@
<?php
namespace App\Models\Sistema;
use App\Models\BaseModel;
class ActivityModel extends BaseModel
{
protected $table = 'auth_activity';
protected $primaryKey = 'id';
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
protected $returnType = "App\Entities\Sistema\ActivityEntity";
const SORTABLE = [
1 => "t1.id",
2 => "t2.username",
3 => "t1.level",
4 => "t1.event",
5 => "t1.ip",
6 => "t1.os",
7 => "t1.browser",
8 => "t1.detail"
];
protected $allowedFields = [
'user_id',
'level',
'event',
'ip',
'os',
'browser',
'detail'
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
/**
* Retrieves a resource from the database based on the given search string.
*
* @param string $search The search string to filter the resource by. Defaults to an empty string.
* @return mixed The resource query builder instance if search string is empty, otherwise the filtered resource query builder instance.
*/
public function getResource(string $search = "")
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t2.username AS user, t1.level AS level, t1.event AS event, t1.ip AS ip, t1.os AS os,
t1.browser AS browser, t1.created_at AS created_at"
)
->join("users t2", "t1.user_id = t2.id", "left")
->orderBy('t1.created_at', 'DESC');
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orLike("t2.username", $search)
->orLike("t1.level", $search)
->orLike("t1.event", $search)
->orLike("t1.ip", $search)
->orLike("t1.os", $search)
->orLike("t1.browser", $search)
->orLike("t1.created_at", $search)
->groupEnd();
}
public function getLogs()
{
$builder = $this->db
->table($this->table . " t1")
->select(
'SUM( IF( os LIKE "%Windows%", 1, 0 ) ) AS windows,
SUM( IF( os = "Mac OS X", 1, 0 ) ) AS mac,
SUM( IF( os = "Linux", 1, 0 ) ) AS linux,
SUM( IF( os = "Android", 1, 0 ) ) AS android,
SUM( IF( os = "iOS", 1, 0 ) ) AS iphone,
SUM( IF( browser LIKE "%Chrome%", 1, 0 ) ) AS chrome,
SUM( IF( browser LIKE "%Firefox%", 1, 0 ) ) AS firefox,
SUM( IF( browser LIKE "%Safari%", 1, 0 ) ) AS safari,
SUM( IF( browser LIKE "%Internet Explorer%", 1, 0 ) ) AS ie,
SUM( IF( browser LIKE "%Edge%", 1, 0 ) ) AS edge,
SUM( IF( browser LIKE "%Opera%", 1, 0 ) ) AS opera'
);
return $builder;
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace App\Models\Sistema;
use App\Models\BaseModel;
class SettingsModel extends BaseModel
{
protected $table = 'auth_settings';
protected $primaryKey = 'id';
protected $returnType = "App\Entities\Sistema\SettingsEntity";
const SORTABLE = [
];
protected $allowedFields = [
'email_gateway',
'email_name',
'email_address',
'email_smtp',
'email_port',
'email_pass',
'email_cert',
'remove_log',
'remove_log_time',
'remove_log_latest',
'storage_gateway',
'backup_storage',
'backup_table',
'backup_email',
'backup_notification_email',
'backup_automatic',
'backup_time',
'backup_latest'
];
protected $useTimestamps = true;
protected $updatedField = 'updated_at';
}

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaAcabadoLineaModel extends \App\Models\GoBaseModel
class TarifaAcabadoLineaModel extends \App\Models\BaseModel
{
protected $table = "tarifa_acabado_lineas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEncuadernacionDimensionesModel extends \App\Models\GoBaseModel
class TarifaEncuadernacionDimensionesModel extends \App\Models\BaseModel
{
protected $table = "tarifa_encuadernacion_dimensiones";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEncuadernacionLineaHorasModel extends \App\Models\GoBaseModel
class TarifaEncuadernacionLineaHorasModel extends \App\Models\BaseModel
{
protected $table = "tarifa_encuadernacion_lineas_horas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEncuadernacionLineaModel extends \App\Models\GoBaseModel
class TarifaEncuadernacionLineaModel extends \App\Models\BaseModel
{
protected $table = "tarifa_encuadernacion_lineas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEncuadernacionModel extends \App\Models\GoBaseModel
class TarifaEncuadernacionModel extends \App\Models\BaseModel
{
protected $table = "tarifa_encuadernacion";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEncuadernacionTiradaModel extends \App\Models\GoBaseModel
class TarifaEncuadernacionTiradaModel extends \App\Models\BaseModel
{
protected $table = "tarifa_encuadernacion_tiradas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEnvioModel extends \App\Models\GoBaseModel
class TarifaEnvioModel extends \App\Models\BaseModel
{
protected $table = "lg_tarifas_envios";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEnvioPrecioModel extends \App\Models\GoBaseModel
class TarifaEnvioPrecioModel extends \App\Models\BaseModel
{
protected $table = "tarifas_envios_precios";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaEnvioZonaModel extends \App\Models\GoBaseModel
class TarifaEnvioZonaModel extends \App\Models\BaseModel
{
protected $table = "tarifas_envios_zonas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaManipuladoLineaModel extends \App\Models\GoBaseModel
class TarifaManipuladoLineaModel extends \App\Models\BaseModel
{
protected $table = "tarifa_manipulado_lineas";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaManipuladoModel extends \App\Models\GoBaseModel
class TarifaManipuladoModel extends \App\Models\BaseModel
{
protected $table = "lg_tarifa_manipulado";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\tarifas;
class TarifaacabadoModel extends \App\Models\GoBaseModel
class TarifaacabadoModel extends \App\Models\BaseModel
{
protected $table = "lg_tarifa_acabado";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifaextraModel extends \App\Models\GoBaseModel
class TarifaextraModel extends \App\Models\BaseModel
{
protected $table = "tarifa_extra";

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Tarifas;
class TarifapreimpresionModel extends \App\Models\GoBaseModel
class TarifapreimpresionModel extends \App\Models\BaseModel
{
protected $table = "lg_tarifa_preimpresion";

View File

@ -1,16 +0,0 @@
<?php
namespace App\Models;
class TemplateModel extends BaseModel
{
protected $table = 'auth_template';
protected $primaryKey = 'id_template';
protected $allowedFields = [
'name',
'subject',
'body',
'type'
];
protected $useTimestamps = true;
protected $updatedField = 'updated_at';
}

View File

@ -1,13 +0,0 @@
<?php
namespace App\Models;
class ThemeModel extends BaseModel
{
protected $table = 'auth_theme';
protected $primaryKey = 'id_theme';
protected $allowedFields = [
'name',
'type',
'path'
];
}

View File

@ -1,12 +0,0 @@
<?php
namespace App\Models;
class TimezoneModel extends BaseModel
{
protected $table = 'auth_timezone';
protected $primaryKey = 'id_timezone';
protected $allowedFields = [
'timezone',
'description'
];
}

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace App\Models;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
class UserModel extends ShieldUserModel
{
protected function initialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'first_name', // Añadido
'last_name', // Añadido
];
}
}

View File

@ -0,0 +1,155 @@
<?php
namespace App\Models\Usuarios;
class GroupModel extends \App\Models\BaseModel
{
protected $table = "auth_groups";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
protected $primaryKey = "id";
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
const SORTABLE = [
1 => "t1.id",
2 => "t1.keyword",
3 => "t1.title",
4 => "t1.description",
5 => "t1.rules",
6 => "t1.created_at",
7 => "t1.updated_at",
];
protected $allowedFields = ["id", "keyword", "title", "description", "rules"];
protected $returnType = "App\Entities\Usuarios\GroupEntity";
public static $labelField = "title";
protected $validationRules = [
"description" => [
"label" => "RolesPermisos.description",
"rules" => "max_length[150]",
],
"title" => [
"label" => "RolesPermisos.title",
"rules" => "required|max_length[50]",
],
];
protected $validationMessages = [
"description" => [
"max_length" => "RolesPermisos.validation.description.max_length",
"required" => "RolesPermisos.validation.description.required",
],
"title" => [
"max_length" => "RolesPermisos.validation.title.max_length",
"required" => "RolesPermisos.validation.title.required",
],
];
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "")
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id AS id, t1.keyword AS keyword, t1.title AS title, t1.description AS description, t1.rules AS rules,
t1.token AS token, t1.created_at AS created_at, t1.updated_at AS updated_at"
);
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id", $search)
->orLike("t1.keyword", $search)
->orLike("t1.title", $search)
->orLike("t1.description", $search)
->orLike("t1.rules", $search)
->orLike("t1.created_at", $search)
->orLike("t1.updated_at", $search)
->groupEnd();
}
public function getUsersWithRol($groupKeyWord)
{
return $this->db
->table('auth_groups_users')
->select('user_id')
->where('group', $groupKeyWord)
->countAllResults();
}
public function getRolPermissionList($rolId)
{
$rolRecord = $this->find($rolId);
$result = [];
foreach ($rolRecord->rules as $section => $permissions) {
if (!is_null($permissions)) {
foreach ($permissions as $permission) {
$result[$section . "." . $permission] = "Can " . $permission;
}
// Add menu visibility permission (automatic management)
$result[$section . ".menu"] = "Menu shall be visualize";
}
}
return $result;
}
public function getRolesPermissionMatrix()
{
$rolesRecord = $this->findAll();
$result = [];
foreach ($rolesRecord as $rolRecord) {
$rolePermissions = [];
foreach ($rolRecord->rules as $section => $permissions) {
foreach ($permissions as $permission) {
$rolePermissions[] = $section . "." . $permission;
}
// Add menu visibility permission (automatic management)
$rolePermissions[] = $section . ".menu";
}
$result[$rolRecord->keyword] = $rolePermissions;
}
return $result;
}
public function getRolesList()
{
$rolesRecord = $this->findAll();
$result = [];
foreach ($rolesRecord as $rolRecord) {
$result[$rolRecord->keyword] = array(
'title' => $rolRecord->title,
'description' => $rolRecord->description
);
}
return $result;
}
}

View File

@ -1,19 +0,0 @@
<?php
namespace App\Models\Usuarios;
use App\Models\BaseModel;
class GroupUserModel extends BaseModel
{
protected $table = 'group_user';
protected $allowedFields = [
'token_user',
'token_group'
];
public function getUsersWithRol($token_group){
$result = $this->select('token_user')->where('token_group', $token_group)->countAllResults();
return $result;
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace App\Models\Usuarios;
class PermisosModel extends \App\Models\BaseModel
{
protected $table = "auth_permissions";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
protected $primaryKey = "id";
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
const SORTABLE = [
1 => "t1.id",
2 => "t1.keyword",
3 => "t1.name",
4 => "t1.description",
5 => "t1.rules",
6 => "t1.created_at",
7 => "t1.updated_at",
];
protected $allowedFields = ["id", "keyword", "name", "description", "rules"];
protected $returnType = "App\Entities\Usuarios\PermisosEntity";
public static $labelField = "name";
protected $validationRules = [
"description" => [
"label" => "UserGroups.description",
"rules" => "max_length[150]",
],
"name" => [
"label" => "UserGroups.name",
"rules" => "required|max_length[50]",
],
];
protected $validationMessages = [
"description" => [
"max_length" => "UserGroups.validation.description.max_length",
"required" => "UserGroups.validation.description.required",
],
"name" => [
"max_length" => "UserGroups.validation.name.max_length",
"required" => "UserGroups.validation.name.required",
],
];
public function getPermissionsList()
{
$allRecords = $this->findAll();
$result = [];
foreach ($allRecords as $record) {
foreach ($record->rules as $section => $permissions) {
foreach ($permissions as $permission) {
$result[$section . "." . $permission] = "Can " . $permission;
}
// Add menu visibility permission (automatic management)
$result[$section . ".menu"] = "Menu shall be visualize";
}
}
return $result;
}
}

View File

@ -1,96 +0,0 @@
<?php
namespace App\Models\Usuarios;
class UserGroupModel extends \App\Models\GoBaseModel
{
protected $table = "auth_user_group";
/**
* Whether primary key uses auto increment.
*
* @var bool
*/
protected $useAutoIncrement = true;
protected $primaryKey = "id_group";
protected $useTimestamps = true;
protected $dateFormat = 'datetime';
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
const SORTABLE = [
1 => "t1.id_group",
2 => "t1.title",
3 => "t1.dashboard",
4 => "t1.rules",
5 => "t1.token",
6 => "t1.created_at",
7 => "t1.updated_at",
];
protected $allowedFields = ["id_group", "title", "dashboard", "rules", "token"];
protected $returnType = "App\Entities\Usuarios\UserGroupEntity";
public static $labelField = "title";
protected $validationRules = [
"dashboard" => [
"label" => "UserGroups.dashboard",
"rules" => "required|max_length[50]",
],
"title" => [
"label" => "UserGroups.title",
"rules" => "required|max_length[150]",
],
];
protected $validationMessages = [
"dashboard" => [
"max_length" => "UserGroups.validation.dashboard.max_length",
"required" => "UserGroups.validation.dashboard.required",
],
"title" => [
"max_length" => "UserGroups.validation.title.max_length",
"required" => "UserGroups.validation.title.required",
],
];
/**
* Get resource data.
*
* @param string $search
*
* @return \CodeIgniter\Database\BaseBuilder
*/
public function getResource(string $search = "")
{
$builder = $this->db
->table($this->table . " t1")
->select(
"t1.id_group AS id_group, t1.title AS title, t1.dashboard AS dashboard, t1.rules AS rules, t1.token AS token, t1.created_at AS created_at, t1.updated_at AS updated_at"
);
return empty($search)
? $builder
: $builder
->groupStart()
->like("t1.id_group", $search)
->orLike("t1.title", $search)
->orLike("t1.dashboard", $search)
->orLike("t1.rules", $search)
->orLike("t1.token", $search)
->orLike("t1.created_at", $search)
->orLike("t1.updated_at", $search)
->orLike("t1.id_group", $search)
->orLike("t1.title", $search)
->orLike("t1.dashboard", $search)
->orLike("t1.rules", $search)
->orLike("t1.token", $search)
->orLike("t1.created_at", $search)
->orLike("t1.updated_at", $search)
->groupEnd();
}
}

View File

@ -1,7 +1,7 @@
<?php
namespace App\Models\Usuarios;
class UserModel extends \App\Models\GoBaseModel
class UserModel extends \App\Models\BaseModel
{
protected $table = "auth_user";
@ -187,8 +187,8 @@ class UserModel extends \App\Models\GoBaseModel
public function getGroupsTitles($user_token){
$sql = 'SELECT `auth_user_group`.`title` FROM `auth_user_group`
JOIN `group_user` ON `auth_user_group`.`token` = `group_user`.`token_group`
$sql = 'SELECT `auth_groups`.`title` FROM `auth_groups`
JOIN `group_user` ON `auth_groups`.`token` = `group_user`.`token_group`
JOIN `auth_user` ON `auth_user`.`token` = `group_user`.`token_user`
WHERE `auth_user`.`token` = \''. $user_token . '\'';