Creado mecanismo de generacion de alertas tipo Boostrap (defecto) y ToastR. Aplicado a los controladores existentes

This commit is contained in:
imnavajas
2023-07-26 22:36:57 +02:00
parent 47a6c3b62a
commit d25ff9666c
28 changed files with 2214 additions and 2195 deletions

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Clientes; <?php namespace App\Controllers\Clientes;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -19,7 +19,8 @@ use App\Models\Configuracion\FormaPagoModel;
use App\Models\Configuracion\PaisModel; use App\Models\Configuracion\PaisModel;
class Cliente extends \App\Controllers\GoBaseResourceController { class Cliente extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ClienteModel::class; protected $modelName = ClienteModel::class;
protected $format = 'json'; protected $format = 'json';
@ -35,9 +36,9 @@ class Cliente extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'clienteList'; protected $indexRoute = 'clienteList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Clientes.moduleTitle'); $this->viewData['pageTitle'] = lang('Clientes.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
@ -57,23 +58,25 @@ class Cliente extends \App\Controllers\GoBaseResourceController {
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Clientes.cliente')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Clientes.cliente')]),
'clienteEntity' => new ClienteEntity(), 'clienteEntity' => new ClienteEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewClienteList', $viewData); return view(static::$viewPath . 'viewClienteList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -83,39 +86,37 @@ class Cliente extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Clientes.cliente'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Clientes.cliente'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/cliente/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -128,23 +129,24 @@ class Cliente extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['clienteEntity'] = isset($sanitizedData) ? new ClienteEntity($sanitizedData) : new ClienteEntity(); $this->viewData['clienteEntity'] = isset($sanitizedData) ? new ClienteEntity($sanitizedData) : new ClienteEntity();
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null); $this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null);
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteEntity->provincia_id ?? null); $this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteEntity->provincia_id ?? null);
$this->viewData['paisList'] = $this->getPaisListItems($clienteEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($clienteEntity->pais_id ?? null);
$this->viewData['userList'] = $this->getUserListItems($clienteEntity->comercial_id ?? null); $this->viewData['userList'] = $this->getUserListItems($clienteEntity->comercial_id ?? null);
$this->viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null); $this->viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null);
$this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null); $this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null);
$this->viewData['formAction'] = route_to('createCliente'); $this->viewData['formAction'] = route_to('createCliente');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Clientes.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Clientes.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -161,98 +163,94 @@ class Cliente extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('credito_asegurado') == null ) { if ($this->request->getPost('credito_asegurado') == null) {
$sanitizedData['credito_asegurado'] = false; $sanitizedData['credito_asegurado'] = false;
} }
if ($this->request->getPost('disponible_fe') == null ) { if ($this->request->getPost('disponible_fe') == null) {
$sanitizedData['disponible_fe'] = false; $sanitizedData['disponible_fe'] = false;
} }
if ($this->request->getPost('message_tracking') == null ) { if ($this->request->getPost('message_tracking') == null) {
$sanitizedData['message_tracking'] = false; $sanitizedData['message_tracking'] = false;
} }
if ($this->request->getPost('message_production_start') == null ) { if ($this->request->getPost('message_production_start') == null) {
$sanitizedData['message_production_start'] = false; $sanitizedData['message_production_start'] = false;
} }
if ($this->request->getPost('tirada_flexible') == null ) { if ($this->request->getPost('tirada_flexible') == null) {
$sanitizedData['tirada_flexible'] = false; $sanitizedData['tirada_flexible'] = false;
} }
if ($this->request->getPost('lineasEnvioFactura') == null ) { if ($this->request->getPost('lineasEnvioFactura') == null) {
$sanitizedData['lineasEnvioFactura'] = false; $sanitizedData['lineasEnvioFactura'] = false;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Clientes.cliente'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$clienteEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Clientes.cliente'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$clienteEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $clienteEntity->id ?? $id; $id = $clienteEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Clientes.cliente'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/cliente/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
//var_dump($clienteEntity); dd(); //var_dump($clienteEntity); dd();
$this->viewData['clienteEntity'] = $clienteEntity; $this->viewData['clienteEntity'] = $clienteEntity;
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null); $this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteEntity->comunidad_autonoma_id ?? null);
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteEntity->provincia_id ?? null); $this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteEntity->provincia_id ?? null);
$this->viewData['paisList'] = $this->getPaisListItems($clienteEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($clienteEntity->pais_id ?? null);
$this->viewData['userList'] = $this->getUserListItems($clienteEntity->comercial_id ?? null); $this->viewData['userList'] = $this->getUserListItems($clienteEntity->comercial_id ?? null);
$this->viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null); $this->viewData['userList2'] = $this->getUserListItems2($clienteEntity->soporte_id ?? null);
$this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null); $this->viewData['formaDePagoList'] = $this->getFormaDePagoListItems($clienteEntity->forma_pago_id ?? null);
$this->viewData['formAction'] = route_to('updateCliente', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Clientes.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateCliente', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Clientes.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -263,17 +261,20 @@ if ($this->request->getPost('lineasEnvioFactura') == null ) {
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
foreach ($resourceData as $item) : foreach ($resourceData as $item) :
if (isset($item->direccion) && strlen($item->direccion) > 100) : if (isset($item->direccion) && strlen($item->direccion) > 100) :
$item->direccion = character_limiter($item->direccion, 100); $item->direccion = character_limiter($item->direccion, 100);
endif;if (isset($item->comentarios_tirada_flexible) && strlen($item->comentarios_tirada_flexible) > 100) : endif;
$item->comentarios_tirada_flexible = character_limiter($item->comentarios_tirada_flexible, 100); if (isset($item->comentarios_tirada_flexible) && strlen($item->comentarios_tirada_flexible) > 100) :
endif;if (isset($item->comentarios_produccion) && strlen($item->comentarios_produccion) > 100) : $item->comentarios_tirada_flexible = character_limiter($item->comentarios_tirada_flexible, 100);
$item->comentarios_produccion = character_limiter($item->comentarios_produccion, 100); endif;
endif;if (isset($item->comentarios) && strlen($item->comentarios) > 100) : if (isset($item->comentarios_produccion) && strlen($item->comentarios_produccion) > 100) :
$item->comentarios = character_limiter($item->comentarios, 100); $item->comentarios_produccion = character_limiter($item->comentarios_produccion, 100);
endif; endif;
endforeach; if (isset($item->comentarios) && strlen($item->comentarios) > 100) :
$item->comentarios = character_limiter($item->comentarios, 100);
endif;
endforeach;
return $this->respond(Collection::datatable( return $this->respond(Collection::datatable(
$resourceData, $resourceData,
@ -285,15 +286,16 @@ endif;
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -307,7 +309,8 @@ endif;
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -318,8 +321,8 @@ endif;
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -334,87 +337,93 @@ endif;
} }
protected function getPaisListItems($selId = null) { protected function getPaisListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
if (!empty($selId)) : if (!empty($selId)) :
$paisModel = model('App\Models\Configuracion\PaisModel'); $paisModel = model('App\Models\Configuracion\PaisModel');
$selOption = $paisModel->where('id', $selId)->findColumn('nombre'); $selOption = $paisModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getUserListItems($selId = null) { protected function getUserListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])];
if (!empty($selId)) : if (!empty($selId)) :
$userModel = model('App\Models\Usuarios\UserModel'); $userModel = model('App\Models\Usuarios\UserModel');
$selOption = $userModel->where('id_user', $selId)->findColumn('first_name'); $selOption = $userModel->where('id_user', $selId)->findColumn('first_name');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getComunidadAutonomaListItems($selId = null) { protected function getComunidadAutonomaListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])];
if (!empty($selId)) : if (!empty($selId)) :
$comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel'); $comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel');
$selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre'); $selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getUserListItems2($selId = null) { protected function getUserListItems2($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Users.user'))])];
if (!empty($selId)) : if (!empty($selId)) :
$userModel = model('App\Models\Configuracion\UserModel'); $userModel = model('App\Models\Configuracion\UserModel');
$selOption = $userModel->where('id_user', $selId)->findColumn('last_name'); $selOption = $userModel->where('id_user', $selId)->findColumn('last_name');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getFormaDePagoListItems($selId = null) { protected function getFormaDePagoListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('FormasPagoes.formaDePago'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('FormasPagoes.formaDePago'))])];
if (!empty($selId)) : if (!empty($selId)) :
$formaPagoModel = model('App\Models\Configuracion\FormaPagoModel'); $formaPagoModel = model('App\Models\Configuracion\FormaPagoModel');
$selOption = $formaPagoModel->where('id', $selId)->findColumn('nombre'); $selOption = $formaPagoModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getProvinciaListItems($selId = null) { protected function getProvinciaListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])];
if (!empty($selId)) : if (!empty($selId)) :
$provinciaModel = model('App\Models\Configuracion\ProvinciaModel'); $provinciaModel = model('App\Models\Configuracion\ProvinciaModel');
$selOption = $provinciaModel->where('id', $selId)->findColumn('nombre'); $selOption = $provinciaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Clientes; <?php namespace App\Controllers\Clientes;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -11,7 +11,8 @@ use App\Models\Clientes\ClienteModel;
use App\Models\Clientes\ClienteContactoModel; use App\Models\Clientes\ClienteContactoModel;
class Clientecontactos extends \App\Controllers\GoBaseResourceController { class Clientecontactos extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ClienteContactoModel::class; protected $modelName = ClienteContactoModel::class;
protected $format = 'json'; protected $format = 'json';
@ -27,34 +28,35 @@ class Clientecontactos extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'contactoDeClienteList'; protected $indexRoute = 'contactoDeClienteList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('ClienteContactos.moduleTitle'); $this->viewData['pageTitle'] = lang('ClienteContactos.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ClienteContactos.contactoDeCliente')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ClienteContactos.contactoDeCliente')]),
'clienteContactoEntity' => new ClienteContactoEntity(), 'clienteContactoEntity' => new ClienteContactoEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewContactoDeClienteList', $viewData); return view(static::$viewPath . 'viewContactoDeClienteList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -63,39 +65,37 @@ class Clientecontactos extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ClienteContactos.contactoDeCliente'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('ClienteContactos.contactoDeCliente'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/cliente-contactos/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -108,18 +108,19 @@ class Clientecontactos extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['clienteContactoEntity'] = isset($sanitizedData) ? new ClienteContactoEntity($sanitizedData) : new ClienteContactoEntity(); $this->viewData['clienteContactoEntity'] = isset($sanitizedData) ? new ClienteContactoEntity($sanitizedData) : new ClienteContactoEntity();
$this->viewData['clienteList'] = $this->getClienteListItems($clienteContactoEntity->cliente_id ?? null); $this->viewData['clienteList'] = $this->getClienteListItems($clienteContactoEntity->cliente_id ?? null);
$this->viewData['formAction'] = route_to('createContactoDeCliente'); $this->viewData['formAction'] = route_to('createContactoDeCliente');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('ClienteContactos.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('ClienteContactos.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -136,73 +137,69 @@ class Clientecontactos extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ClienteContactos.contactoDeCliente'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$clienteContactoEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ClienteContactos.contactoDeCliente'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$clienteContactoEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $clienteContactoEntity->id ?? $id; $id = $clienteContactoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('ClienteContactos.contactoDeCliente'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/cliente-contactos/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['clienteContactoEntity'] = $clienteContactoEntity; $this->viewData['clienteContactoEntity'] = $clienteContactoEntity;
$this->viewData['clienteList'] = $this->getClienteListItems($clienteContactoEntity->cliente_id ?? null); $this->viewData['clienteList'] = $this->getClienteListItems($clienteContactoEntity->cliente_id ?? null);
$this->viewData['formAction'] = route_to('updateContactoDeCliente', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('ClienteContactos.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateContactoDeCliente', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('ClienteContactos.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -213,11 +210,11 @@ class Clientecontactos extends \App\Controllers\GoBaseResourceController {
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
foreach ($resourceData as $item) : foreach ($resourceData as $item) :
if (isset($item->apellidos) && strlen($item->apellidos) > 100) : if (isset($item->apellidos) && strlen($item->apellidos) > 100) :
$item->apellidos = character_limiter($item->apellidos, 100); $item->apellidos = character_limiter($item->apellidos, 100);
endif; endif;
endforeach; endforeach;
return $this->respond(Collection::datatable( return $this->respond(Collection::datatable(
$resourceData, $resourceData,
@ -229,15 +226,16 @@ endif;
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -251,7 +249,8 @@ endif;
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -262,8 +261,8 @@ endif;
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -278,17 +277,18 @@ endif;
} }
protected function getClienteListItems($selId = null) { protected function getClienteListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Clientes.cliente'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Clientes.cliente'))])];
if (!empty($selId)) : if (!empty($selId)) :
$clienteModel = model('App\Models\Clientes\ClienteModel'); $clienteModel = model('App\Models\Clientes\ClienteModel');
$selOption = $clienteModel->where('id', $selId)->findColumn('nombre'); $selOption = $clienteModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Clientes; <?php namespace App\Controllers\Clientes;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -15,7 +15,8 @@ use App\Models\Configuracion\ProvinciaModel;
use App\Models\Configuracion\ComunidadAutonomaModel; use App\Models\Configuracion\ComunidadAutonomaModel;
class Clientedistribuidores extends \App\Controllers\GoBaseResourceController { class Clientedistribuidores extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ClienteDistribuidorModel::class; protected $modelName = ClienteDistribuidorModel::class;
protected $format = 'json'; protected $format = 'json';
@ -31,34 +32,35 @@ class Clientedistribuidores extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'distribuidorDeClienteList'; protected $indexRoute = 'distribuidorDeClienteList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('ClienteDistribuidores.moduleTitle'); $this->viewData['pageTitle'] = lang('ClienteDistribuidores.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ClienteDistribuidores.distribuidorDeCliente')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ClienteDistribuidores.distribuidorDeCliente')]),
'clienteDistribuidorEntity' => new ClienteDistribuidorEntity(), 'clienteDistribuidorEntity' => new ClienteDistribuidorEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewDistribuidorDeClienteList', $viewData); return view(static::$viewPath . 'viewDistribuidorDeClienteList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -67,39 +69,37 @@ class Clientedistribuidores extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ClienteDistribuidores.distribuidorDeCliente'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('ClienteDistribuidores.distribuidorDeCliente'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/cliente-distribuidores/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -112,20 +112,21 @@ class Clientedistribuidores extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['clienteDistribuidorEntity'] = isset($sanitizedData) ? new ClienteDistribuidorEntity($sanitizedData) : new ClienteDistribuidorEntity(); $this->viewData['clienteDistribuidorEntity'] = isset($sanitizedData) ? new ClienteDistribuidorEntity($sanitizedData) : new ClienteDistribuidorEntity();
$this->viewData['paisList'] = $this->getPaisListItems($clienteDistribuidorEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($clienteDistribuidorEntity->pais_id ?? null);
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteDistribuidorEntity->provincia_id ?? null); $this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteDistribuidorEntity->provincia_id ?? null);
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteDistribuidorEntity->comunidad_autonoma_id ?? null); $this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteDistribuidorEntity->comunidad_autonoma_id ?? null);
$this->viewData['formAction'] = route_to('createDistribuidorDeCliente'); $this->viewData['formAction'] = route_to('createDistribuidorDeCliente');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('ClienteDistribuidores.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('ClienteDistribuidores.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -142,75 +143,71 @@ class Clientedistribuidores extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ClienteDistribuidores.distribuidorDeCliente'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$clienteDistribuidorEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ClienteDistribuidores.distribuidorDeCliente'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$clienteDistribuidorEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $clienteDistribuidorEntity->id ?? $id; $id = $clienteDistribuidorEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('ClienteDistribuidores.distribuidorDeCliente'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/cliente-distribuidores/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['clienteDistribuidorEntity'] = $clienteDistribuidorEntity; $this->viewData['clienteDistribuidorEntity'] = $clienteDistribuidorEntity;
$this->viewData['paisList'] = $this->getPaisListItems($clienteDistribuidorEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($clienteDistribuidorEntity->pais_id ?? null);
$this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteDistribuidorEntity->provincia_id ?? null); $this->viewData['provinciaList'] = $this->getProvinciaListItems($clienteDistribuidorEntity->provincia_id ?? null);
$this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteDistribuidorEntity->comunidad_autonoma_id ?? null); $this->viewData['comunidadAutonomaList'] = $this->getComunidadAutonomaListItems($clienteDistribuidorEntity->comunidad_autonoma_id ?? null);
$this->viewData['formAction'] = route_to('updateDistribuidorDeCliente', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('ClienteDistribuidores.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateDistribuidorDeCliente', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('ClienteDistribuidores.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -221,13 +218,14 @@ class Clientedistribuidores extends \App\Controllers\GoBaseResourceController {
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
foreach ($resourceData as $item) : foreach ($resourceData as $item) :
if (isset($item->direccion) && strlen($item->direccion) > 100) : if (isset($item->direccion) && strlen($item->direccion) > 100) :
$item->direccion = character_limiter($item->direccion, 100); $item->direccion = character_limiter($item->direccion, 100);
endif;if (isset($item->horarios_entrega) && strlen($item->horarios_entrega) > 100) : endif;
$item->horarios_entrega = character_limiter($item->horarios_entrega, 100); if (isset($item->horarios_entrega) && strlen($item->horarios_entrega) > 100) :
endif; $item->horarios_entrega = character_limiter($item->horarios_entrega, 100);
endforeach; endif;
endforeach;
return $this->respond(Collection::datatable( return $this->respond(Collection::datatable(
$resourceData, $resourceData,
@ -239,15 +237,16 @@ endif;
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -261,7 +260,8 @@ endif;
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -272,8 +272,8 @@ endif;
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -288,45 +288,48 @@ endif;
} }
protected function getComunidadAutonomaListItems($selId = null) { protected function getComunidadAutonomaListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))])];
if (!empty($selId)) : if (!empty($selId)) :
$comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel'); $comunidadAutonomaModel = model('App\Models\Configuracion\ComunidadAutonomaModel');
$selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre'); $selOption = $comunidadAutonomaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getPaisListItems($selId = null) { protected function getPaisListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
if (!empty($selId)) : if (!empty($selId)) :
$paisModel = model('App\Models\Configuracion\PaisModel'); $paisModel = model('App\Models\Configuracion\PaisModel');
$selOption = $paisModel->where('id', $selId)->findColumn('nombre'); $selOption = $paisModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getProvinciaListItems($selId = null) { protected function getProvinciaListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Provincias.provincia'))])];
if (!empty($selId)) : if (!empty($selId)) :
$provinciaModel = model('App\Models\Configuracion\ProvinciaModel'); $provinciaModel = model('App\Models\Configuracion\ProvinciaModel');
$selOption = $provinciaModel->where('id', $selId)->findColumn('nombre'); $selOption = $provinciaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -11,7 +11,8 @@ use App\Models\Configuracion\PaisModel;
use App\Models\Configuracion\ComunidadAutonomaModel; use App\Models\Configuracion\ComunidadAutonomaModel;
class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController { class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ComunidadAutonomaModel::class; protected $modelName = ComunidadAutonomaModel::class;
protected $format = 'json'; protected $format = 'json';
@ -27,34 +28,35 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'comunidadAutonomaList'; protected $indexRoute = 'comunidadAutonomaList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('ComunidadesAutonomas.moduleTitle'); $this->viewData['pageTitle'] = lang('ComunidadesAutonomas.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ComunidadesAutonomas.comunidadAutonoma')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ComunidadesAutonomas.comunidadAutonoma')]),
'comunidadAutonomaEntity' => new ComunidadAutonomaEntity(), 'comunidadAutonomaEntity' => new ComunidadAutonomaEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewComunidadAutonomaList', $viewData); return view(static::$viewPath . 'viewComunidadAutonomaList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -63,39 +65,37 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/comunidades-autonomas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -108,18 +108,19 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['comunidadAutonomaEntity'] = isset($sanitizedData) ? new ComunidadAutonomaEntity($sanitizedData) : new ComunidadAutonomaEntity(); $this->viewData['comunidadAutonomaEntity'] = isset($sanitizedData) ? new ComunidadAutonomaEntity($sanitizedData) : new ComunidadAutonomaEntity();
$this->viewData['paisList'] = $this->getPaisListItems($comunidadAutonomaEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($comunidadAutonomaEntity->pais_id ?? null);
$this->viewData['formAction'] = route_to('createComunidadAutonoma'); $this->viewData['formAction'] = route_to('createComunidadAutonoma');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('ComunidadesAutonomas.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('ComunidadesAutonomas.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -136,73 +137,69 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$comunidadAutonomaEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$comunidadAutonomaEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $comunidadAutonomaEntity->id ?? $id; $id = $comunidadAutonomaEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/comunidades-autonomas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['comunidadAutonomaEntity'] = $comunidadAutonomaEntity; $this->viewData['comunidadAutonomaEntity'] = $comunidadAutonomaEntity;
$this->viewData['paisList'] = $this->getPaisListItems($comunidadAutonomaEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($comunidadAutonomaEntity->pais_id ?? null);
$this->viewData['formAction'] = route_to('updateComunidadAutonoma', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('ComunidadesAutonomas.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateComunidadAutonoma', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('ComunidadesAutonomas.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -224,15 +221,16 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -246,7 +244,8 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -257,8 +256,8 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -273,17 +272,18 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
} }
protected function getPaisListItems($selId = null) { protected function getPaisListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
if (!empty($selId)) : if (!empty($selId)) :
$paisModel = model('App\Models\Configuracion\PaisModel'); $paisModel = model('App\Models\Configuracion\PaisModel');
$selOption = $paisModel->where('id', $selId)->findColumn('id'); $selOption = $paisModel->where('id', $selId)->findColumn('id');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
} }

View File

@ -1,11 +1,12 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Entities\Configuracion\FormasPagoEntity; use App\Entities\Configuracion\FormasPagoEntity;
class Formaspago extends \App\Controllers\GoBaseController { class Formaspago extends \App\Controllers\GoBaseController
{
use \CodeIgniter\API\ResponseTrait; use \CodeIgniter\API\ResponseTrait;
protected static $primaryModelName = 'App\Models\Configuracion\FormasPagoModel'; protected static $primaryModelName = 'App\Models\Configuracion\FormasPagoModel';
@ -18,32 +19,34 @@ class Formaspago extends \App\Controllers\GoBaseController {
protected $indexRoute = 'formaPagoList'; protected $indexRoute = 'formaPagoList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('FormasPagoes.moduleTitle'); $this->viewData['pageTitle'] = lang('FormasPagoes.moduleTitle');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
if (session('errorMessage')) { if (session('errorMessage')) {
$this->session->setFlashData('sweet-error', session('errorMessage')); $this->session->setFlashData('sweet-error', session('errorMessage'));
} }
if (session('successMessage')) { if (session('successMessage')) {
$this->session->setFlashData('sweet-success', session('successMessage')); $this->session->setFlashData('sweet-success', session('successMessage'));
} }
} }
public function index() { public function index()
{
$this->viewData['usingClientSideDataTable'] = true; $this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaPago')]); $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaPago')]);
parent::index(); parent::index();
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -52,34 +55,32 @@ class Formaspago extends \App\Controllers\GoBaseController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try { if ($this->canValidate()) :
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); try {
} catch (\Exception $e) { $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
$noException = false; } catch (\Exception $e) {
$this->dealWithException($e); $noException = false;
} $this->dealWithException($e);
else: }
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaPago'))]); else:
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
endif; $this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('FormasPagoes.formaPago'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor(route_to('editFormaPago', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -99,14 +100,15 @@ class Formaspago extends \App\Controllers\GoBaseController {
$this->viewData['formAction'] = route_to('createFormaPago'); $this->viewData['formAction'] = route_to('createFormaPago');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('FormasPagoes.formaPago').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('FormasPagoes.formaPago') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -123,38 +125,35 @@ class Formaspago extends \App\Controllers\GoBaseController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaPago'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$formasPagoEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaPago'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$formasPagoEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $formasPagoEntity->id ?? $id; $id = $formasPagoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('FormasPagoes.formaPago'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor(route_to('editFormaPago', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -165,7 +164,7 @@ class Formaspago extends \App\Controllers\GoBaseController {
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
@ -173,23 +172,23 @@ class Formaspago extends \App\Controllers\GoBaseController {
$this->viewData['formAction'] = route_to('updateFormaPago', $id); $this->viewData['formAction'] = route_to('updateFormaPago', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('FormasPagoes.formaPago').' '.lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('FormasPagoes.formaPago') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -202,8 +201,9 @@ class Formaspago extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -214,8 +214,8 @@ class Formaspago extends \App\Controllers\GoBaseController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -228,5 +228,5 @@ class Formaspago extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\FormaPagoEntity;
use App\Models\Configuracion\FormaPagoModel; use App\Models\Configuracion\FormaPagoModel;
class Formaspagos extends \App\Controllers\GoBaseResourceController { class Formaspagos extends \App\Controllers\GoBaseResourceController
{
protected $modelName = FormaPagoModel::class; protected $modelName = FormaPagoModel::class;
protected $format = 'json'; protected $format = 'json';
@ -25,34 +26,35 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'formaDePagoList'; protected $indexRoute = 'formaDePagoList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('FormasPagoes.moduleTitle'); $this->viewData['pageTitle'] = lang('FormasPagoes.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaDePago')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaDePago')]),
'formaPagoEntity' => new FormaPagoEntity(), 'formaPagoEntity' => new FormaPagoEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewFormaDePagoList', $viewData); return view(static::$viewPath . 'viewFormaDePagoList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -61,39 +63,37 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaDePago'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('FormasPagoes.formaDePago'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/formas-pagos/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -109,14 +109,15 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
$this->viewData['formAction'] = route_to('createFormaDePago'); $this->viewData['formAction'] = route_to('createFormaDePago');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('FormasPagoes.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('FormasPagoes.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -133,72 +134,68 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaDePago'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$formaPagoEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaDePago'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$formaPagoEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $formaPagoEntity->id ?? $id; $id = $formaPagoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('FormasPagoes.formaDePago'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/formas-pagos/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['formaPagoEntity'] = $formaPagoEntity; $this->viewData['formaPagoEntity'] = $formaPagoEntity;
$this->viewData['formAction'] = route_to('updateFormaDePago', $id); $this->viewData['formAction'] = route_to('updateFormaDePago', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('FormasPagoes.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('FormasPagoes.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -220,15 +217,16 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -242,7 +240,8 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -253,8 +252,8 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();

View File

@ -6,13 +6,13 @@ use App\Controllers\GoBaseResourceController;
use App\Models\Usuarios\UserGroupModel; use App\Models\Usuarios\UserGroupModel;
use App\Models\Usuarios\GroupUserModel; use App\Models\Usuarios\GroupUserModel;
class Group extends \App\Controllers\GoBaseController class Group extends \App\Controllers\GoBaseController
{ {
use \CodeIgniter\API\ResponseTrait; use \CodeIgniter\API\ResponseTrait;
protected static $primaryModelName = 'App\Models\Usuarios\UserGroupModel'; protected static $primaryModelName = 'App\Models\Usuarios\UserGroupModel';
protected $modelName = UserGroupModel::class; protected $modelName = UserGroupModel::class;
protected static $singularObjectNameCc = 'userGroup'; protected static $singularObjectNameCc = 'userGroup';
protected static $singularObjectName = 'Group'; protected static $singularObjectName = 'Group';
protected static $pluralObjectName = 'Groups'; protected static $pluralObjectName = 'Groups';
@ -24,22 +24,23 @@ class Group extends \App\Controllers\GoBaseController
private $group_user_model; private $group_user_model;
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Group.moduleTitle'); $this->viewData['pageTitle'] = lang('Group.moduleTitle');
self::$viewPath = getenv('theme.path').'form/group/'; self::$viewPath = getenv('theme.path') . 'form/group/';
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() public function index()
{ {
$this->viewData['usingClientSideDataTable'] = true; $this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Groups.group')]); $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Groups.group')]);
// IMN // IMN
$this->group_user_model = new GroupUserModel(); $this->group_user_model = new GroupUserModel();
$this->viewData['model'] = $this->group_user_model; $this->viewData['model'] = $this->group_user_model;
parent::index(); parent::index();
} }
@ -55,38 +56,36 @@ class Group extends \App\Controllers\GoBaseController
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$title = $postData['title']; $title = $postData['title'];
$dashboard = $postData['dashboard']; $dashboard = $postData['dashboard'];
unset($postData['title']); unset($postData['title']);
unset($postData['dashboard']); unset($postData['dashboard']);
unset($postData['id_group']); unset($postData['id_group']);
unset($postData['save']); unset($postData['save']);
$controller = null; $controller = null;
$rules_access = null; $rules_access = null;
foreach ($postData as $key=>$value){ foreach ($postData as $key => $value) {
$exp = explode('_',$key); $exp = explode('_', $key);
$controller[] = $exp[0]; $controller[] = $exp[0];
} }
if($controller != null){ if ($controller != null) {
foreach (array_unique($controller) as $item){ foreach (array_unique($controller) as $item) {
$rules_access[$item] = []; $rules_access[$item] = [];
foreach ($postData as $key=>$value){ foreach ($postData as $key => $value) {
$exp = explode('_',$key); $exp = explode('_', $key);
if($exp[0] == $item){ if ($exp[0] == $item) {
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ; array_push($rules_access[$item], str_replace($exp[0] . '_', '', $key));
} }
} }
} }
} }
$temp_data['rules'] = json_encode($rules_access ?? '{}');
$temp_data['rules'] = json_encode($rules_access??'{}');
$temp_data['token'] = md5(uniqid(rand(), true));; $temp_data['token'] = md5(uniqid(rand(), true));;
$temp_data['title'] = $title; $temp_data['title'] = $title;
$temp_data['dashboard'] = $dashboard; $temp_data['dashboard'] = $dashboard;
@ -97,31 +96,29 @@ class Group extends \App\Controllers\GoBaseController
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Group.userGroup'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Group.userGroup'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/user-groups/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -134,21 +131,22 @@ class Group extends \App\Controllers\GoBaseController
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['group'] = isset($sanitizedData) ? new UserGroupModel($sanitizedData) : new UserGroupModel(); $this->viewData['group'] = isset($sanitizedData) ? new UserGroupModel($sanitizedData) : new UserGroupModel();
$this->viewData['formAction'] = route_to('createGroup'); $this->viewData['formAction'] = route_to('createGroup');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Group.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Group.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} }
public function edit($requestedId = null) { public function edit($requestedId = null)
{
helper('general'); helper('general');
$session = session(); $session = session();
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -165,7 +163,7 @@ class Group extends \App\Controllers\GoBaseController
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$id_group = $groupEntity->id_group; $id_group = $groupEntity->id_group;
@ -180,62 +178,59 @@ class Group extends \App\Controllers\GoBaseController
$controller = null; $controller = null;
$rules_access = null; $rules_access = null;
foreach ($postData as $key=>$value){ foreach ($postData as $key => $value) {
$exp = explode('_',$key); $exp = explode('_', $key);
$controller[] = $exp[0]; $controller[] = $exp[0];
} }
if($controller != null){ if ($controller != null) {
foreach (array_unique($controller) as $item){ foreach (array_unique($controller) as $item) {
$rules_access[$item] = []; $rules_access[$item] = [];
foreach ($postData as $key=>$value){ foreach ($postData as $key => $value) {
$exp = explode('_',$key); $exp = explode('_', $key);
if($exp[0] == $item){ if ($exp[0] == $item) {
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ; array_push($rules_access[$item], str_replace($exp[0] . '_', '', $key));
} }
} }
} }
} }
$temp_data['id_group'] = $id_group; $temp_data['id_group'] = $id_group;
$temp_data['rules'] = json_encode($rules_access??'{}'); $temp_data['rules'] = json_encode($rules_access ?? '{}');
$temp_data['token'] = $token; $temp_data['token'] = $token;
$temp_data['title'] = $title; $temp_data['title'] = $title;
$temp_data['dashboard'] = $dashboard; $temp_data['dashboard'] = $dashboard;
$sanitizedData = $this->sanitized($temp_data, $nullIfEmpty); $sanitizedData = $this->sanitized($temp_data, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Group.userGroup'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$groupEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Group.userGroup'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$groupEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $groupEntity->id ?? $id; $id = $groupEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Group.userGroup'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor(route_to('editGroup', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if($session->get('group') == $this->request->getPost('token')){ if ($session->get('group') == $this->request->getPost('token')) {
$session->set('rules', $temp_data['rules']); $session->set('rules', $temp_data['rules']);
} }
if ($thenRedirect) : if ($thenRedirect) :
@ -247,7 +242,7 @@ class Group extends \App\Controllers\GoBaseController
else: else:
$this->viewData['successMessage'] = $message; $this->viewData['successMessage'] = $message;
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
@ -255,23 +250,23 @@ class Group extends \App\Controllers\GoBaseController
$this->viewData['formAction'] = route_to('updateGroup', $id); $this->viewData['formAction'] = route_to('updateGroup', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Group.userGroup').' '.lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Group.userGroup') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -284,8 +279,9 @@ class Group extends \App\Controllers\GoBaseController
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -296,8 +292,8 @@ class Group extends \App\Controllers\GoBaseController
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\Imposicion;
use App\Models\Configuracion\ImposicionModel; use App\Models\Configuracion\ImposicionModel;
class Imposiciones extends \App\Controllers\GoBaseResourceController { class Imposiciones extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ImposicionModel::class; protected $modelName = ImposicionModel::class;
protected $format = 'json'; protected $format = 'json';
@ -25,34 +26,35 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'imposicionList'; protected $indexRoute = 'imposicionList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Imposiciones.moduleTitle'); $this->viewData['pageTitle'] = lang('Imposiciones.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Imposiciones.imposicion')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Imposiciones.imposicion')]),
'imposicion' => new Imposicion(), 'imposicion' => new Imposicion(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewImposicionList', $viewData); return view(static::$viewPath . 'viewImposicionList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -61,39 +63,37 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Imposiciones.imposicion'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Imposiciones.imposicion'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/imposiciones/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -106,18 +106,19 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['imposicion'] = isset($sanitizedData) ? new Imposicion($sanitizedData) : new Imposicion(); $this->viewData['imposicion'] = isset($sanitizedData) ? new Imposicion($sanitizedData) : new Imposicion();
$this->viewData['orientacionList'] = $this->getOrientacionOptions(); $this->viewData['orientacionList'] = $this->getOrientacionOptions();
$this->viewData['formAction'] = route_to('createImposicion'); $this->viewData['formAction'] = route_to('createImposicion');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Imposiciones.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Imposiciones.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -134,73 +135,69 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Imposiciones.imposicion'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$imposicion->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Imposiciones.imposicion'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$imposicion->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $imposicion->id ?? $id; $id = $imposicion->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Imposiciones.imposicion'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/imposiciones/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['imposicion'] = $imposicion; $this->viewData['imposicion'] = $imposicion;
$this->viewData['orientacionList'] = $this->getOrientacionOptions(); $this->viewData['orientacionList'] = $this->getOrientacionOptions();
$this->viewData['formAction'] = route_to('updateImposicion', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Imposiciones.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateImposicion', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Imposiciones.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -222,15 +219,16 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', ancho', 'ancho', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', ancho', 'ancho', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->ancho = '- '.lang('Basic.global.None').' -'; $nonItem->ancho = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -244,7 +242,8 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -255,8 +254,8 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -271,14 +270,15 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
} }
protected function getOrientacionOptions() { protected function getOrientacionOptions()
$orientacionOptions = [ {
'' => lang('Basic.global.pleaseSelect'), $orientacionOptions = [
'H' => 'H', '' => lang('Basic.global.pleaseSelect'),
'V' => 'V', 'H' => 'H',
]; 'V' => 'V',
return $orientacionOptions; ];
} return $orientacionOptions;
}
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\Maquina;
use App\Models\Configuracion\MaquinaModel; use App\Models\Configuracion\MaquinaModel;
class Maquinas extends \App\Controllers\GoBaseResourceController { class Maquinas extends \App\Controllers\GoBaseResourceController
{
protected $modelName = MaquinaModel::class; protected $modelName = MaquinaModel::class;
protected $format = 'json'; protected $format = 'json';
@ -25,9 +26,9 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'maquinaList'; protected $indexRoute = 'maquinaList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Maquinas.moduleTitle'); $this->viewData['pageTitle'] = lang('Maquinas.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
@ -48,24 +49,26 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Maquinas.maquina')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Maquinas.maquina')]),
'maquina' => new Maquina(), 'maquina' => new Maquina(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewMaquinaList', $viewData); return view(static::$viewPath . 'viewMaquinaList', $viewData);
} }
public function add() { public function add()
{
// JJO // JJO
$session = session(); $session = session();
@ -76,42 +79,40 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
$sanitizedData['user_created_id'] = $session->id_user; $sanitizedData['user_created_id'] = $session->id_user;
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Maquinas.maquina'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Maquinas.maquina'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "maquinas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
//return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); //return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
return redirect()->to(site_url('configuracion/maquinas/edit/'.$id))->with('sweet-success', $message); return redirect()->to(site_url('configuracion/maquinas/edit/' . $id))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -124,18 +125,19 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['maquina'] = isset($sanitizedData) ? new Maquina($sanitizedData) : new Maquina(); $this->viewData['maquina'] = isset($sanitizedData) ? new Maquina($sanitizedData) : new Maquina();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null); $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions(); $this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['formAction'] = route_to('createMaquina'); $this->viewData['formAction'] = route_to('createMaquina');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Maquinas.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Maquinas.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
// JJO // JJO
$session = session(); $session = session();
@ -156,61 +158,57 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('is_padre') == null ) { if ($this->request->getPost('is_padre') == null) {
$sanitizedData['is_padre'] = false; $sanitizedData['is_padre'] = false;
} }
if ($this->request->getPost('is_rotativa') == null ) { if ($this->request->getPost('is_rotativa') == null) {
$sanitizedData['is_rotativa'] = false; $sanitizedData['is_rotativa'] = false;
} }
if ($this->request->getPost('is_tinta') == null ) { if ($this->request->getPost('is_tinta') == null) {
$sanitizedData['is_tinta'] = false; $sanitizedData['is_tinta'] = false;
} }
// JJO // JJO
$sanitizedData['user_updated_id'] = $session->id_user; $sanitizedData['user_updated_id'] = $session->id_user;
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
//JJO: comprobar alto y ancho impresion < alto y ancho //JJO: comprobar alto y ancho impresion < alto y ancho
if($sanitizedData['alto'] < $sanitizedData['alto_impresion']){ if ($sanitizedData['alto'] < $sanitizedData['alto_impresion']) {
$successfulResult = false; $successfulResult = false;
$this->viewData['errorMessage'] = lang('Maquinas.validation.alto_menor_alto_impresion');; $this->viewData['errorMessage'] = lang('Maquinas.validation.alto_menor_alto_impresion');;
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
} } else if ($sanitizedData['ancho'] < $sanitizedData['ancho_impresion']) {
else if ($sanitizedData['ancho'] < $sanitizedData['ancho_impresion']){
$successfulResult = false; $successfulResult = false;
$this->viewData['errorMessage'] = lang('Maquinas.validation.ancho_menor_ancho_impresion');; $this->viewData['errorMessage'] = lang('Maquinas.validation.ancho_menor_ancho_impresion');;
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
} } else {
else{ try {
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
} }
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Maquinas.maquina'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$maquina->fill($sanitizedData);
$thenRedirect = false; else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Maquinas.maquina'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$maquina->fill($sanitizedData);
$thenRedirect = false;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $maquina->id ?? $id; $id = $maquina->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Maquinas.maquina'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "maquinas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -221,30 +219,30 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['maquina'] = $maquina; $this->viewData['maquina'] = $maquina;
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null); $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions(); $this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['formAction'] = route_to('updateMaquina', $id); $this->viewData['formAction'] = route_to('updateMaquina', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Maquinas.moduleTitle').' '.lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Maquinas.moduleTitle') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -255,11 +253,11 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
foreach ($resourceData as $item) : foreach ($resourceData as $item) :
if (isset($item->observaciones) && strlen($item->observaciones) > 100) : if (isset($item->observaciones) && strlen($item->observaciones) > 100) :
$item->observaciones = character_limiter($item->observaciones, 100); $item->observaciones = character_limiter($item->observaciones, 100);
endif; endif;
endforeach; endforeach;
return $this->respond(Collection::datatable( return $this->respond(Collection::datatable(
$resourceData, $resourceData,
@ -271,15 +269,16 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -293,7 +292,8 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -304,8 +304,8 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -320,29 +320,31 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
} }
protected function getMaquinaListItems($selId = null) { protected function getMaquinaListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
if (!empty($selId)) : if (!empty($selId)) :
$maquinaModel = model('App\Models\Configuracion\MaquinaModel'); $maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getTipoOptions() { protected function getTipoOptions()
$tipoOptions = [ {
'' => lang('Basic.global.pleaseSelect'), $tipoOptions = [
'impresion' => 'impresion', '' => lang('Basic.global.pleaseSelect'),
'manipulado' => 'manipulado', 'impresion' => 'impresion',
'acabado' => 'acabado', 'manipulado' => 'manipulado',
]; 'acabado' => 'acabado',
return $tipoOptions; ];
} return $tipoOptions;
}
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -11,7 +11,8 @@ use App\Models\Configuracion\MaquinaModel;
use App\Models\Configuracion\MaquinasDefectoModel; use App\Models\Configuracion\MaquinasDefectoModel;
class Maquinasdefecto extends \App\Controllers\GoBaseResourceController { class Maquinasdefecto extends \App\Controllers\GoBaseResourceController
{
protected $modelName = MaquinasDefectoModel::class; protected $modelName = MaquinasDefectoModel::class;
protected $format = 'json'; protected $format = 'json';
@ -27,9 +28,9 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'maquinaPorDefectoList'; protected $indexRoute = 'maquinaPorDefectoList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('MaquinasPorDefecto.moduleTitle'); $this->viewData['pageTitle'] = lang('MaquinasPorDefecto.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
@ -42,24 +43,26 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasPorDefecto.maquinaPorDefecto')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasPorDefecto.maquinaPorDefecto')]),
'maquinasDefectoEntity' => new MaquinasDefectoEntity(), 'maquinasDefectoEntity' => new MaquinasDefectoEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewMaquinaPorDefectoList', $viewData); return view(static::$viewPath . 'viewMaquinaPorDefectoList', $viewData);
} }
public function add() { public function add()
{
// JJO // JJO
$session = session(); $session = session();
@ -70,46 +73,43 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
$sanitizedData['user_created_id'] = $session->id_user; $sanitizedData['user_created_id'] = $session->id_user;
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
// JJO: se añade que se checkeen los intervalos de ancho y tirada. // JJO: se añade que se checkeen los intervalos de ancho y tirada.
// En caso de error se devuelve un mensaje. // En caso de error se devuelve un mensaje.
try { try {
$error = $this->model->checkIntervals($sanitizedData); $error = $this->model->checkIntervals($sanitizedData);
if(empty($error)){ if (empty($error)) {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} } else {
else{
$successfulResult = false; $successfulResult = false;
$this->viewData['errorMessage'] = $error; $this->viewData['errorMessage'] = $error;
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "configuracion/maquinasdefecto/edit/{$id}" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -126,19 +126,20 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['maquinasDefectoEntity'] = isset($sanitizedData) ? new MaquinasDefectoEntity($sanitizedData) : new MaquinasDefectoEntity(); $this->viewData['maquinasDefectoEntity'] = isset($sanitizedData) ? new MaquinasDefectoEntity($sanitizedData) : new MaquinasDefectoEntity();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null); $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions(); $this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['formAction'] = route_to('createMaquinaPorDefecto'); $this->viewData['formAction'] = route_to('createMaquinaPorDefecto');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('MaquinasPorDefecto.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('MaquinasPorDefecto.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
// JJO // JJO
$session = session(); $session = session();
@ -158,49 +159,46 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
$sanitizedData['user_updated_id'] = $session->id_user; $sanitizedData['user_updated_id'] = $session->id_user;
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
// JJO: se añade que se checkeen los intervalos de ancho y tirada. // JJO: se añade que se checkeen los intervalos de ancho y tirada.
// En caso de error se devuelve un mensaje. // En caso de error se devuelve un mensaje.
try { try {
$error = $this->model->checkIntervals($sanitizedData, $id); $error = $this->model->checkIntervals($sanitizedData, $id);
if(empty($error)){ if (empty($error)) {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} } else {
else{
$successfulResult = false; $successfulResult = false;
$this->viewData['errorMessage'] = $error; $this->viewData['errorMessage'] = $error;
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]); $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$maquinasDefectoEntity->fill($sanitizedData);
$thenRedirect = true; endif;
$maquinasDefectoEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $maquinasDefectoEntity->id ?? $id; $id = $maquinasDefectoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "maquinasdefecto/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -211,30 +209,30 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['maquinasDefectoEntity'] = $maquinasDefectoEntity; $this->viewData['maquinasDefectoEntity'] = $maquinasDefectoEntity;
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null); $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions(); $this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['formAction'] = route_to('updateMaquinaPorDefecto', $id); $this->viewData['formAction'] = route_to('updateMaquinaPorDefecto', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('MaquinasPorDefecto.moduleTitle').' '.lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('MaquinasPorDefecto.moduleTitle') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -259,15 +257,16 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', tipo', 'tipo', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', tipo', 'tipo', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->tipo = '- '.lang('Basic.global.None').' -'; $nonItem->tipo = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -281,7 +280,8 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -292,8 +292,8 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -308,32 +308,34 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
} }
protected function getMaquinaListItems($selId = null) { protected function getMaquinaListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
if (!empty($selId)) : if (!empty($selId)) :
$maquinaModel = model('App\Models\Configuracion\MaquinaModel'); $maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getTipoOptions() { protected function getTipoOptions()
$tipoOptions = [ {
'' => lang('Basic.global.pleaseSelect'), $tipoOptions = [
'bn' => 'bn', '' => lang('Basic.global.pleaseSelect'),
'bnhq' => 'bnhq', 'bn' => 'bn',
'color' => 'color', 'bnhq' => 'bnhq',
'portada' => 'portada', 'color' => 'color',
'cubierta' => 'cubierta', 'portada' => 'portada',
'rotativa' => 'rotativa', 'cubierta' => 'cubierta',
]; 'rotativa' => 'rotativa',
return $tipoOptions; ];
} return $tipoOptions;
}
//sanitiezdata //sanitiezdata

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -22,7 +22,8 @@ use
DataTables\Editor\Validate, DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions; DataTables\Editor\ValidateOptions;
class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController { class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
{
protected $modelName = MaquinasTarifasImpresionModel::class; protected $modelName = MaquinasTarifasImpresionModel::class;
protected $format = 'json'; protected $format = 'json';
@ -38,34 +39,35 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
protected $indexRoute = 'maquinasTarifaImpresionList'; protected $indexRoute = 'maquinasTarifaImpresionList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('MaquinasTarifasImpresions.moduleTitle'); $this->viewData['pageTitle'] = lang('MaquinasTarifasImpresions.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasTarifasImpresions.maquinasTarifaImpresion')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasTarifasImpresions.maquinasTarifaImpresion')]),
'maquinasTarifasImpresion' => new MaquinasTarifasImpresion(), 'maquinasTarifasImpresion' => new MaquinasTarifasImpresion(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewMaquinasTarifaImpresionList', $viewData); return view(static::$viewPath . 'viewMaquinasTarifaImpresionList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -74,35 +76,33 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "maquinastarifasimpresion/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -119,19 +119,20 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['maquinasTarifasImpresion'] = isset($sanitizedData) ? new MaquinasTarifasImpresion($sanitizedData) : new MaquinasTarifasImpresion(); $this->viewData['maquinasTarifasImpresion'] = isset($sanitizedData) ? new MaquinasTarifasImpresion($sanitizedData) : new MaquinasTarifasImpresion();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null); $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions(); $this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['formAction'] = route_to('createMaquinasTarifaImpresion'); $this->viewData['formAction'] = route_to('createMaquinasTarifaImpresion');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('MaquinasTarifasImpresions.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('MaquinasTarifasImpresions.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -148,43 +149,39 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('predeterminado') == null ) { if ($this->request->getPost('predeterminado') == null) {
$sanitizedData['predeterminado'] = false; $sanitizedData['predeterminado'] = false;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$maquinasTarifasImpresion->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$maquinasTarifasImpresion->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $maquinasTarifasImpresion->id ?? $id; $id = $maquinasTarifasImpresion->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "maquinastarifasimpresion/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -195,110 +192,110 @@ if ($this->request->getPost('predeterminado') == null ) {
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['maquinasTarifasImpresion'] = $maquinasTarifasImpresion; $this->viewData['maquinasTarifasImpresion'] = $maquinasTarifasImpresion;
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null); $this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions(); $this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['formAction'] = route_to('updateMaquinasTarifaImpresion', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('MaquinasTarifasImpresions.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateMaquinasTarifaImpresion', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('MaquinasTarifasImpresions.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable_editor() {
public function datatable_editor()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
// Build our Editor instance and process the data coming from _POST // Build our Editor instance and process the data coming from _POST
$response = Editor::inst( $db, 'lg_maquinas_tarifas_impresion' ) $response = Editor::inst($db, 'lg_maquinas_tarifas_impresion')
->fields( ->fields(
Field::inst( 'uso' ) Field::inst('uso')
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('MaquinasTarifasImpresions.validation.uso.required') ) 'message' => lang('MaquinasTarifasImpresions.validation.uso.required'))
), ),
Field::inst( 'tipo' ) Field::inst('tipo')
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required') ) 'message' => lang('MaquinasTarifasImpresions.validation.tipo.required'))
), ),
Field::inst( 'precio' ) Field::inst('precio')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('MaquinasTarifasImpresions.validation.precio.decimal') ) 'message' => lang('MaquinasTarifasImpresions.validation.precio.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required') ) 'message' => lang('MaquinasTarifasImpresions.validation.tipo.required'))
), ),
Field::inst( 'maquina_id' ), Field::inst('maquina_id'),
Field::inst( 'user_created_id' ), Field::inst('user_created_id'),
Field::inst( 'created_at' ), Field::inst('created_at'),
Field::inst( 'user_updated_id' ), Field::inst('user_updated_id'),
Field::inst( 'updated_at' ), Field::inst('updated_at'),
Field::inst( 'is_deleted' ), Field::inst('is_deleted'),
Field::inst( 'deleted_at' ), Field::inst('deleted_at'),
)
->validator( function($editor, $action, $data){
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){
foreach ($data['data'] as $pkey => $values ){
// Si no se quiere borrar...
if($data['data'][$pkey]['is_deleted'] != 1)
{
// Cubierta y sobrecubierta sólo pueden ser en color
if($values['uso'] != 'interior' && $values['tipo'] != 'color'){
return lang('MaquinasTarifasImpresions.validation.cubierta_sobrecubierta_color');
}
$builder = $this->model->select('*') )
->where(array( ->validator(function ($editor, $action, $data) {
'maquina_id'=> $values['maquina_id'], if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
'tipo'=> $values['tipo'], foreach ($data['data'] as $pkey => $values) {
'uso'=> $values['uso'], // Si no se quiere borrar...
'is_deleted'=> 0)); if ($data['data'][$pkey]['is_deleted'] != 1) {
// Cubierta y sobrecubierta sólo pueden ser en color
if ($values['uso'] != 'interior' && $values['tipo'] != 'color') {
return lang('MaquinasTarifasImpresions.validation.cubierta_sobrecubierta_color');
}
// No se pueden duplicar valores al crear o al editar $builder = $this->model->select('*')
if ($builder->countAllResults() >= 1){ ->where(array(
if(($action === Editor::ACTION_EDIT && $builder->get()->getFirstRow()->id != $pkey) 'maquina_id' => $values['maquina_id'],
|| $action === Editor::ACTION_CREATE){ 'tipo' => $values['tipo'],
'uso' => $values['uso'],
return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo'); 'is_deleted' => 0));
// No se pueden duplicar valores al crear o al editar
if ($builder->countAllResults() >= 1) {
if (($action === Editor::ACTION_EDIT && $builder->get()->getFirstRow()->id != $pkey)
|| $action === Editor::ACTION_CREATE) {
return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo');
}
} }
} }
} }
} }
} })
}) ->on('preCreate', function ($editor, &$values) {
->on( 'preCreate', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_created_id')
->field( 'user_created_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('created_at')
->field( 'created_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->on('preEdit', function ($editor, &$values) {
->on( 'preEdit', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_updated_id')
->field( 'user_updated_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('updated_at')
->field( 'updated_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->debug(true)
->debug(true) ->process($_POST)
->process( $_POST ) ->data();
->data();
/*// if unique key is set in DB /*// if unique key is set in DB
if(isset($response['error'])){ if(isset($response['error'])){
if(str_contains($response['error'], "tirada_min_tirada_max") && if(str_contains($response['error'], "tirada_min_tirada_max") &&
@ -307,10 +304,10 @@ if ($this->request->getPost('predeterminado') == null ) {
} }
}*/ }*/
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
$response[$csrfTokenName] = $newTokenHash; $response[$csrfTokenName] = $newTokenHash;
echo json_encode($response); echo json_encode($response);
} else { } else {
@ -318,12 +315,13 @@ if ($this->request->getPost('predeterminado') == null ) {
} }
} }
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -347,15 +345,16 @@ if ($this->request->getPost('predeterminado') == null ) {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', maquina_id', 'maquina_id', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', maquina_id', 'maquina_id', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->maquina_id = '- '.lang('Basic.global.None').' -'; $nonItem->maquina_id = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -369,7 +368,8 @@ if ($this->request->getPost('predeterminado') == null ) {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -380,8 +380,8 @@ if ($this->request->getPost('predeterminado') == null ) {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -396,30 +396,32 @@ if ($this->request->getPost('predeterminado') == null ) {
} }
protected function getMaquinaListItems($selId = null) { protected function getMaquinaListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
if (!empty($selId)) : if (!empty($selId)) :
$maquinaModel = model('App\Models\Configuracion\MaquinaModel'); $maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$selOption = $maquinaModel->where('id', $selId)->findColumn('nombre'); $selOption = $maquinaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
protected function getTipoOptions() { protected function getTipoOptions()
$tipoOptions = [ {
'' => lang('Basic.global.pleaseSelect'), $tipoOptions = [
'negro' => 'negro', '' => lang('Basic.global.pleaseSelect'),
'color' => 'color', 'negro' => 'negro',
'negrohq' => 'negrohq', 'color' => 'color',
'bicolor' => 'bicolor', 'negrohq' => 'negrohq',
]; 'bicolor' => 'bicolor',
return $tipoOptions; ];
} return $tipoOptions;
}
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\PaisEntity;
use App\Models\Configuracion\PaisModel; use App\Models\Configuracion\PaisModel;
class Paises extends \App\Controllers\GoBaseResourceController { class Paises extends \App\Controllers\GoBaseResourceController
{
protected $modelName = PaisModel::class; protected $modelName = PaisModel::class;
protected $format = 'json'; protected $format = 'json';
@ -25,34 +26,35 @@ class Paises extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'paisList'; protected $indexRoute = 'paisList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Paises.moduleTitle'); $this->viewData['pageTitle'] = lang('Paises.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]),
'paisEntity' => new PaisEntity(), 'paisEntity' => new PaisEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewPaisList', $viewData); return view(static::$viewPath . 'viewPaisList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -61,39 +63,37 @@ class Paises extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Paises.pais'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Paises.pais'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/paises/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -109,14 +109,15 @@ class Paises extends \App\Controllers\GoBaseResourceController {
$this->viewData['formAction'] = route_to('createPais'); $this->viewData['formAction'] = route_to('createPais');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Paises.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Paises.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -133,75 +134,71 @@ class Paises extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('show_erp') == null ) { if ($this->request->getPost('show_erp') == null) {
$sanitizedData['show_erp'] = false; $sanitizedData['show_erp'] = false;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Paises.pais'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$paisEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Paises.pais'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$paisEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $paisEntity->id ?? $id; $id = $paisEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Paises.pais'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/paises/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['paisEntity'] = $paisEntity; $this->viewData['paisEntity'] = $paisEntity;
$this->viewData['formAction'] = route_to('updatePais', $id); $this->viewData['formAction'] = route_to('updatePais', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Paises.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Paises.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -223,15 +220,16 @@ if ($this->request->getPost('show_erp') == null ) {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -245,7 +243,8 @@ if ($this->request->getPost('show_erp') == null ) {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -256,8 +255,8 @@ if ($this->request->getPost('show_erp') == null ) {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();

View File

@ -95,7 +95,7 @@ class Papelesgenericos extends \App\Controllers\GoBaseResourceController
$this->dealWithException($e); $this->dealWithException($e);
} }
else : else :
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('PapelGenerico.papelGenerico'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
@ -105,9 +105,7 @@ class Papelesgenericos extends \App\Controllers\GoBaseResourceController
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('PapelGenerico.papelGenerico'))]) . '.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor("papelesgenericos/{$id}/edit", lang('Basic.global.continueEditing') . '?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -185,9 +183,7 @@ class Papelesgenericos extends \App\Controllers\GoBaseResourceController
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $papelGenerico->id ?? $id; $id = $papelGenerico->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('PapelGenerico.papelGenerico'))]) . '.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]).'.';
$message .= anchor("papelesgenericos/{$id}/edit", lang('Basic.global.continueEditing') . '?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :

View File

@ -118,7 +118,7 @@ class Papelesimpresion extends \App\Controllers\GoBaseResourceController
$this->dealWithException($e); $this->dealWithException($e);
} }
else : else :
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('PapelImpresion.papelImpresion'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
@ -128,9 +128,7 @@ class Papelesimpresion extends \App\Controllers\GoBaseResourceController
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('PapelImpresion.papelImpresion'))]) . '.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor("papelesimpresion/{$id}/edit", lang('Basic.global.continueEditing') . '?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -232,9 +230,7 @@ class Papelesimpresion extends \App\Controllers\GoBaseResourceController
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $papelImpresion->id ?? $id; $id = $papelImpresion->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('PapelImpresion.papelImpresion'))]) . '.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]).'.';
$message .= anchor("papelesimpresion/{$id}/edit", lang('Basic.global.continueEditing') . '?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :

View File

@ -78,7 +78,7 @@ class Papelimpresiontipologias extends \App\Controllers\GoBaseResourceController
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ImpresionTipologias.papelImpresionTipologia'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
@ -88,9 +88,7 @@ class Papelimpresiontipologias extends \App\Controllers\GoBaseResourceController
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('ImpresionTipologias.papelImpresionTipologia'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "papelimpresiontipologias/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -177,9 +175,7 @@ class Papelimpresiontipologias extends \App\Controllers\GoBaseResourceController
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $papelImpresionTipologia->id ?? $id; $id = $papelImpresionTipologia->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('ImpresionTipologias.papelImpresionTipologia'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]).'.';
$message .= anchor( "papelimpresiontipologias/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -11,7 +11,8 @@ use App\Models\Configuracion\PaisModel;
use App\Models\Configuracion\ProvinciaModel; use App\Models\Configuracion\ProvinciaModel;
class Provincias extends \App\Controllers\GoBaseResourceController { class Provincias extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ProvinciaModel::class; protected $modelName = ProvinciaModel::class;
protected $format = 'json'; protected $format = 'json';
@ -27,34 +28,35 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'provinciaList'; protected $indexRoute = 'provinciaList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Provincias.moduleTitle'); $this->viewData['pageTitle'] = lang('Provincias.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Provincias.provincia')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Provincias.provincia')]),
'provinciaEntity' => new ProvinciaEntity(), 'provinciaEntity' => new ProvinciaEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewProvinciaList', $viewData); return view(static::$viewPath . 'viewProvinciaList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -63,39 +65,37 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Provincias.provincia'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Provincias.provincia'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/provincias/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
@ -108,18 +108,19 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['provinciaEntity'] = isset($sanitizedData) ? new ProvinciaEntity($sanitizedData) : new ProvinciaEntity(); $this->viewData['provinciaEntity'] = isset($sanitizedData) ? new ProvinciaEntity($sanitizedData) : new ProvinciaEntity();
$this->viewData['paisList'] = $this->getPaisListItems($provinciaEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($provinciaEntity->pais_id ?? null);
$this->viewData['formAction'] = route_to('createProvincia'); $this->viewData['formAction'] = route_to('createProvincia');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Provincias.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Provincias.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -136,73 +137,69 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Provincias.provincia'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$provinciaEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Provincias.provincia'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$provinciaEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $provinciaEntity->id ?? $id; $id = $provinciaEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Provincias.provincia'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "admin/provincias/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to( $this->indexRoute ) )->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['provinciaEntity'] = $provinciaEntity; $this->viewData['provinciaEntity'] = $provinciaEntity;
$this->viewData['paisList'] = $this->getPaisListItems($provinciaEntity->pais_id ?? null); $this->viewData['paisList'] = $this->getPaisListItems($provinciaEntity->pais_id ?? null);
$this->viewData['formAction'] = route_to('updateProvincia', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Provincias.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateProvincia', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Provincias.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -224,15 +221,16 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -246,7 +244,8 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -257,8 +256,8 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -273,17 +272,18 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
} }
protected function getPaisListItems($selId = null) { protected function getPaisListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
if (!empty($selId)) : if (!empty($selId)) :
$paisModel = model('App\Models\Configuracion\PaisModel'); $paisModel = model('App\Models\Configuracion\PaisModel');
$selOption = $paisModel->where('id', $selId)->findColumn('nombre'); $selOption = $paisModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
} }

View File

@ -1,11 +1,12 @@
<?php namespace App\Controllers\Configuracion; <?php namespace App\Controllers\Configuracion;
use App\Entities\Configuracion\TipologiasEntity; use App\Entities\Configuracion\TipologiasEntity;
class Tipologias extends \App\Controllers\GoBaseController { class Tipologias extends \App\Controllers\GoBaseController
{
use \CodeIgniter\API\ResponseTrait; use \CodeIgniter\API\ResponseTrait;
protected static $primaryModelName = 'App\Models\Configuracion\TipologiasLibroModel'; protected static $primaryModelName = 'App\Models\Configuracion\TipologiasLibroModel';
@ -18,26 +19,27 @@ class Tipologias extends \App\Controllers\GoBaseController {
protected $indexRoute = 'tipologiaLibrosList'; protected $indexRoute = 'tipologiaLibrosList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('TipologiasLibros.moduleTitle'); $this->viewData['pageTitle'] = lang('TipologiasLibros.moduleTitle');
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$this->viewData['usingClientSideDataTable'] = true; $this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('TipologiasLibros.tipologiaLibros')]); $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('TipologiasLibros.tipologiaLibros')]);
parent::index(); parent::index();
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -46,34 +48,32 @@ class Tipologias extends \App\Controllers\GoBaseController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try { if ($this->canValidate()) :
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); try {
} catch (\Exception $e) { $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
$noException = false; } catch (\Exception $e) {
$this->dealWithException($e); $noException = false;
} $this->dealWithException($e);
else: }
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]); else:
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
endif; $this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor(route_to('editTipologiaLibros', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -93,14 +93,15 @@ class Tipologias extends \App\Controllers\GoBaseController {
$this->viewData['formAction'] = route_to('createTipologiaLibros'); $this->viewData['formAction'] = route_to('createTipologiaLibros');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TipologiasLibros.tipologiaLibros').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('TipologiasLibros.tipologiaLibros') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -117,39 +118,35 @@ class Tipologias extends \App\Controllers\GoBaseController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tipologiasEntity->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tipologiasEntity->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tipologiasEntity->id ?? $id; $id = $tipologiasEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor(route_to('editTipologiaLibros', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -160,7 +157,7 @@ class Tipologias extends \App\Controllers\GoBaseController {
else: else:
$this->viewData['successMessage'] = $message; $this->viewData['successMessage'] = $message;
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
@ -168,23 +165,23 @@ class Tipologias extends \App\Controllers\GoBaseController {
$this->viewData['formAction'] = route_to('updateTipologiaLibros', $id); $this->viewData['formAction'] = route_to('updateTipologiaLibros', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TipologiasLibros.tipologiaLibros').' '.lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('TipologiasLibros.tipologiaLibros') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -197,8 +194,9 @@ class Tipologias extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -209,8 +207,8 @@ class Tipologias extends \App\Controllers\GoBaseController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -223,5 +221,5 @@ class Tipologias extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
} }

View File

@ -68,6 +68,15 @@ abstract class GoBaseResourceController extends \CodeIgniter\RESTful\ResourceCon
*/ */
public $delete_flag = 0; public $delete_flag = 0;
/**
* IMN: Variable para seleccionar el tipo de mensajeria que usa una clase
*
* 'alerts' -> Boostrap 5 default alerts
* 'toastr' -> Javascript ToastR library
* @var string
*/
public $alertStyle = 'alerts';
/** /**
* An array of helpers to be loaded automatically upon * An array of helpers to be loaded automatically upon
@ -116,6 +125,9 @@ abstract class GoBaseResourceController extends \CodeIgniter\RESTful\ResourceCon
$this->viewData['viewPath'] = static::$viewPath; $this->viewData['viewPath'] = static::$viewPath;
$this->viewData['currentLocale'] = $this->request->getLocale(); $this->viewData['currentLocale'] = $this->request->getLocale();
/* IMN */
$this->viewData['alertStyle'] = $this->alertStyle;
} }
/** /**

View File

@ -98,7 +98,7 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifaacabado.tarifaacabado'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
@ -108,9 +108,7 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Tarifaacabado.tarifaacabado'))]) . '.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor("tarifasacabado/{$id}/edit", lang('Basic.global.continueEditing') . '?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -120,9 +118,7 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
//JJO $this->session->setFlashData('sweet-success', $message);
$this->viewData['successMessage'] = $message;
//$this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
@ -194,9 +190,7 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifaacabadoEntity->id ?? $id; $id = $tarifaacabadoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Tarifaacabado.tarifaacabado'))]) . '.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]).'.';
//$message .= anchor("tarifasacabado/{$id}/edit", lang('Basic.global.continueEditing') . '?');
//$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -205,8 +199,7 @@ class Tarifaacabado extends \App\Controllers\GoBaseResourceController
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
//JJO $this->session->setFlashData('sweet-success', $message);
$this->viewData['successMessage'] = $message;
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Tarifas; <?php namespace App\Controllers\Tarifas;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -24,7 +24,8 @@ use
use function PHPUnit\Framework\isEmpty; use function PHPUnit\Framework\isEmpty;
class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController { class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController
{
protected $modelName = TarifaAcabadoLineaModel::class; protected $modelName = TarifaAcabadoLineaModel::class;
protected $format = 'json'; protected $format = 'json';
@ -40,34 +41,35 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'tarifaAcabadoLineaList'; protected $indexRoute = 'tarifaAcabadoLineaList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('TarifaAcabadoLineas.moduleTitle'); $this->viewData['pageTitle'] = lang('TarifaAcabadoLineas.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifaAcabadoLineas.tarifaAcabadoLinea')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifaAcabadoLineas.tarifaAcabadoLinea')]),
'tarifaAcabadoLinea' => new TarifaAcabadoLinea(), 'tarifaAcabadoLinea' => new TarifaAcabadoLinea(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewTarifaAcabadoLineaList', $viewData); return view(static::$viewPath . 'viewTarifaAcabadoLineaList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -76,35 +78,33 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaAcabadoLineas.tarifaAcabadoLinea'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifaAcabadoLineas.tarifaAcabadoLinea'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "tarifa-acabado-lineas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -121,18 +121,19 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['tarifaAcabadoLinea'] = isset($sanitizedData) ? new TarifaAcabadoLinea($sanitizedData) : new TarifaAcabadoLinea(); $this->viewData['tarifaAcabadoLinea'] = isset($sanitizedData) ? new TarifaAcabadoLinea($sanitizedData) : new TarifaAcabadoLinea();
$this->viewData['tarifaAcabadoList'] = $this->getTarifaAcabadoListItems($tarifaAcabadoLinea->tarifa_acabado_id ?? null); $this->viewData['tarifaAcabadoList'] = $this->getTarifaAcabadoListItems($tarifaAcabadoLinea->tarifa_acabado_id ?? null);
$this->viewData['formAction'] = route_to('createTarifaAcabadoLinea'); $this->viewData['formAction'] = route_to('createTarifaAcabadoLinea');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifaAcabadoLineas.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('TarifaAcabadoLineas.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -149,40 +150,36 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaAcabadoLineas.tarifaAcabadoLinea'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifaAcabadoLinea->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaAcabadoLineas.tarifaAcabadoLinea'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifaAcabadoLinea->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifaAcabadoLinea->id ?? $id; $id = $tarifaAcabadoLinea->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifaAcabadoLineas.tarifaAcabadoLinea'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "tarifa-acabado-lineas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -193,29 +190,29 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['tarifaAcabadoLinea'] = $tarifaAcabadoLinea; $this->viewData['tarifaAcabadoLinea'] = $tarifaAcabadoLinea;
$this->viewData['tarifaAcabadoList'] = $this->getTarifaAcabadoListItems($tarifaAcabadoLinea->tarifa_acabado_id ?? null); $this->viewData['tarifaAcabadoList'] = $this->getTarifaAcabadoListItems($tarifaAcabadoLinea->tarifa_acabado_id ?? null);
$this->viewData['formAction'] = route_to('updateTarifaAcabadoLinea', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('TarifaAcabadoLineas.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['formAction'] = route_to('updateTarifaAcabadoLinea', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifaAcabadoLineas.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
@ -226,10 +223,10 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
$order = TarifaAcabadoLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0]; $order = TarifaAcabadoLineaModel::SORTABLE[$requestedOrder >= 0 ? $requestedOrder : 0];
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_TA = $reqData['id_tarifaacabado'] ?? -1; $id_TA = $reqData['id_tarifaacabado'] ?? -1;
$resourceData = $this->model->getResource("", $id_TA)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource("", $id_TA)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable( return $this->respond(Collection::datatable(
@ -242,98 +239,99 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function datatable_editor() { public function datatable_editor()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
// Build our Editor instance and process the data coming from _POST // Build our Editor instance and process the data coming from _POST
$response = Editor::inst( $db, 'tarifa_acabado_lineas' ) $response = Editor::inst($db, 'tarifa_acabado_lineas')
->fields( ->fields(
Field::inst( 'paginas_min' ) Field::inst('paginas_min')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required'))
), ),
Field::inst( 'paginas_max' ) Field::inst('paginas_max')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required'))
), ),
Field::inst( 'precio_min' ) Field::inst('precio_min')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_min.required') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_min.required'))
), ),
Field::inst( 'precio_max' ) Field::inst('precio_max')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_max.required') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_max.required'))
), ),
Field::inst( 'margen' ) Field::inst('margen')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.margen.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.margen.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.margen.required') ) 'message' => lang('TarifaAcabadoLineas.validation.margen.required'))
), ),
Field::inst( 'tarifa_acabado_id' ), Field::inst('tarifa_acabado_id'),
Field::inst( 'user_created_id' ), Field::inst('user_created_id'),
Field::inst( 'created_at' ), Field::inst('created_at'),
Field::inst( 'user_updated_id' ), Field::inst('user_updated_id'),
Field::inst( 'updated_at' ), Field::inst('updated_at'),
Field::inst( 'is_deleted' ), Field::inst('is_deleted'),
Field::inst( 'deleted_at' ), Field::inst('deleted_at'),
)
->validator( function($editor, $action, $data){
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){
foreach ($data['data'] as $pkey => $values ){
// Si no se quiere borrar...
if($data['data'][$pkey]['is_deleted'] != 1){
$process_data['paginas_min'] = $data['data'][$pkey]['paginas_min']; )
$process_data['paginas_max'] = $data['data'][$pkey]['paginas_max']; ->validator(function ($editor, $action, $data) {
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_acabado_id']); if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
// No se pueden duplicar valores al crear o al editar foreach ($data['data'] as $pkey => $values) {
if (!empty($response)){ // Si no se quiere borrar...
return $response; if ($data['data'][$pkey]['is_deleted'] != 1) {
$process_data['paginas_min'] = $data['data'][$pkey]['paginas_min'];
$process_data['paginas_max'] = $data['data'][$pkey]['paginas_max'];
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_acabado_id']);
// No se pueden duplicar valores al crear o al editar
if (!empty($response)) {
return $response;
}
} }
} }
} }
} })
}) ->on('preCreate', function ($editor, &$values) {
->on( 'preCreate', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_created_id')
->field( 'user_created_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('created_at')
->field( 'created_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->on('preEdit', function ($editor, &$values) {
->on( 'preEdit', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_updated_id')
->field( 'user_updated_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('updated_at')
->field( 'updated_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->debug(true)
->debug(true) ->process($_POST)
->process( $_POST ) ->data();
->data();
// if unique key is set in DB // if unique key is set in DB
/*if(isset($response['error'])){ /*if(isset($response['error'])){
@ -343,10 +341,10 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
} }
}*/ }*/
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
$response[$csrfTokenName] = $newTokenHash; $response[$csrfTokenName] = $newTokenHash;
echo json_encode($response); echo json_encode($response);
} else { } else {
@ -354,15 +352,16 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', tarifa_acabado_id', 'tarifa_acabado_id', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', tarifa_acabado_id', 'tarifa_acabado_id', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->tarifa_acabado_id = '- '.lang('Basic.global.None').' -'; $nonItem->tarifa_acabado_id = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -376,7 +375,8 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -387,8 +387,8 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -403,17 +403,18 @@ class Tarifaacabadolineas extends \App\Controllers\GoBaseResourceController {
} }
protected function getTarifaAcabadoListItems($selId = null) { protected function getTarifaAcabadoListItems($selId = null)
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Tarifaacabado.tarifaAcabado'))])]; {
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Tarifaacabado.tarifaAcabado'))])];
if (!empty($selId)) : if (!empty($selId)) :
$tarifaacabadoModel = model('App\Models\tarifas\TarifaacabadoModel'); $tarifaacabadoModel = model('App\Models\tarifas\TarifaacabadoModel');
$selOption = $tarifaacabadoModel->where('id', $selId)->findColumn('id'); $selOption = $tarifaacabadoModel->where('id', $selId)->findColumn('id');
if (!empty($selOption)) : if (!empty($selOption)) :
$data[$selId] = $selOption[0]; $data[$selId] = $selOption[0];
endif; endif;
endif; endif;
return $data; return $data;
} }
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Tarifas; <?php namespace App\Controllers\Tarifas;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -21,7 +21,8 @@ use
DataTables\Editor\ValidateOptions; DataTables\Editor\ValidateOptions;
class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceController { class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceController
{
protected $modelName = TarifaEncuadernacionLineaModel::class; protected $modelName = TarifaEncuadernacionLineaModel::class;
protected $format = 'json'; protected $format = 'json';
@ -37,34 +38,35 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
protected $indexRoute = 'tarifaEncuadernacionLineaList'; protected $indexRoute = 'tarifaEncuadernacionLineaList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('TarifaEncuadernacionLineas.moduleTitle'); $this->viewData['pageTitle'] = lang('TarifaEncuadernacionLineas.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifaEncuadernacionLineas.tarifaencuadernacionLinea')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifaEncuadernacionLineas.tarifaencuadernacionLinea')]),
'tarifaEncuadernacionLinea' => new TarifaEncuadernacionLinea(), 'tarifaEncuadernacionLinea' => new TarifaEncuadernacionLinea(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewTarifaEncuadernacionLineaList', $viewData); return view(static::$viewPath . 'viewTarifaEncuadernacionLineaList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -73,35 +75,33 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaEncuadernacionLineas.tarifaencuadernacionLinea'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifaEncuadernacionLineas.tarifaencuadernacionLinea'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "tarifaencuadernacionlineas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -121,14 +121,15 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
$this->viewData['formAction'] = route_to('createTarifaEncuadernacionLinea'); $this->viewData['formAction'] = route_to('createTarifaEncuadernacionLinea');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifaEncuadernacionLineas.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('TarifaEncuadernacionLineas.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -145,40 +146,36 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaEncuadernacionLineas.tarifaencuadernacionLinea'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifaEncuadernacionLinea->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaEncuadernacionLineas.tarifaencuadernacionLinea'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifaEncuadernacionLinea->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifaEncuadernacionLinea->id ?? $id; $id = $tarifaEncuadernacionLinea->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifaEncuadernacionLineas.tarifaencuadernacionLinea'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "tarifaencuadernacionlineas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -189,119 +186,119 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['tarifaEncuadernacionLinea'] = $tarifaEncuadernacionLinea; $this->viewData['tarifaEncuadernacionLinea'] = $tarifaEncuadernacionLinea;
$this->viewData['formAction'] = route_to('updateTarifaEncuadernacionLinea', $id); $this->viewData['formAction'] = route_to('updateTarifaEncuadernacionLinea', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('TarifaEncuadernacionLineas.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifaEncuadernacionLineas.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable_editor() {
public function datatable_editor()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
// Build our Editor instance and process the data coming from _POST // Build our Editor instance and process the data coming from _POST
$response = Editor::inst( $db, 'tarifa_encuadernacion_lineas' ) $response = Editor::inst($db, 'tarifa_encuadernacion_lineas')
->fields( ->fields(
Field::inst( 'paginas_min' ) Field::inst('paginas_min')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required'))
), ),
Field::inst( 'paginas_max' ) Field::inst('paginas_max')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required'))
), ),
Field::inst( 'precio_min' ) Field::inst('precio_min')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_min.required') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_min.required'))
), ),
Field::inst( 'precio_max' ) Field::inst('precio_max')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_max.required') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_max.required'))
), ),
Field::inst( 'margen' ) Field::inst('margen')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.margen.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.margen.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.margen.required') ) 'message' => lang('TarifaAcabadoLineas.validation.margen.required'))
), ),
Field::inst( 'tarifa_encuadernacion_id' ), Field::inst('tarifa_encuadernacion_id'),
Field::inst( 'user_created_id' ), Field::inst('user_created_id'),
Field::inst( 'created_at' ), Field::inst('created_at'),
Field::inst( 'user_updated_id' ), Field::inst('user_updated_id'),
Field::inst( 'updated_at' ), Field::inst('updated_at'),
Field::inst( 'is_deleted' ), Field::inst('is_deleted'),
Field::inst( 'deleted_at' ), Field::inst('deleted_at'),
) )
->validator( function($editor, $action, $data){ ->validator(function ($editor, $action, $data) {
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){ if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
foreach ($data['data'] as $pkey => $values ){ foreach ($data['data'] as $pkey => $values) {
// Si no se quiere borrar... // Si no se quiere borrar...
if($data['data'][$pkey]['is_deleted'] != 1) if ($data['data'][$pkey]['is_deleted'] != 1) {
{ $process_data['paginas_min'] = $data['data'][$pkey]['paginas_min'];
$process_data['paginas_min'] = $data['data'][$pkey]['paginas_min']; $process_data['paginas_max'] = $data['data'][$pkey]['paginas_max'];
$process_data['paginas_max'] = $data['data'][$pkey]['paginas_max']; $response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_encuadernacion_id']);
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_encuadernacion_id']); // No se pueden duplicar valores al crear o al editar
// No se pueden duplicar valores al crear o al editar if (!empty($response)) {
if (!empty($response)){ return $response;
return $response; }
} }
} }
} }
} })
}) ->on('preCreate', function ($editor, &$values) {
->on( 'preCreate', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_created_id')
->field( 'user_created_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('created_at')
->field( 'created_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->on('preEdit', function ($editor, &$values) {
->on( 'preEdit', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_updated_id')
->field( 'user_updated_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('updated_at')
->field( 'updated_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->debug(true)
->debug(true) ->process($_POST)
->process( $_POST ) ->data();
->data();
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
$response[$csrfTokenName] = $newTokenHash; $response[$csrfTokenName] = $newTokenHash;
echo json_encode($response); echo json_encode($response);
} else { } else {
@ -309,12 +306,13 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
} }
} }
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -325,7 +323,7 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_TM = $reqData['id_tarifaencuadernacion'] ?? -1; $id_TM = $reqData['id_tarifaencuadernacion'] ?? -1;
$resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable( return $this->respond(Collection::datatable(
@ -338,15 +336,16 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', tarifa_encuadernacion_id', 'tarifa_encuadernacion_id', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', tarifa_encuadernacion_id', 'tarifa_encuadernacion_id', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->tarifa_encuadernacion_id = '- '.lang('Basic.global.None').' -'; $nonItem->tarifa_encuadernacion_id = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -360,7 +359,8 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -371,8 +371,8 @@ class Tarifaencuadernacionlineas extends \App\Controllers\GoBaseResourceControll
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Tarifas; <?php namespace App\Controllers\Tarifas;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -21,7 +21,8 @@ use
DataTables\Editor\ValidateOptions; DataTables\Editor\ValidateOptions;
class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController { class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController
{
protected $modelName = TarifaManipuladoLineaModel::class; protected $modelName = TarifaManipuladoLineaModel::class;
protected $format = 'json'; protected $format = 'json';
@ -37,34 +38,35 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'tarifaManipuladoLineaList'; protected $indexRoute = 'tarifaManipuladoLineaList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('TarifaManipuladoLineas.moduleTitle'); $this->viewData['pageTitle'] = lang('TarifaManipuladoLineas.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifaManipuladoLineas.tarifamanipuladoLinea')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('TarifaManipuladoLineas.tarifamanipuladoLinea')]),
'tarifaManipuladoLinea' => new TarifaManipuladoLinea(), 'tarifaManipuladoLinea' => new TarifaManipuladoLinea(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewTarifaManipuladoLineaList', $viewData); return view(static::$viewPath . 'viewTarifaManipuladoLineaList', $viewData);
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -73,35 +75,33 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "tarifamanipuladolineas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -121,14 +121,15 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
$this->viewData['formAction'] = route_to('createTarifaManipuladoLinea'); $this->viewData['formAction'] = route_to('createTarifaManipuladoLinea');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('TarifaManipuladoLineas.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('TarifaManipuladoLineas.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -145,40 +146,36 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifaManipuladoLinea->fill($sanitizedData);
$thenRedirect = true; if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifaManipuladoLinea->fill($sanitizedData);
$thenRedirect = true;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifaManipuladoLinea->id ?? $id; $id = $tarifaManipuladoLinea->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TarifaManipuladoLineas.tarifamanipuladoLinea'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "tarifamanipuladolineas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -189,119 +186,119 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
else: else:
$this->session->setFlashData('sweet-success', $message); $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['tarifaManipuladoLinea'] = $tarifaManipuladoLinea; $this->viewData['tarifaManipuladoLinea'] = $tarifaManipuladoLinea;
$this->viewData['formAction'] = route_to('updateTarifaManipuladoLinea', $id); $this->viewData['formAction'] = route_to('updateTarifaManipuladoLinea', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('TarifaManipuladoLineas.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('TarifaManipuladoLineas.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable_editor() {
public function datatable_editor()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
// Build our Editor instance and process the data coming from _POST // Build our Editor instance and process the data coming from _POST
$response = Editor::inst( $db, 'tarifa_manipulado_lineas' ) $response = Editor::inst($db, 'tarifa_manipulado_lineas')
->fields( ->fields(
Field::inst( 'paginas_min' ) Field::inst('paginas_min')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_min.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_min.required'))
), ),
Field::inst( 'paginas_max' ) Field::inst('paginas_max')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_max.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required') ) 'message' => lang('TarifaAcabadoLineas.validation.paginas_max.required'))
), ),
Field::inst( 'precio_min' ) Field::inst('precio_min')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_min.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_min.required') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_min.required'))
), ),
Field::inst( 'precio_max' ) Field::inst('precio_max')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_max.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.precio_max.required') ) 'message' => lang('TarifaAcabadoLineas.validation.precio_max.required'))
), ),
Field::inst( 'margen' ) Field::inst('margen')
->validator( 'Validate::numeric', array( ->validator('Validate::numeric', array(
'message' => lang('TarifaAcabadoLineas.validation.margen.decimal') ) 'message' => lang('TarifaAcabadoLineas.validation.margen.decimal'))
) )
->validator( 'Validate::notEmpty',array( ->validator('Validate::notEmpty', array(
'message' => lang('TarifaAcabadoLineas.validation.margen.required') ) 'message' => lang('TarifaAcabadoLineas.validation.margen.required'))
), ),
Field::inst( 'tarifa_manipulado_id' ), Field::inst('tarifa_manipulado_id'),
Field::inst( 'user_created_id' ), Field::inst('user_created_id'),
Field::inst( 'created_at' ), Field::inst('created_at'),
Field::inst( 'user_updated_id' ), Field::inst('user_updated_id'),
Field::inst( 'updated_at' ), Field::inst('updated_at'),
Field::inst( 'is_deleted' ), Field::inst('is_deleted'),
Field::inst( 'deleted_at' ), Field::inst('deleted_at'),
) )
->validator( function($editor, $action, $data){ ->validator(function ($editor, $action, $data) {
if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){ if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT) {
foreach ($data['data'] as $pkey => $values ){ foreach ($data['data'] as $pkey => $values) {
// Si no se quiere borrar... // Si no se quiere borrar...
if($data['data'][$pkey]['is_deleted'] != 1) if ($data['data'][$pkey]['is_deleted'] != 1) {
{ $process_data['paginas_min'] = $data['data'][$pkey]['paginas_min'];
$process_data['paginas_min'] = $data['data'][$pkey]['paginas_min']; $process_data['paginas_max'] = $data['data'][$pkey]['paginas_max'];
$process_data['paginas_max'] = $data['data'][$pkey]['paginas_max']; $response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_manipulado_id']);
$response = $this->model->checkIntervals($process_data, $pkey, $data['data'][$pkey]['tarifa_manipulado_id']); // No se pueden duplicar valores al crear o al editar
// No se pueden duplicar valores al crear o al editar if (!empty($response)) {
if (!empty($response)){ return $response;
return $response; }
} }
} }
} }
} })
}) ->on('preCreate', function ($editor, &$values) {
->on( 'preCreate', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_created_id')
->field( 'user_created_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('created_at')
->field( 'created_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->on('preEdit', function ($editor, &$values) {
->on( 'preEdit', function ( $editor, &$values ) { $session = session();
$session = session(); $datetime = (new \CodeIgniter\I18n\Time("now"));
$datetime = (new \CodeIgniter\I18n\Time("now")); $editor
$editor ->field('user_updated_id')
->field( 'user_updated_id' ) ->setValue($session->id_user);
->setValue( $session->id_user ); $editor
$editor ->field('updated_at')
->field( 'updated_at' ) ->setValue($datetime->format('Y-m-d H:i:s'));
->setValue( $datetime->format('Y-m-d H:i:s') ); })
} ) ->debug(true)
->debug(true) ->process($_POST)
->process( $_POST ) ->data();
->data();
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
$response[$csrfTokenName] = $newTokenHash; $response[$csrfTokenName] = $newTokenHash;
echo json_encode($response); echo json_encode($response);
} else { } else {
@ -309,12 +306,13 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -325,7 +323,7 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
$dir = $reqData['order']['0']['dir'] ?? 'asc'; $dir = $reqData['order']['0']['dir'] ?? 'asc';
$id_TM = $reqData['id_tarifamanipulado'] ?? -1; $id_TM = $reqData['id_tarifamanipulado'] ?? -1;
$resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); $resourceData = $this->model->getResource("", $id_TM)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(Collection::datatable( return $this->respond(Collection::datatable(
@ -338,15 +336,16 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', tarifa_manipulado_id', 'tarifa_manipulado_id', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', tarifa_manipulado_id', 'tarifa_manipulado_id', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->tarifa_manipulado_id = '- '.lang('Basic.global.None').' -'; $nonItem->tarifa_manipulado_id = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -360,7 +359,8 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -371,8 +371,8 @@ class Tarifamanipuladolineas extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();

View File

@ -1,11 +1,12 @@
<?php namespace App\Controllers\Tarifas; <?php namespace App\Controllers\Tarifas;
use App\Entities\Tarifas\TarifapreimpresionEntity; use App\Entities\Tarifas\TarifapreimpresionEntity;
class Tarifapreimpresion extends \App\Controllers\GoBaseController { class Tarifapreimpresion extends \App\Controllers\GoBaseController
{
use \CodeIgniter\API\ResponseTrait; use \CodeIgniter\API\ResponseTrait;
protected static $primaryModelName = 'App\Models\Tarifas\TarifapreimpresionModel'; protected static $primaryModelName = 'App\Models\Tarifas\TarifapreimpresionModel';
@ -18,9 +19,9 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
protected $indexRoute = 'tarifapreimpresionList'; protected $indexRoute = 'tarifapreimpresionList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Tarifapreimpresion.moduleTitle'); $this->viewData['pageTitle'] = lang('Tarifapreimpresion.moduleTitle');
// Se indica que este controlador trabaja con soft_delete // Se indica que este controlador trabaja con soft_delete
$this->soft_delete = true; $this->soft_delete = true;
@ -34,21 +35,22 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
]; ];
parent::initController($request, $response, $logger); parent::initController($request, $response, $logger);
} }
public function index() { public function index()
{
$this->viewData['usingClientSideDataTable'] = true; $this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifapreimpresion.tarifapreimpresion')]); $this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifapreimpresion.tarifapreimpresion')]);
parent::index(); parent::index();
} }
public function add() { public function add()
{
$requestMethod = $this->request->getMethod(); $requestMethod = $this->request->getMethod();
@ -57,34 +59,32 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try { if ($this->canValidate()) :
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); try {
} catch (\Exception $e) { $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
$noException = false; } catch (\Exception $e) {
$this->dealWithException($e); $noException = false;
} $this->dealWithException($e);
else: }
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifapreimpresion.tarifapreimpresion'))]); else:
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
endif; $this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Tarifapreimpresion.tarifapreimpresion'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor(route_to('editTarifapreimpresion', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -93,7 +93,7 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
return $this->redirect2listView('successMessage', $message); return $this->redirect2listView('successMessage', $message);
endif; endif;
else: else:
$this->viewData['successMessage'] = $message; $this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
@ -104,14 +104,15 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
$this->viewData['formAction'] = route_to('createTarifapreimpresion'); $this->viewData['formAction'] = route_to('createTarifapreimpresion');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Tarifapreimpresion.tarifapreimpresion').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Tarifapreimpresion.tarifapreimpresion') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
// JJO // JJO
$session = session(); $session = session();
@ -131,39 +132,37 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
if(isset($this->model->user_updated_id)){ if (isset($this->model->user_updated_id)) {
$sanitizedData['user_updated_id'] = $session->id_user; $sanitizedData['user_updated_id'] = $session->id_user;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData); $successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifapreimpresion.tarifapreimpresion'))]); $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifapreimpresion.tarifapreimpresion'))]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$tarifapreimpresionEntity->fill($sanitizedData);
$thenRedirect = false; endif;
$tarifapreimpresionEntity->fill($sanitizedData);
$thenRedirect = false;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifapreimpresionEntity->id ?? $id; $id = $tarifapreimpresionEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Tarifapreimpresion.tarifapreimpresion'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
//$message .= anchor(route_to('editTarifapreimpresion', $id), lang('Basic.global.continueEditing').'?');
//$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
@ -172,10 +171,9 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
return $this->redirect2listView('successMessage', $message); return $this->redirect2listView('successMessage', $message);
endif; endif;
else: else:
//JJO $this->session->setFlashData('sweet-success', $message);
$this->viewData['successMessage'] = $message;
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
@ -183,23 +181,23 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
$this->viewData['formAction'] = route_to('updateTarifapreimpresion', $id); $this->viewData['formAction'] = route_to('updateTarifapreimpresion', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Tarifapreimpresion.tarifapreimpresion').' '.lang('Basic.global.edit3'); $this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Tarifapreimpresion.tarifapreimpresion') . ' ' . lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -212,8 +210,9 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -224,8 +223,8 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -238,5 +237,5 @@ class Tarifapreimpresion extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403); return $this->failUnauthorized('Invalid request', 403);
} }
} }
} }

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Tarifas; <?php namespace App\Controllers\Tarifas;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Tarifas\TarifaEncuadernacionEntity;
use App\Models\Tarifas\TarifaEncuadernacionModel; use App\Models\Tarifas\TarifaEncuadernacionModel;
class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController { class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController
{
protected $modelName = TarifaEncuadernacionModel::class; protected $modelName = TarifaEncuadernacionModel::class;
protected $format = 'json'; protected $format = 'json';
@ -25,9 +26,9 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'tarifaEncuadernacionList'; protected $indexRoute = 'tarifaEncuadernacionList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Tarifaencuadernacion.moduleTitle'); $this->viewData['pageTitle'] = lang('Tarifaencuadernacion.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
@ -48,24 +49,26 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Tarifaencuadernacion.tarifaencuadernacion')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Tarifaencuadernacion.tarifaencuadernacion')]),
'tarifaEncuadernacionEntity' => new TarifaEncuadernacionEntity(), 'tarifaEncuadernacionEntity' => new TarifaEncuadernacionEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewTarifaEncuadernacionList', $viewData); return view(static::$viewPath . 'viewTarifaEncuadernacionList', $viewData);
} }
public function add() { public function add()
{
// JJO // JJO
$session = session(); $session = session();
@ -76,51 +79,47 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
if(isset($this->model->user_updated_id)){ if (isset($this->model->user_updated_id)) {
$sanitizedData['user_created_id'] = $session->id_user; $sanitizedData['user_created_id'] = $session->id_user;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifaencuadernacion.tarifaencuadernacion'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Tarifaencuadernacion.tarifaencuadernacion'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
//$message .= anchor( "tarifaencuadernacion/{$id}/edit" , lang('Basic.global.continueEditing').'?');
//$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(site_url('tarifas/tarifasencuadernacion/edit/'.$id))->with('sweet-success', $message); return redirect()->to(site_url('tarifas/tarifasencuadernacion/edit/' . $id))->with('sweet-success', $message);
//return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); //return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
//JJO $this->session->setFlashData('sweet-success', $message);
$this->viewData['successMessage'] = $message;
//$this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
@ -131,17 +130,18 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
$this->viewData['formAction'] = site_url('tarifas/tarifasencuadernacion/add');//route_to('createTarifaEncuadernacion'); $this->viewData['formAction'] = site_url('tarifas/tarifasencuadernacion/add');//route_to('createTarifaEncuadernacion');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Tarifaencuadernacion.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Tarifaencuadernacion.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
// JJO // JJO
$session = session(); $session = session();
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -149,7 +149,7 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
$tarifaEncuadernacionEntity = $this->model->find($id); $tarifaEncuadernacionEntity = $this->model->find($id);
if ($tarifaEncuadernacionEntity == false) : if ($tarifaEncuadernacionEntity == false) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Tarifaencuadernacion.tarifaencuadernacion')), $id]); $message = lang('Basic.global.notFoundWithIdErr', [lang('Basic.global.record'), $id]);
return $this->redirect2listView('sweet-error', $message); return $this->redirect2listView('sweet-error', $message);
endif; endif;
@ -158,16 +158,16 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
if(isset($this->model->user_updated_id)){ if (isset($this->model->user_updated_id)) {
$sanitizedData['user_updated_id'] = $session->id_user; $sanitizedData['user_updated_id'] = $session->id_user;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
@ -178,23 +178,21 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifaencuadernacion.tarifaencuadernacion'))]); $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$tarifaEncuadernacionEntity->fill($sanitizedData); $tarifaEncuadernacionEntity->fill($sanitizedData);
$thenRedirect = false; $thenRedirect = false;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifaEncuadernacionEntity->id ?? $id; $id = $tarifaEncuadernacionEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Tarifaencuadernacion.tarifaencuadernacion'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
//$message .= anchor( "tarifa ulado/{$id}/edit" , lang('Basic.global.continueEditing').'?');
//$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
@ -202,28 +200,28 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
else: else:
$this->viewData['successMessage'] = $message; $this->viewData['successMessage'] = $message;
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['tarifaEncuadernacionEntity'] = $tarifaEncuadernacionEntity; $this->viewData['tarifaEncuadernacionEntity'] = $tarifaEncuadernacionEntity;
$this->viewData['formAction'] = route_to('updateTarifaEncuadernacion', $id); $this->viewData['formAction'] = route_to('updateTarifaEncuadernacion', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Tarifaencuadernacion.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Tarifaencuadernacion.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -245,15 +243,16 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -267,7 +266,8 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -278,8 +278,8 @@ class Tarifasencuadernacion extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Tarifas; <?php namespace App\Controllers\Tarifas;
use App\Controllers\GoBaseResourceController; use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Tarifas\TarifaManipuladoEntity;
use App\Models\Tarifas\TarifaManipuladoModel; use App\Models\Tarifas\TarifaManipuladoModel;
class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController { class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController
{
protected $modelName = TarifaManipuladoModel::class; protected $modelName = TarifaManipuladoModel::class;
protected $format = 'json'; protected $format = 'json';
@ -25,9 +26,9 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
protected $indexRoute = 'tarifaManipuladoList'; protected $indexRoute = 'tarifaManipuladoList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) { public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Tarifamanipulado.moduleTitle'); $this->viewData['pageTitle'] = lang('Tarifamanipulado.moduleTitle');
$this->viewData['usingSweetAlert'] = true; $this->viewData['usingSweetAlert'] = true;
@ -48,24 +49,26 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
} }
public function index() { public function index()
{
$viewData = [ $viewData = [
'currentModule' => static::$controllerSlug, 'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Tarifamanipulado.tarifamanipulado')]), 'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Tarifamanipulado.tarifamanipulado')]),
'tarifaManipuladoEntity' => new TarifaManipuladoEntity(), 'tarifaManipuladoEntity' => new TarifaManipuladoEntity(),
'usingServerSideDataTable' => true, 'usingServerSideDataTable' => true,
]; ];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class $viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath.'viewTarifaManipuladoList', $viewData); return view(static::$viewPath . 'viewTarifaManipuladoList', $viewData);
} }
public function add() { public function add()
{
// JJO // JJO
$session = session(); $session = session();
@ -76,51 +79,47 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
if(isset($this->model->user_updated_id)){ if (isset($this->model->user_updated_id)) {
$sanitizedData['user_created_id'] = $session->id_user; $sanitizedData['user_created_id'] = $session->id_user;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
try { try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData); $successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) { } catch (\Exception $e) {
$noException = false; $noException = false;
$this->dealWithException($e); $this->dealWithException($e);
} }
else: else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]); $this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$thenRedirect = true; // Change this to false if you want your user to stay on the form after submission $thenRedirect = true; // Change this to false if you want your user to stay on the form after submission
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $this->model->db->insertID(); $id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]).'.'; $message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
$message .= anchor( "tarifamanipulado/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(site_url('tarifas/tarifasmanipulado/edit/'.$id))->with('sweet-success', $message); return redirect()->to(site_url('tarifas/tarifasmanipulado/edit/' . $id))->with('sweet-success', $message);
//return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); //return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
endif; endif;
else: else:
//JJO $this->session->setFlashData('sweet-success', $message);
$this->viewData['successMessage'] = $message;
//$this->session->setFlashData('sweet-success', $message);
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
@ -131,17 +130,18 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
$this->viewData['formAction'] = site_url('tarifas/tarifasmanipulado/add');//route_to('createTarifaManipulado'); $this->viewData['formAction'] = site_url('tarifas/tarifasmanipulado/add');//route_to('createTarifaManipulado');
$this->viewData['boxTitle'] = lang('Basic.global.addNew').' '.lang('Tarifamanipulado.moduleTitle').' '.lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Tarifamanipulado.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
return $this->displayForm(__METHOD__); return $this->displayForm(__METHOD__);
} // end function add() } // end function add()
public function edit($requestedId = null) { public function edit($requestedId = null)
{
// JJO // JJO
$session = session(); $session = session();
if ($requestedId == null) : if ($requestedId == null) :
return $this->redirect2listView(); return $this->redirect2listView();
endif; endif;
@ -158,16 +158,16 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') : if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1'); $nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost(); $postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty); $sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO // JJO
if(isset($this->model->user_updated_id)){ if (isset($this->model->user_updated_id)) {
$sanitizedData['user_updated_id'] = $session->id_user; $sanitizedData['user_updated_id'] = $session->id_user;
} }
$noException = true; $noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) : if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) : if ($this->canValidate()) :
@ -180,21 +180,19 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
else: else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]); $this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]);
$this->session->setFlashdata('formErrors', $this->model->errors()); $this->session->setFlashdata('formErrors', $this->model->errors());
endif; endif;
$tarifaManipuladoEntity->fill($sanitizedData); $tarifaManipuladoEntity->fill($sanitizedData);
$thenRedirect = false; $thenRedirect = false;
endif; endif;
if ($noException && $successfulResult) : if ($noException && $successfulResult) :
$id = $tarifaManipuladoEntity->id ?? $id; $id = $tarifaManipuladoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Tarifamanipulado.tarifamanipulado'))]).'.'; $message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
//$message .= anchor( "tarifamanipulado/{$id}/edit" , lang('Basic.global.continueEditing').'?');
//$message = ucfirst(str_replace("'", "\'", $message));
if ($thenRedirect) : if ($thenRedirect) :
if (!empty($this->indexRoute)) : if (!empty($this->indexRoute)) :
return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message); return redirect()->to(route_to($this->indexRoute))->with('sweet-success', $message);
else: else:
return $this->redirect2listView('sweet-success', $message); return $this->redirect2listView('sweet-success', $message);
@ -202,28 +200,28 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
else: else:
$this->viewData['successMessage'] = $message; $this->viewData['successMessage'] = $message;
endif; endif;
endif; // $noException && $successfulResult endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post') endif; // ($requestMethod === 'post')
$this->viewData['tarifaManipuladoEntity'] = $tarifaManipuladoEntity; $this->viewData['tarifaManipuladoEntity'] = $tarifaManipuladoEntity;
$this->viewData['formAction'] = route_to('updateTarifaManipulado', $id); $this->viewData['formAction'] = route_to('updateTarifaManipulado', $id);
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Tarifamanipulado.moduleTitle') . ' ' . lang('Basic.global.edit3');
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Tarifamanipulado.moduleTitle').' '.lang('Basic.global.edit3');
return $this->displayForm(__METHOD__, $id); return $this->displayForm(__METHOD__, $id);
} // end function edit(...) } // end function edit(...)
public function datatable() { public function datatable()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$reqData = $this->request->getPost(); $reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns']) ) { if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.'; $errstr = 'No data available in response to this specific request.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr); $response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response; return $response;
} }
$start = $reqData['start'] ?? 0; $start = $reqData['start'] ?? 0;
@ -245,15 +243,16 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
} }
} }
public function allItemsSelect() { public function allItemsSelect()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$onlyActiveOnes = true; $onlyActiveOnes = true;
$reqVal = $this->request->getPost('val') ?? 'id'; $reqVal = $this->request->getPost('val') ?? 'id';
$menu = $this->model->getAllForMenu($reqVal.', nombre', 'nombre', $onlyActiveOnes, false); $menu = $this->model->getAllForMenu($reqVal . ', nombre', 'nombre', $onlyActiveOnes, false);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -'; $nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();
@ -267,7 +266,8 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
} }
} }
public function menuItems() { public function menuItems()
{
if ($this->request->isAJAX()) { if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[0]; $searchStr = goSanitize($this->request->getPost('searchTerm'))[0];
$reqId = goSanitize($this->request->getPost('id'))[0]; $reqId = goSanitize($this->request->getPost('id'))[0];
@ -278,8 +278,8 @@ class Tarifasmanipulado extends \App\Controllers\GoBaseResourceController {
$menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr); $menu = $this->model->getSelect2MenuItems($columns2select, $columns2select[1], $onlyActiveOnes, $searchStr);
$nonItem = new \stdClass; $nonItem = new \stdClass;
$nonItem->id = ''; $nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -'; $nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu , $nonItem); array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash(); $newTokenHash = csrf_hash();
$csrfTokenName = csrf_token(); $csrfTokenName = csrf_token();

View File

@ -63,7 +63,7 @@ return [
'pleaseSelect' => 'Por favor seleccione...', 'pleaseSelect' => 'Por favor seleccione...',
'pleaseSelectA' => 'Por favor seleccione un {0}... ', 'pleaseSelectA' => 'Por favor seleccione un {0}... ',
'pleaseSelectOne' => 'Por favor seleccione un...', 'pleaseSelectOne' => 'Por favor seleccione un...',
'record' => 'el registro', 'record' => 'registro',
'saveSuccess' => 'El {0} se ha guardado satisfactoriamente', 'saveSuccess' => 'El {0} se ha guardado satisfactoriamente',
'saveSuccess1' => 'El {0} ', 'saveSuccess1' => 'El {0} ',
'saveSuccess2' => ' se ha guardado satisfactoriamente', 'saveSuccess2' => ' se ha guardado satisfactoriamente',

View File

@ -10,32 +10,49 @@
<?= $this->section('additionalInlineJs') ?> <?= $this->section('additionalInlineJs') ?>
toastr.options = { toastr.options = {
"closeButton": false, "closeButton": false,
"debug": false, "debug": false,
"newestOnTop": false, "newestOnTop": false,
"progressBar": false, "progressBar": false,
"positionClass": "toast-top-right", "positionClass": "toast-top-right",
"preventDuplicates": false, "preventDuplicates": false,
"onclick": null, "onclick": null,
"showDuration": "300", "showDuration": "300",
"hideDuration": "1000", "hideDuration": "1000",
"timeOut": "5000", "timeOut": "5000",
"extendedTimeOut": "1000", "extendedTimeOut": "1000",
"showEasing": "swing", "showEasing": "swing",
"hideEasing": "linear", "hideEasing": "linear",
"showMethod": "fadeIn", "showMethod": "fadeIn",
"hideMethod": "fadeOut" "hideMethod": "fadeOut"
}; };
<?php if (session('sweet-success')) { ?> <?php if (session('sweet-success')) {
toastr.success(`<?= session('sweet-success') ?>`); if (isset($alertStyle) && ($alertStyle == 'toastr')) { ?>
<?php } ?> toastr.success(`<?= session('sweet-success') ?>`);
<?php if (session('sweet-warning')) { ?> <?php } else { ?>
toastr.success(`<?= session('sweet-warning') ?>`); popSuccessAlert(`<?= session('sweet-success') ?>`);
<?php } ?> <?php }
<?php if (session('sweet-error')) { ?> }
toastr.success(`<?= session('sweet-error') ?>`); ?>
<?php } ?>
<?php if (session('sweet-warning')) {
if (isset($alertStyle) && ($alertStyle == 'toastr')) { ?>
toastr.warning(`<?= session('sweet-warning') ?>`);
<?php } else { ?>
popWarningAlert(`<?= session('sweet-warning') ?>`);
<?php }
}
?>
<?php if (session('sweet-error')) {
if (isset($alertStyle) && ($alertStyle == 'toastr')) { ?>
toastr.error(`<?= session('sweet-error') ?>`);
<?php } else { ?>
popErrorgAlert(`<?= session('sweet-error') ?>`);
<?php }
}
?>
<?= $this->endSection() ?> <?= $this->endSection() ?>

View File

@ -134,7 +134,6 @@ if (!empty($token) && $tfa == false) {
aria-expanded="false" aria-expanded="false"
> >
<i class="ti ti-bell ti-md"></i> <i class="ti ti-bell ti-md"></i>
<span class="badge bg-danger rounded-pill badge-notifications">5</span>
</a> </a>
</li> </li>
<!--/ Notification --> <!--/ Notification -->