Renonmbrado de GoBaseModel a BaseModel

This commit is contained in:
imnavajas
2024-05-02 23:52:46 +02:00
parent c36dbfce86
commit 497e55f593
59 changed files with 303 additions and 613 deletions

View File

@ -1,204 +0,0 @@
<?php
namespace App\Controllers;
use App\Models\CountriesModel;
use App\Models\CronTabModel;
use App\Models\CurrencyModel;
use App\Models\SettingsModel;
use App\Models\TemplateModel;
use App\Models\ThemeModel;
use App\Models\TimezoneModel;
use App\Models\Usuarios\UserGroupModel;
use App\Models\Usuarios\UserModel;
class Settings extends BaseController
{
private $settings_model;
private $countries_model;
private $theme_model;
private $currency_model;
private $timezone_model;
private $group_model;
private $template_model;
private $user_model;
private $crontab_model;
private $integration;
function __construct()
{
$this->settings_model = new SettingsModel();
$this->countries_model = new CountriesModel();
$this->theme_model = new ThemeModel();
$this->currency_model = new CurrencyModel();
$this->timezone_model = new TimezoneModel();
$this->group_model = new UserGroupModel();
$this->template_model = new TemplateModel();
$this->user_model = new UserModel();
$this->crontab_model = new CronTabModel();
$this->integration = new Integration();
}
public function index()
{
helper('form');
$data['title'] = [
'module' => lang("App.settings_title"),
'page' => lang("App.settings_subtitle"),
'icon' => 'fas fa-sliders-h'
];
$data['breadcrumb'] = [
['title' => lang("App.menu_settings"), 'route' => site_url('settings'), 'active' => true]
];
$data['obj'] = $this->settings_model->first();
$data['countries'] = $this->countries_model->select('id_country,code,name')->where('data_lang',session()->get('lang')??'en')->findAll();
$data['theme'] = $this->theme_model->select('id_theme,type,name')->findAll();
$data['currency'] = $this->currency_model->select('id_currency,code,name')->findAll();
$data['timezone'] = $this->timezone_model->select('id_timezone,timezone,description')->findAll();
$data['group'] = $this->group_model->select('token,title')->findAll();
$db = db_connect('default');
$data['tables'] = $db->listTables();
$data['user'] = $this->user_model->select('token,first_name,email')->where('status',true)->findAll();
echo view(getenv('theme.path').'form/settings/index', $data);
}
public function store()
{
//Demo Mode
if(env('demo.mode')??false){
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
return redirect()->to('/settings');
}
helper('form');
$session = session();
if($listPost = $this->request->getPost()){
$listPost['id_settings'] = 1;
$listPost['captcha_register'] = isset($listPost['captcha_register']) && $listPost['captcha_register'] == 'on';
$listPost['captcha_login'] = isset($listPost['captcha_login']) && $listPost['captcha_login'] == 'on';
$listPost['captcha_recovery'] = isset($listPost['captcha_recovery']) && $listPost['captcha_recovery'] == 'on';
$listPost['registration'] = isset($listPost['registration']) && $listPost['registration'] == 'on';
$listPost['terms_conditions'] = isset($listPost['terms_conditions']) && $listPost['terms_conditions'] == 'on';
$listPost['email_confirmation'] = isset($listPost['email_confirmation']) && $listPost['email_confirmation'] == 'on';
$listPost['send_email_register'] = isset($listPost['send_email_register']) && $listPost['send_email_register'] == 'on';
$listPost['send_notification_register'] = isset($listPost['send_notification_register']) && $listPost['send_notification_register'] == 'on';
$listPost['send_email_welcome'] = isset($listPost['send_email_welcome']) && $listPost['send_email_welcome'] == 'on';
$listPost['remember_me'] = isset($listPost['remember_me']) && $listPost['remember_me'] == 'on';
$listPost['forgot_password'] = isset($listPost['forgot_password']) && $listPost['forgot_password'] == 'on';
$listPost['two_factor_auth'] = isset($listPost['two_factor_auth']) && $listPost['two_factor_auth'] == 'on';
$listPost['throttle_auth'] = isset($listPost['throttle_auth']) && $listPost['throttle_auth'] == 'on';
$listPost['enable_api'] = isset($listPost['enable_api']) && $listPost['enable_api'] == 'on';
$listPost['block_external_api'] = isset($listPost['block_external_api']) && $listPost['block_external_api'] == 'on';
$listPost['remove_log'] = isset($listPost['remove_log']) && $listPost['remove_log'] == 'on';
$listPost['backup_notification_email'] = isset($listPost['backup_notification_email']) && $listPost['backup_notification_email'] == 'on';
$listPost['backup_automatic'] = isset($listPost['backup_automatic']) && $listPost['backup_automatic'] == 'on';
$listPost['backup_table'] = implode(",",$listPost['backup_table']??[]);
$this->settings_model->save($listPost);
$settings = $this->settings_model->first()??[];
$session->set('settings', $settings);
$session->set('lang', $settings['default_language'] ?? 'es');
$session->setFlashdata('sweet', ['success',lang("App.settings_alert_add")]);
return redirect()->to('/settings');
} else{
$session->setFlashdata('sweet', ['error',lang("App.settings_alert_error")]);
return redirect()->to('/settings');
}
}
public function template()
{
helper('form');
$data['title'] = [
'module' => lang("App.template_title"),
'page' => lang("App.template_subtitle"),
'icon' => 'fas fa-mail-bulk'
];
$data['breadcrumb'] = [
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
['title' => lang("App.menu_settings"), 'route' => "/settings", 'active' => false],
['title' => lang("App.template_title"), 'route' => "", 'active' => true]
];
$data['btn_return'] = [
'title' => lang("App.global_come_back"),
'route' => '/home',
'class' => 'btn btn-dark mr-1',
'icon' => 'fas fa-angle-left'
];
$data['btn_submit'] = [
'title' => lang("App.global_save"),
'route' => '',
'class' => 'btn btn-primary mr-1',
'icon' => 'fas fa-save'
];
$data['template'] = $this->template_model->findAll();
echo view(getenv('theme.path').'main/header');
echo view(getenv('theme.path').'form/settings/template', $data);
echo view(getenv('theme.path').'main/footer');
}
public function template_store()
{
//Demo Mode
if(env('demo.mode')??false){
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
return redirect()->to('/settings/template');
}
$session = session();
helper('form');
if($field = $this->request->getPost()){
$ids = [];
$template = [];
unset($field['files']);
foreach ($field as $key=>$value){
$id = explode('_',$key);
array_push($ids,$id[2]);
}
foreach (array_unique($ids) as $item){
$template[$item] = [];
foreach ($field as $key=>$value){
$id = explode('_',$key);
if($id[2] == $item){
if(empty($template[$item])){
$template[$item] = array_merge( $template[$item],['id_template' => intval($id[2])]);
$template[$item] = array_merge( $template[$item],['subject' => ""]);
$template[$item] = array_merge( $template[$item],['body' => ""]);
}
switch($id[1])
{
case 'email';
switch($id[0])
{
case 'title';
$template[$item] = array_merge( $template[$item],['subject' => $value]);
break;
default;
$template[$item] = array_merge( $template[$item],[$id[0] => $value]);
break;
}
break;
}
}
}
}
$this->template_model->updateBatch($template,'id_template');
$session->setFlashdata('sweet', ['success',lang("App.template_alert_add")]);
return redirect()->to('/settings/template');
} else{
$session->setFlashdata('sweet', ['error',lang("App.template_alert_error")]);
return redirect()->to('/settings/template');
}
}
}

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";

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";

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";

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

@ -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,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

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

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";

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

@ -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,7 +1,7 @@
<?php
namespace App\Models\Usuarios;
class UserGroupModel extends \App\Models\GoBaseModel
class UserGroupModel extends \App\Models\BaseModel
{
protected $table = "auth_user_group";

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";