Continuo migrando, estoy perfilando activity y los settings

This commit is contained in:
imnavajas
2024-05-01 22:13:00 +02:00
parent dce9e08cf6
commit 54de3402f3
62 changed files with 698 additions and 425 deletions

View File

@ -0,0 +1,84 @@
<?php namespace App\Controllers\Sistema;
use App\Controllers\BaseResourceController;
use App\Entities\Sistema\ActivityEntity;
use App\Models\CollectionModel;
use App\Models\Sistema\ActivityModel;
class Actividad extends BaseResourceController
{
protected $modelName = ActivityModel::class;
protected $format = 'json';
protected static $controllerSlug = 'activity';
protected static string $viewPath = 'themes/backend/vuexy/form/activity/';
protected static $indexRoute = 'activityList';
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
$this->viewData['pageTitle'] = lang('Paises.moduleTitle');
// Breadcrumbs
$this->viewData['breadcrumb'] = [
['title' => "Home", 'route' => "javascript:void(0);", 'active' => false],
['title' => lang("App.menu_activity"), 'route' => route_to('activityList'), 'active' => true]
];
parent::initController($request, $response, $logger);
}
public function index()
{
$viewData = [
'pageSubTitle' => lang('Basic.global.ManageAllRecords', [lang('Paises.pais')]),
'activityEntity' => new ActivityEntity(),
'usingServerSideDataTable' => true,
'logs' => $this->model->getLogs()->get()->getResultArray()[0] // MEJORAR!!!
];
$viewData = array_merge($this->viewData, $viewData); // merge any possible values from the parent controller class
return view(static::$viewPath . static::$indexRoute, $viewData);
}
public function datatable()
{
if ($this->request->isAJAX()) {
$reqData = $this->request->getPost();
if (!isset($reqData['draw']) || !isset($reqData['columns'])) {
$errstr = 'No data available in response to this specific request.';
$response = $this->respond(CollectionModel::datatable([], 0, 0, $errstr), 400, $errstr);
return $response;
}
$start = $reqData['start'] ?? 0;
$length = $reqData['length'] ?? 5;
$search = $reqData['search']['value'];
$requestedOrder = $reqData['order']['0']['column'] ?? 1;
$order = ActivityModel::SORTABLE[$requestedOrder > 0 ? $requestedOrder : 1];
$dir = $reqData['order']['0']['dir'] ?? 'asc';
$resourceData = $this->model->getResource($search)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject();
return $this->respond(CollectionModel::datatable(
$resourceData,
$this->model->getResource()->countAllResults(),
$this->model->getResource($search)->countAllResults()
));
} else {
return $this->failUnauthorized('Invalid request', 403);
}
}
}

View File

@ -0,0 +1,100 @@
<?php namespace App\Controllers\Sistema;
use App\Controllers\BaseResourceController;
use App\Models\Sistema\SettingsModel;
class Ajustes extends BaseResourceController
{
protected $modelName = SettingsModel::class;
protected $format = 'json';
protected static $controllerSlug = 'settings';
protected static string $viewPath = 'themes/vuexy/form/settings/';
protected static string $formViewName = 'settingsForm';
protected $indexRoute = 'settingForm';
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 settings()
{
$id = 1;
$settingsEntity = $this->model->find($id);
if (!$settingsEntity) :
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Provincias.provincia')), $id]);
return $this->redirect2listView('sweet-error', $message);
endif;
if ($this->request->is('post')) :
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, true);
$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;
$settingsEntity->fill($sanitizedData);
$thenRedirect = false;
endif;
if ($noException && $successfulResult) :
$id = $settingsEntity->id ?? $id;
$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);
else:
return $this->redirect2listView('sweet-success', $message);
endif;
else:
$this->session->setFlashData('sweet-success', $message);
endif;
endif; // $noException && $successfulResult
endif; // ($requestMethod === 'post')
$this->viewData['settingsEntity'] = $settingsEntity;
$this->viewData['formAction'] = route_to('settingsEdit');
$this->viewData['tables'] = db_connect()->listTables();
return $this->displayForm(__METHOD__, $id);
} // end function settings(...)
}