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\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController;
@ -11,7 +11,8 @@ use App\Models\Configuracion\PaisModel;
use App\Models\Configuracion\ComunidadAutonomaModel;
class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ComunidadAutonomaModel::class;
protected $format = 'json';
@ -27,34 +28,35 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
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['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ComunidadesAutonomas.comunidadAutonoma')]),
'comunidadAutonomaEntity' => new ComunidadAutonomaEntity(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('ComunidadesAutonomas.comunidadAutonoma')]),
'comunidadAutonomaEntity' => new ComunidadAutonomaEntity(),
'usingServerSideDataTable' => true,
];
$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();
@ -63,39 +65,37 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]).'.';
$message .= anchor( "admin/comunidades-autonomas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -108,18 +108,19 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post')
$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['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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -136,73 +137,69 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $comunidadAutonomaEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('ComunidadesAutonomas.comunidadAutonoma'))]).'.';
$message .= anchor( "admin/comunidades-autonomas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$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);
} // end function edit(...)
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
@ -224,15 +221,16 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
}
}
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -246,7 +244,8 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -273,17 +272,18 @@ class Comunidadesautonomas extends \App\Controllers\GoBaseResourceController {
}
protected function getPaisListItems($selId = null) {
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
protected function getPaisListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
if (!empty($selId)) :
$paisModel = model('App\Models\Configuracion\PaisModel');
$paisModel = model('App\Models\Configuracion\PaisModel');
$selOption = $paisModel->where('id', $selId)->findColumn('id');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
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;
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';
@ -18,32 +19,34 @@ class Formaspago extends \App\Controllers\GoBaseController {
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');
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'));
}
if (session('successMessage')) {
}
if (session('successMessage')) {
$this->session->setFlashData('sweet-success', session('successMessage'));
}
}
}
public function index() {
public function index()
{
$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();
}
public function add() {
public function add()
{
$requestMethod = $this->request->getMethod();
@ -52,34 +55,32 @@ class Formaspago extends \App\Controllers\GoBaseController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaPago'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('FormasPagoes.formaPago'))]).'.';
$message .= anchor(route_to('editFormaPago', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -99,14 +100,15 @@ class Formaspago extends \App\Controllers\GoBaseController {
$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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -123,38 +125,35 @@ class Formaspago extends \App\Controllers\GoBaseController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $formasPagoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('FormasPagoes.formaPago'))]).'.';
$message .= anchor(route_to('editFormaPago', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -165,7 +164,7 @@ class Formaspago extends \App\Controllers\GoBaseController {
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
@ -173,23 +172,23 @@ class Formaspago extends \App\Controllers\GoBaseController {
$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);
} // end function edit(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -202,8 +201,9 @@ class Formaspago extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -228,5 +228,5 @@ class Formaspago extends \App\Controllers\GoBaseController {
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;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\FormaPagoEntity;
use App\Models\Configuracion\FormaPagoModel;
class Formaspagos extends \App\Controllers\GoBaseResourceController {
class Formaspagos extends \App\Controllers\GoBaseResourceController
{
protected $modelName = FormaPagoModel::class;
protected $format = 'json';
@ -25,34 +26,35 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
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['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaDePago')]),
'formaPagoEntity' => new FormaPagoEntity(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('FormasPagoes.formaDePago')]),
'formaPagoEntity' => new FormaPagoEntity(),
'usingServerSideDataTable' => true,
];
$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();
@ -61,39 +63,37 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('FormasPagoes.formaDePago'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('FormasPagoes.formaDePago'))]).'.';
$message .= anchor( "admin/formas-pagos/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -109,14 +109,15 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
$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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -133,72 +134,68 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $formaPagoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('FormasPagoes.formaDePago'))]).'.';
$message .= anchor( "admin/formas-pagos/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$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);
} // end function edit(...)
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
@ -220,15 +217,16 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
}
}
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -242,7 +240,8 @@ class Formaspagos extends \App\Controllers\GoBaseResourceController {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();

View File

@ -6,13 +6,13 @@ use App\Controllers\GoBaseResourceController;
use App\Models\Usuarios\UserGroupModel;
use App\Models\Usuarios\GroupUserModel;
class Group extends \App\Controllers\GoBaseController
class Group extends \App\Controllers\GoBaseController
{
use \CodeIgniter\API\ResponseTrait;
protected static $primaryModelName = 'App\Models\Usuarios\UserGroupModel';
protected $modelName = UserGroupModel::class;
protected static $singularObjectNameCc = 'userGroup';
protected static $singularObjectName = 'Group';
protected static $pluralObjectName = 'Groups';
@ -24,22 +24,23 @@ class Group extends \App\Controllers\GoBaseController
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');
self::$viewPath = getenv('theme.path').'form/group/';
self::$viewPath = getenv('theme.path') . 'form/group/';
parent::initController($request, $response, $logger);
}
public function index()
{
$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
$this->group_user_model = new GroupUserModel();
$this->viewData['model'] = $this->group_user_model;
parent::index();
}
@ -55,38 +56,36 @@ class Group extends \App\Controllers\GoBaseController
$postData = $this->request->getPost();
$title = $postData['title'];
$dashboard = $postData['dashboard'];
unset($postData['title']);
unset($postData['dashboard']);
unset($postData['id_group']);
unset($postData['save']);
$controller = null;
$rules_access = null;
foreach ($postData as $key=>$value){
$exp = explode('_',$key);
foreach ($postData as $key => $value) {
$exp = explode('_', $key);
$controller[] = $exp[0];
}
if($controller != null){
foreach (array_unique($controller) as $item){
if ($controller != null) {
foreach (array_unique($controller) as $item) {
$rules_access[$item] = [];
foreach ($postData as $key=>$value){
$exp = explode('_',$key);
if($exp[0] == $item){
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ;
foreach ($postData as $key => $value) {
$exp = explode('_', $key);
if ($exp[0] == $item) {
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['title'] = $title;
$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 ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Group.userGroup'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Group.userGroup'))]).'.';
$message .= anchor( "admin/user-groups/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -134,21 +131,22 @@ class Group extends \App\Controllers\GoBaseController
endif; // ($requestMethod === 'post')
$this->viewData['group'] = isset($sanitizedData) ? new UserGroupModel($sanitizedData) : new UserGroupModel();
$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__);
}
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
helper('general');
$session = session();
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -165,7 +163,7 @@ class Group extends \App\Controllers\GoBaseController
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$id_group = $groupEntity->id_group;
@ -180,62 +178,59 @@ class Group extends \App\Controllers\GoBaseController
$controller = null;
$rules_access = null;
foreach ($postData as $key=>$value){
$exp = explode('_',$key);
foreach ($postData as $key => $value) {
$exp = explode('_', $key);
$controller[] = $exp[0];
}
if($controller != null){
foreach (array_unique($controller) as $item){
if ($controller != null) {
foreach (array_unique($controller) as $item) {
$rules_access[$item] = [];
foreach ($postData as $key=>$value){
$exp = explode('_',$key);
if($exp[0] == $item){
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ;
foreach ($postData as $key => $value) {
$exp = explode('_', $key);
if ($exp[0] == $item) {
array_push($rules_access[$item], str_replace($exp[0] . '_', '', $key));
}
}
}
}
$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['title'] = $title;
$temp_data['dashboard'] = $dashboard;
$sanitizedData = $this->sanitized($temp_data, $nullIfEmpty);
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $groupEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Group.userGroup'))]).'.';
$message .= anchor(route_to('editGroup', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if($session->get('group') == $this->request->getPost('token')){
if ($session->get('group') == $this->request->getPost('token')) {
$session->set('rules', $temp_data['rules']);
}
if ($thenRedirect) :
@ -247,7 +242,7 @@ class Group extends \App\Controllers\GoBaseController
else:
$this->viewData['successMessage'] = $message;
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
@ -255,23 +250,23 @@ class Group extends \App\Controllers\GoBaseController
$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);
} // end function edit(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -284,8 +279,9 @@ class Group extends \App\Controllers\GoBaseController
return $this->failUnauthorized('Invalid request', 403);
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\Imposicion;
use App\Models\Configuracion\ImposicionModel;
class Imposiciones extends \App\Controllers\GoBaseResourceController {
class Imposiciones extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ImposicionModel::class;
protected $format = 'json';
@ -25,34 +26,35 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
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['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Imposiciones.imposicion')]),
'imposicion' => new Imposicion(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Imposiciones.imposicion')]),
'imposicion' => new Imposicion(),
'usingServerSideDataTable' => true,
];
$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();
@ -61,39 +63,37 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Imposiciones.imposicion'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Imposiciones.imposicion'))]).'.';
$message .= anchor( "admin/imposiciones/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -106,18 +106,19 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post')
$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['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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -134,73 +135,69 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $imposicion->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Imposiciones.imposicion'))]).'.';
$message .= anchor( "admin/imposiciones/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$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);
} // end function edit(...)
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
@ -222,15 +219,16 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
}
}
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->ancho = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->ancho = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -244,7 +242,8 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -271,14 +270,15 @@ class Imposiciones extends \App\Controllers\GoBaseResourceController {
}
protected function getOrientacionOptions() {
$orientacionOptions = [
'' => lang('Basic.global.pleaseSelect'),
'H' => 'H',
'V' => 'V',
];
return $orientacionOptions;
}
protected function getOrientacionOptions()
{
$orientacionOptions = [
'' => lang('Basic.global.pleaseSelect'),
'H' => 'H',
'V' => 'V',
];
return $orientacionOptions;
}
}

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\Maquina;
use App\Models\Configuracion\MaquinaModel;
class Maquinas extends \App\Controllers\GoBaseResourceController {
class Maquinas extends \App\Controllers\GoBaseResourceController
{
protected $modelName = MaquinaModel::class;
protected $format = 'json';
@ -25,9 +26,9 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
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['usingSweetAlert'] = true;
@ -48,24 +49,26 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Maquinas.maquina')]),
'maquina' => new Maquina(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Maquinas.maquina')]),
'maquina' => new Maquina(),
'usingServerSideDataTable' => true,
];
$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
$session = session();
@ -76,42 +79,40 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO
$sanitizedData['user_created_id'] = $session->id_user;
$sanitizedData['user_created_id'] = $session->id_user;
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Maquinas.maquina'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Maquinas.maquina'))]).'.';
$message .= anchor( "maquinas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
//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:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -124,18 +125,19 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post')
$this->viewData['maquina'] = isset($sanitizedData) ? new Maquina($sanitizedData) : new Maquina();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
// JJO
$session = session();
@ -156,61 +158,57 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('is_padre') == null ) {
$sanitizedData['is_padre'] = false;
}
if ($this->request->getPost('is_rotativa') == null ) {
$sanitizedData['is_rotativa'] = false;
}
if ($this->request->getPost('is_tinta') == null ) {
$sanitizedData['is_tinta'] = false;
}
if ($this->request->getPost('is_padre') == null) {
$sanitizedData['is_padre'] = false;
}
if ($this->request->getPost('is_rotativa') == null) {
$sanitizedData['is_rotativa'] = false;
}
if ($this->request->getPost('is_tinta') == null) {
$sanitizedData['is_tinta'] = false;
}
// JJO
$sanitizedData['user_updated_id'] = $session->id_user;
$sanitizedData['user_updated_id'] = $session->id_user;
$noException = true;
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
if($sanitizedData['alto'] < $sanitizedData['alto_impresion']){
if ($sanitizedData['alto'] < $sanitizedData['alto_impresion']) {
$successfulResult = false;
$this->viewData['errorMessage'] = lang('Maquinas.validation.alto_menor_alto_impresion');;
$this->session->setFlashdata('formErrors', $this->model->errors());
}
else if ($sanitizedData['ancho'] < $sanitizedData['ancho_impresion']){
$this->session->setFlashdata('formErrors', $this->model->errors());
} else if ($sanitizedData['ancho'] < $sanitizedData['ancho_impresion']) {
$successfulResult = false;
$this->viewData['errorMessage'] = lang('Maquinas.validation.ancho_menor_ancho_impresion');;
$this->session->setFlashdata('formErrors', $this->model->errors());
}
else{
try {
$this->session->setFlashdata('formErrors', $this->model->errors());
} else {
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('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;
if ($noException && $successfulResult) :
$id = $maquina->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Maquinas.maquina'))]).'.';
$message .= anchor( "maquinas/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -221,30 +219,30 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['maquina'] = $maquina;
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquina->padre_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$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);
} // end function edit(...)
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
@ -255,11 +253,11 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$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) :
$item->observaciones = character_limiter($item->observaciones, 100);
endif;
endforeach;
endforeach;
return $this->respond(Collection::datatable(
$resourceData,
@ -271,15 +269,16 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
}
}
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -293,7 +292,8 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -320,29 +320,31 @@ class Maquinas extends \App\Controllers\GoBaseResourceController {
}
protected function getMaquinaListItems($selId = null) {
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
protected function getMaquinaListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
if (!empty($selId)) :
$maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$selOption = $maquinaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
endif;
endif;
return $data;
}
return $data;
}
protected function getTipoOptions() {
$tipoOptions = [
'' => lang('Basic.global.pleaseSelect'),
'impresion' => 'impresion',
'manipulado' => 'manipulado',
'acabado' => 'acabado',
];
return $tipoOptions;
}
protected function getTipoOptions()
{
$tipoOptions = [
'' => lang('Basic.global.pleaseSelect'),
'impresion' => 'impresion',
'manipulado' => 'manipulado',
'acabado' => 'acabado',
];
return $tipoOptions;
}
}

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController;
@ -11,7 +11,8 @@ use App\Models\Configuracion\MaquinaModel;
use App\Models\Configuracion\MaquinasDefectoModel;
class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
class Maquinasdefecto extends \App\Controllers\GoBaseResourceController
{
protected $modelName = MaquinasDefectoModel::class;
protected $format = 'json';
@ -27,9 +28,9 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
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['usingSweetAlert'] = true;
@ -42,24 +43,26 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasPorDefecto.maquinaPorDefecto')]),
'maquinasDefectoEntity' => new MaquinasDefectoEntity(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasPorDefecto.maquinaPorDefecto')]),
'maquinasDefectoEntity' => new MaquinasDefectoEntity(),
'usingServerSideDataTable' => true,
];
$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
$session = session();
@ -70,46 +73,43 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO
$sanitizedData['user_created_id'] = $session->id_user;
$noException = true;
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.
// En caso de error se devuelve un mensaje.
try {
try {
$error = $this->model->checkIntervals($sanitizedData);
if(empty($error)){
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
}
else{
if (empty($error)) {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} else {
$successfulResult = false;
$this->viewData['errorMessage'] = $error;
$this->session->setFlashdata('formErrors', $this->model->errors());
$this->session->setFlashdata('formErrors', $this->model->errors());
}
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]);
$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
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]).'.';
$message .= anchor( "configuracion/maquinasdefecto/edit/{$id}" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -126,19 +126,20 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post')
$this->viewData['maquinasDefectoEntity'] = isset($sanitizedData) ? new MaquinasDefectoEntity($sanitizedData) : new MaquinasDefectoEntity();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
// JJO
$session = session();
@ -158,49 +159,46 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
// JJO
$sanitizedData['user_updated_id'] = $session->id_user;
$noException = true;
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.
// En caso de error se devuelve un mensaje.
try {
$error = $this->model->checkIntervals($sanitizedData, $id);
if(empty($error)){
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
}
else{
if (empty($error)) {
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
} else {
$successfulResult = false;
$this->viewData['errorMessage'] = $error;
$this->session->setFlashdata('formErrors', $this->model->errors());
$this->session->setFlashdata('formErrors', $this->model->errors());
}
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
endif;
$maquinasDefectoEntity->fill($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['warningMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]);
$this->session->setFlashdata('formErrors', $this->model->errors());
$thenRedirect = true;
endif;
$maquinasDefectoEntity->fill($sanitizedData);
$thenRedirect = true;
endif;
if ($noException && $successfulResult) :
$id = $maquinasDefectoEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('MaquinasPorDefecto.maquinaPorDefecto'))]).'.';
$message .= anchor( "maquinasdefecto/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -211,30 +209,30 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['maquinasDefectoEntity'] = $maquinasDefectoEntity;
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasDefectoEntity->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$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);
} // end function edit(...)
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
@ -259,15 +257,16 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
}
}
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->tipo = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->tipo = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -281,7 +280,8 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -308,32 +308,34 @@ class Maquinasdefecto extends \App\Controllers\GoBaseResourceController {
}
protected function getMaquinaListItems($selId = null) {
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
protected function getMaquinaListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
if (!empty($selId)) :
$maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$selOption = $maquinaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
endif;
endif;
return $data;
}
return $data;
}
protected function getTipoOptions() {
$tipoOptions = [
'' => lang('Basic.global.pleaseSelect'),
'bn' => 'bn',
'bnhq' => 'bnhq',
'color' => 'color',
'portada' => 'portada',
'cubierta' => 'cubierta',
'rotativa' => 'rotativa',
];
return $tipoOptions;
}
protected function getTipoOptions()
{
$tipoOptions = [
'' => lang('Basic.global.pleaseSelect'),
'bn' => 'bn',
'bnhq' => 'bnhq',
'color' => 'color',
'portada' => 'portada',
'cubierta' => 'cubierta',
'rotativa' => 'rotativa',
];
return $tipoOptions;
}
//sanitiezdata

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController;
@ -22,7 +22,8 @@ use
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController {
class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
{
protected $modelName = MaquinasTarifasImpresionModel::class;
protected $format = 'json';
@ -38,34 +39,35 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
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['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasTarifasImpresions.maquinasTarifaImpresion')]),
'maquinasTarifasImpresion' => new MaquinasTarifasImpresion(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('MaquinasTarifasImpresions.maquinasTarifaImpresion')]),
'maquinasTarifasImpresion' => new MaquinasTarifasImpresion(),
'usingServerSideDataTable' => true,
];
$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();
@ -74,35 +76,33 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]).'.';
$message .= anchor( "maquinastarifasimpresion/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -119,19 +119,20 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
endif; // ($requestMethod === 'post')
$this->viewData['maquinasTarifasImpresion'] = isset($sanitizedData) ? new MaquinasTarifasImpresion($sanitizedData) : new MaquinasTarifasImpresion();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -148,43 +149,39 @@ class Maquinastarifasimpresion extends \App\Controllers\GoBaseResourceController
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('predeterminado') == null ) {
$sanitizedData['predeterminado'] = false;
}
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('predeterminado') == null) {
$sanitizedData['predeterminado'] = false;
}
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $maquinasTarifasImpresion->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('MaquinasTarifasImpresions.maquinasTarifaImpresion'))]).'.';
$message .= anchor( "maquinastarifasimpresion/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -195,110 +192,110 @@ if ($this->request->getPost('predeterminado') == null ) {
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['maquinasTarifasImpresion'] = $maquinasTarifasImpresion;
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null);
$this->viewData['tipoList'] = $this->getTipoOptions();
$this->viewData['maquinaList'] = $this->getMaquinaListItems($maquinasTarifasImpresion->maquina_id ?? null);
$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);
} // end function edit(...)
public function datatable_editor() {
public function datatable_editor()
{
if ($this->request->isAJAX()) {
include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php");
// Build our Editor instance and process the data coming from _POST
$response = Editor::inst( $db, 'lg_maquinas_tarifas_impresion' )
->fields(
Field::inst( 'uso' )
->validator( 'Validate::notEmpty',array(
'message' => lang('MaquinasTarifasImpresions.validation.uso.required') )
),
Field::inst( 'tipo' )
->validator( 'Validate::notEmpty',array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required') )
),
Field::inst( 'precio' )
->validator( 'Validate::numeric', array(
'message' => lang('MaquinasTarifasImpresions.validation.precio.decimal') )
)
->validator( 'Validate::notEmpty',array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required') )
),
Field::inst( 'maquina_id' ),
Field::inst( 'user_created_id' ),
Field::inst( 'created_at' ),
Field::inst( 'user_updated_id' ),
Field::inst( 'updated_at' ),
Field::inst( 'is_deleted' ),
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');
}
$response = Editor::inst($db, 'lg_maquinas_tarifas_impresion')
->fields(
Field::inst('uso')
->validator('Validate::notEmpty', array(
'message' => lang('MaquinasTarifasImpresions.validation.uso.required'))
),
Field::inst('tipo')
->validator('Validate::notEmpty', array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required'))
),
Field::inst('precio')
->validator('Validate::numeric', array(
'message' => lang('MaquinasTarifasImpresions.validation.precio.decimal'))
)
->validator('Validate::notEmpty', array(
'message' => lang('MaquinasTarifasImpresions.validation.tipo.required'))
),
Field::inst('maquina_id'),
Field::inst('user_created_id'),
Field::inst('created_at'),
Field::inst('user_updated_id'),
Field::inst('updated_at'),
Field::inst('is_deleted'),
Field::inst('deleted_at'),
$builder = $this->model->select('*')
->where(array(
'maquina_id'=> $values['maquina_id'],
'tipo'=> $values['tipo'],
'uso'=> $values['uso'],
'is_deleted'=> 0));
)
->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');
}
// 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');
$builder = $this->model->select('*')
->where(array(
'maquina_id' => $values['maquina_id'],
'tipo' => $values['tipo'],
'uso' => $values['uso'],
'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 ) {
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$editor
->field( 'user_created_id' )
->setValue( $session->id_user );
$editor
->field( 'created_at' )
->setValue( $datetime->format('Y-m-d H:i:s') );
} )
->on( 'preEdit', function ( $editor, &$values ) {
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$editor
->field( 'user_updated_id' )
->setValue( $session->id_user );
$editor
->field( 'updated_at' )
->setValue( $datetime->format('Y-m-d H:i:s') );
} )
->debug(true)
->process( $_POST )
->data();
})
->on('preCreate', function ($editor, &$values) {
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$editor
->field('user_created_id')
->setValue($session->id_user);
$editor
->field('created_at')
->setValue($datetime->format('Y-m-d H:i:s'));
})
->on('preEdit', function ($editor, &$values) {
$session = session();
$datetime = (new \CodeIgniter\I18n\Time("now"));
$editor
->field('user_updated_id')
->setValue($session->id_user);
$editor
->field('updated_at')
->setValue($datetime->format('Y-m-d H:i:s'));
})
->debug(true)
->process($_POST)
->data();
/*// if unique key is set in DB
if(isset($response['error'])){
if(str_contains($response['error'], "tirada_min_tirada_max") &&
@ -307,10 +304,10 @@ if ($this->request->getPost('predeterminado') == null ) {
}
}*/
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
$csrfTokenName = csrf_token();
$response[$csrfTokenName] = $newTokenHash;
echo json_encode($response);
} else {
@ -318,12 +315,13 @@ if ($this->request->getPost('predeterminado') == null ) {
}
}
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
@ -347,15 +345,16 @@ if ($this->request->getPost('predeterminado') == null ) {
}
}
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->maquina_id = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->maquina_id = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -369,7 +368,8 @@ if ($this->request->getPost('predeterminado') == null ) {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -396,30 +396,32 @@ if ($this->request->getPost('predeterminado') == null ) {
}
protected function getMaquinaListItems($selId = null) {
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
protected function getMaquinaListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Maquinas.maquina'))])];
if (!empty($selId)) :
$maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$maquinaModel = model('App\Models\Configuracion\MaquinaModel');
$selOption = $maquinaModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
endif;
endif;
return $data;
}
return $data;
}
protected function getTipoOptions() {
$tipoOptions = [
'' => lang('Basic.global.pleaseSelect'),
'negro' => 'negro',
'color' => 'color',
'negrohq' => 'negrohq',
'bicolor' => 'bicolor',
];
return $tipoOptions;
}
protected function getTipoOptions()
{
$tipoOptions = [
'' => lang('Basic.global.pleaseSelect'),
'negro' => 'negro',
'color' => 'color',
'negrohq' => 'negrohq',
'bicolor' => 'bicolor',
];
return $tipoOptions;
}
}

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController;
@ -9,7 +9,8 @@ use App\Entities\Configuracion\PaisEntity;
use App\Models\Configuracion\PaisModel;
class Paises extends \App\Controllers\GoBaseResourceController {
class Paises extends \App\Controllers\GoBaseResourceController
{
protected $modelName = PaisModel::class;
protected $format = 'json';
@ -25,34 +26,35 @@ class Paises extends \App\Controllers\GoBaseResourceController {
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['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]),
'paisEntity' => new PaisEntity(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]),
'paisEntity' => new PaisEntity(),
'usingServerSideDataTable' => true,
];
$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();
@ -61,39 +63,37 @@ class Paises extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Paises.pais'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Paises.pais'))]).'.';
$message .= anchor( "admin/paises/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -109,14 +109,15 @@ class Paises extends \App\Controllers\GoBaseResourceController {
$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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -133,75 +134,71 @@ class Paises extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('show_erp') == null ) {
$sanitizedData['show_erp'] = false;
}
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
if ($this->request->getPost('show_erp') == null) {
$sanitizedData['show_erp'] = false;
}
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $paisEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Paises.pais'))]).'.';
$message .= anchor( "admin/paises/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$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);
} // end function edit(...)
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$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()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -245,7 +243,8 @@ if ($this->request->getPost('show_erp') == null ) {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
<?php namespace App\Controllers\Configuracion;
<?php namespace App\Controllers\Configuracion;
use App\Controllers\GoBaseResourceController;
@ -11,7 +11,8 @@ use App\Models\Configuracion\PaisModel;
use App\Models\Configuracion\ProvinciaModel;
class Provincias extends \App\Controllers\GoBaseResourceController {
class Provincias extends \App\Controllers\GoBaseResourceController
{
protected $modelName = ProvinciaModel::class;
protected $format = 'json';
@ -27,34 +28,35 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
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['usingSweetAlert'] = true;
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$viewData = [
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Provincias.provincia')]),
'provinciaEntity' => new ProvinciaEntity(),
'usingServerSideDataTable' => true,
];
'currentModule' => static::$controllerSlug,
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Provincias.provincia')]),
'provinciaEntity' => new ProvinciaEntity(),
'usingServerSideDataTable' => true,
];
$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();
@ -63,39 +65,37 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('Provincias.provincia'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('Provincias.provincia'))]).'.';
$message .= anchor( "admin/provincias/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
@ -108,18 +108,19 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
endif; // ($requestMethod === 'post')
$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['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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -136,73 +137,69 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $provinciaEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Provincias.provincia'))]).'.';
$message .= anchor( "admin/provincias/{$id}/edit" , lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
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:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$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);
} // end function edit(...)
public function datatable() {
public function datatable()
{
if ($this->request->isAJAX()) {
$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.';
$response = $this->respond(Collection::datatable( [], 0, 0, $errstr ), 400, $errstr);
$response = $this->respond(Collection::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
@ -224,15 +221,16 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
}
}
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -246,7 +244,8 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -273,17 +272,18 @@ class Provincias extends \App\Controllers\GoBaseResourceController {
}
protected function getPaisListItems($selId = null) {
$data = [''=>lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
protected function getPaisListItems($selId = null)
{
$data = ['' => lang('Basic.global.pleaseSelectA', [mb_strtolower(lang('Paises.pais'))])];
if (!empty($selId)) :
$paisModel = model('App\Models\Configuracion\PaisModel');
$paisModel = model('App\Models\Configuracion\PaisModel');
$selOption = $paisModel->where('id', $selId)->findColumn('nombre');
if (!empty($selOption)) :
$data[$selId] = $selOption[0];
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;
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';
@ -18,26 +19,27 @@ class Tipologias extends \App\Controllers\GoBaseController {
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');
parent::initController($request, $response, $logger);
}
public function index() {
public function index()
{
$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();
}
public function add() {
public function add()
{
$requestMethod = $this->request->getMethod();
@ -46,34 +48,32 @@ class Tipologias extends \App\Controllers\GoBaseController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]);
$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
if ($this->canValidate()) :
try {
$successfulResult = $this->model->skipValidation(true)->save($sanitizedData);
} catch (\Exception $e) {
$noException = false;
$this->dealWithException($e);
}
else:
$this->viewData['errorMessage'] = lang('Basic.global.formErr1', [lang('Basic.global.record')]);
$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
endif;
if ($noException && $successfulResult) :
$id = $this->model->db->insertID();
$message = lang('Basic.global.saveSuccess', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]).'.';
$message .= anchor(route_to('editTipologiaLibros', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.saveSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -93,14 +93,15 @@ class Tipologias extends \App\Controllers\GoBaseController {
$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__);
} // end function add()
public function edit($requestedId = null) {
public function edit($requestedId = null)
{
if ($requestedId == null) :
return $this->redirect2listView();
endif;
@ -117,39 +118,35 @@ class Tipologias extends \App\Controllers\GoBaseController {
if ($requestMethod === 'post') :
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$noException = true;
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;
if ($noException && $successfulResult) :
$id = $tipologiasEntity->id ?? $id;
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('TipologiasLibros.tipologiaLibros'))]).'.';
$message .= anchor(route_to('editTipologiaLibros', $id), lang('Basic.global.continueEditing').'?');
$message = ucfirst(str_replace("'", "\'", $message));
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
if ($thenRedirect) :
if (!empty($this->indexRoute)) :
@ -160,7 +157,7 @@ class Tipologias extends \App\Controllers\GoBaseController {
else:
$this->viewData['successMessage'] = $message;
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
@ -168,23 +165,23 @@ class Tipologias extends \App\Controllers\GoBaseController {
$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);
} // end function edit(...)
public function allItemsSelect() {
public function allItemsSelect()
{
if ($this->request->isAJAX()) {
$onlyActiveOnes = true;
$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->id = '';
$nonItem->nombre = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->nombre = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -197,8 +194,9 @@ class Tipologias extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function menuItems() {
public function menuItems()
{
if ($this->request->isAJAX()) {
$searchStr = goSanitize($this->request->getPost('searchTerm'))[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);
$nonItem = new \stdClass;
$nonItem->id = '';
$nonItem->text = '- '.lang('Basic.global.None').' -';
array_unshift($menu , $nonItem);
$nonItem->text = '- ' . lang('Basic.global.None') . ' -';
array_unshift($menu, $nonItem);
$newTokenHash = csrf_hash();
$csrfTokenName = csrf_token();
@ -223,5 +221,5 @@ class Tipologias extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403);
}
}
}