mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Completada visualizacion y traduccion de roles y permisos
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
use App\Models\Usuarios\GroupModel;
|
||||
use App\Models\Usuarios\GroupsUsersModel;
|
||||
use App\Models\Usuarios\PermisosModel;
|
||||
|
||||
class Group extends \App\Controllers\GoBaseController
|
||||
{
|
||||
@ -24,9 +25,14 @@ class Group extends \App\Controllers\GoBaseController
|
||||
|
||||
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/';
|
||||
|
||||
// Breadcrumbs
|
||||
$this->viewData['breadcrumb'] = [
|
||||
['title' => "Home", 'route' => "javascript:void(0);", 'active' => false],
|
||||
['title' => lang("App.menu_permission_group"), 'route' => site_url("configuracion/group"), 'active' => true]
|
||||
];
|
||||
|
||||
parent::initController($request, $response, $logger);
|
||||
|
||||
}
|
||||
@ -47,46 +53,35 @@ class Group extends \App\Controllers\GoBaseController
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$temp_data['id'] = $groupEntity->id;
|
||||
$temp_data['name'] = $postData['name'];
|
||||
$temp_data['description'] = $postData['description'];
|
||||
|
||||
$name = $postData['name'];
|
||||
unset($postData['name']);
|
||||
// Clear not rules fields
|
||||
unset($postData['safekat_token']);
|
||||
unset($postData['id']);
|
||||
unset($postData['name']);
|
||||
unset($postData['description']);
|
||||
unset($postData['save']);
|
||||
unset($postData['selectAll']);
|
||||
|
||||
$controller = null;
|
||||
$rules_access = null;
|
||||
|
||||
$rules_access = [];
|
||||
foreach ($postData as $key => $value) {
|
||||
$exp = explode('_', $key);
|
||||
$controller[] = $exp[0];
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
if (!isset($rules_access[$exp[0]])) {
|
||||
$rules_access[$exp[0]] = [];
|
||||
}
|
||||
array_push($rules_access[$exp[0]], str_replace($exp[0] . '_', '', $key));
|
||||
}
|
||||
|
||||
|
||||
$temp_data['rules'] = json_encode($rules_access ?? '{}');
|
||||
$temp_data['name'] = $name;
|
||||
|
||||
$sanitizedData = $this->sanitized($temp_data, $nullIfEmpty);
|
||||
$sanitizedData = $this->sanitized($temp_data, true);
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
if ($successfulResult = $this->canValidate()) :
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
@ -123,9 +118,8 @@ class Group extends \App\Controllers\GoBaseController
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['group'] = isset($sanitizedData) ? new GroupModel($sanitizedData) : new GroupModel();
|
||||
$this->viewData['permisos'] = (new PermisosModel())->find();
|
||||
$this->viewData['formAction'] = route_to('createGroup');
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . lang('Group.moduleTitle') . ' ' . lang('Basic.global.addNewSuffix');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__);
|
||||
}
|
||||
@ -135,7 +129,6 @@ class Group extends \App\Controllers\GoBaseController
|
||||
{
|
||||
|
||||
helper('general');
|
||||
$session = session();
|
||||
|
||||
if ($requestedId == null) :
|
||||
return $this->redirect2listView();
|
||||
@ -148,49 +141,37 @@ class Group extends \App\Controllers\GoBaseController
|
||||
return $this->redirect2listView('errorMessage', $message);
|
||||
endif;
|
||||
|
||||
|
||||
|
||||
if ($this->request->getPost()) :
|
||||
|
||||
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
||||
|
||||
$postData = $this->request->getPost();
|
||||
|
||||
$id_group = $groupEntity->id;
|
||||
$name = $postData['name'];
|
||||
$temp_data['id'] = $groupEntity->id;
|
||||
$temp_data['name'] = $postData['name'];
|
||||
$temp_data['description'] = $postData['description'];
|
||||
|
||||
// Clear not rules fields
|
||||
unset($postData['safekat_token']);
|
||||
unset($postData['id']);
|
||||
unset($postData['name']);
|
||||
unset($postData['description']);
|
||||
unset($postData['save']);
|
||||
unset($postData['selectAll']);
|
||||
|
||||
$controller = null;
|
||||
$rules_access = null;
|
||||
|
||||
$rules_access = [];
|
||||
foreach ($postData as $key => $value) {
|
||||
$exp = explode('_', $key);
|
||||
$controller[] = $exp[0];
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
if (!isset($rules_access[$exp[0]])) {
|
||||
$rules_access[$exp[0]] = [];
|
||||
}
|
||||
array_push($rules_access[$exp[0]], str_replace($exp[0] . '_', '', $key));
|
||||
}
|
||||
|
||||
$temp_data['id'] = $id_group;
|
||||
$temp_data['rules'] = json_encode($rules_access ?? '{}');
|
||||
$temp_data['name'] = $name;
|
||||
|
||||
$sanitizedData = $this->sanitized($temp_data, $nullIfEmpty);
|
||||
$sanitizedData = $this->sanitized($temp_data, true);
|
||||
|
||||
$noException = true;
|
||||
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
|
||||
|
||||
if ($successfulResult = $this->canValidate()) :
|
||||
|
||||
if ($this->canValidate()) :
|
||||
try {
|
||||
@ -209,13 +190,11 @@ class Group extends \App\Controllers\GoBaseController
|
||||
|
||||
$thenRedirect = false;
|
||||
endif;
|
||||
|
||||
if ($noException && $successfulResult) :
|
||||
$id = $groupEntity->id ?? $id;
|
||||
$message = lang('Basic.global.updateSuccess', [lang('Basic.global.record')]) . '.';
|
||||
|
||||
if ($session->get('group') == $this->request->getPost('token')) {
|
||||
$session->set('rules', $temp_data['rules']);
|
||||
}
|
||||
if ($thenRedirect) :
|
||||
if (!empty($this->indexRoute)) :
|
||||
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
||||
@ -230,9 +209,8 @@ class Group extends \App\Controllers\GoBaseController
|
||||
endif; // ($requestMethod === 'post')
|
||||
|
||||
$this->viewData['group'] = $groupEntity;
|
||||
$this->viewData['permisos'] = (new PermisosModel())->find();
|
||||
$this->viewData['formAction'] = route_to('updateGroup', $id);
|
||||
$this->viewData['boxTitle'] = lang('Basic.global.edit2') . ' ' . lang('Group.userGroup') . ' ' . lang('Basic.global.edit3');
|
||||
|
||||
|
||||
return $this->displayForm(__METHOD__, $id);
|
||||
} // end function edit(...)
|
||||
|
||||
Reference in New Issue
Block a user