mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
292 lines
10 KiB
PHP
292 lines
10 KiB
PHP
<?php namespace App\Controllers\Usuarios;
|
|
|
|
use App\Entities\Usuarios\UserGroupEntity;
|
|
|
|
use App\Controllers\GoBaseResourceController;
|
|
use App\Models\Usuarios\UserGroupModel;
|
|
|
|
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';
|
|
protected static $controllerSlug = 'groups';
|
|
|
|
static $viewPath = '';
|
|
|
|
protected $indexRoute = 'groupList';
|
|
|
|
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/';
|
|
|
|
parent::initController($request, $response, $logger);
|
|
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->viewData['usingClientSideDataTable'] = true;
|
|
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Groups.group')]);
|
|
|
|
parent::index();
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
helper('form');
|
|
|
|
$data['title'] = [
|
|
'module' => lang("App.group_add_title"),
|
|
'page' => lang("App.group_add_subtitle"),
|
|
'icon' => 'far fa-plus-square'
|
|
];
|
|
|
|
$data['breadcrumb'] = [
|
|
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
|
['title' => lang("App.group_title"), 'route' => "/usuarios/group", 'active' => false],
|
|
['title' => lang("App.group_add_title"), 'route' => "", 'active' => true]
|
|
];
|
|
|
|
$data['btn_return'] = [
|
|
'title' => lang("App.global_come_back"),
|
|
'route' => 'usuarios/group',
|
|
'class' => 'btn btn-dark mr-1',
|
|
'icon' => 'fas fa-angle-left'
|
|
];
|
|
|
|
$data['btn_submit'] = [
|
|
'title' => lang("App.global_save"),
|
|
'route' => '',
|
|
'class' => 'btn btn-primary mr-1',
|
|
'icon' => 'fas fa-save'
|
|
];
|
|
|
|
echo view(getenv('theme.path').'main/header');
|
|
echo view(getenv('theme.path').'form/group/form',$data);
|
|
echo view(getenv('theme.path').'main/footer');
|
|
}
|
|
|
|
//public function edit($id)
|
|
public function edit($requestedId = null)
|
|
{
|
|
|
|
if ($requestedId == null) :
|
|
return $this->redirect2listView();
|
|
endif;
|
|
$id = filter_var($requestedId, FILTER_SANITIZE_URL);
|
|
$group = $this->model->find($id);
|
|
|
|
if ($group == false) :
|
|
$message = lang('Basic.global.notFoundWithIdErr', [mb_strtolower(lang('Paises.pais')), $id]);
|
|
return $this->redirect2listView('errorMessage', $message);
|
|
endif;
|
|
|
|
$requestMethod = $this->request->getMethod();
|
|
|
|
if ($requestMethod === 'post') :
|
|
|
|
$nullIfEmpty = true; // !(phpversion() >= '8.1');
|
|
|
|
$postData = $this->request->getPost();
|
|
$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('Paises.pais'))]);
|
|
$this->session->setFlashdata('formErrors', $this->model->errors());
|
|
|
|
endif;
|
|
|
|
$group->fill($sanitizedData);
|
|
|
|
$thenRedirect = true;
|
|
endif;
|
|
if ($noException && $successfulResult) :
|
|
$id = $group->id ?? $id;
|
|
$message = lang('Basic.global.updateSuccess', [mb_strtolower(lang('Group.group'))]).'.';
|
|
$message .= anchor(route_to('editGroup', $id), lang('Basic.global.continueEditing').'?');
|
|
$message = ucfirst(str_replace("'", "\'", $message));
|
|
|
|
if ($thenRedirect) :
|
|
if (!empty($this->indexRoute)) :
|
|
return redirect()->to(route_to($this->indexRoute))->with('successMessage', $message);
|
|
else:
|
|
return $this->redirect2listView('successMessage', $message);
|
|
endif;
|
|
else:
|
|
$this->viewData['successMessage'] = $message;
|
|
endif;
|
|
|
|
endif; // $noException && $successfulResult
|
|
endif; // ($requestMethod === 'post')
|
|
|
|
$this->viewData['group'] = $group;
|
|
|
|
$this->viewData['formAction'] = route_to('updateGroup', $id);
|
|
|
|
$this->viewData['boxTitle'] = lang('Basic.global.edit2').' '.lang('Paises.pais').' '.lang('Basic.global.edit3');
|
|
|
|
|
|
return $this->displayForm(__METHOD__, $id);
|
|
/*
|
|
helper('form');
|
|
|
|
$data['title'] = [
|
|
'module' => lang("App.group_edit_title"),
|
|
'page' => lang("App.group_edit_subtitle"),
|
|
'icon' => 'fas fa-edit'
|
|
];
|
|
|
|
$data['breadcrumb'] = [
|
|
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
|
['title' => lang("App.group_title"), 'route' => "/group", 'active' => false],
|
|
['title' => lang("App.group_edit_title"), 'route' => "", 'active' => true]
|
|
];
|
|
|
|
$data['btn_return'] = [
|
|
'title' => lang("App.global_come_back"),
|
|
'route' => 'usuarios/group',
|
|
'class' => 'btn btn-dark mr-1',
|
|
'icon' => 'fas fa-angle-left'
|
|
];
|
|
|
|
$data['btn_submit'] = [
|
|
'title' => lang("App.global_save"),
|
|
'route' => '',
|
|
'class' => 'btn btn-primary mr-1',
|
|
'icon' => 'fas fa-save'
|
|
];
|
|
|
|
$data['obj'] = $this->group_model->where('token', $id)->first();
|
|
if($data['obj']==null){
|
|
return redirect()->to('/usuarios/group');
|
|
}
|
|
|
|
echo view(getenv('theme.path').'main/header');
|
|
echo view(getenv('theme.path').'form/group/form',$data);
|
|
echo view(getenv('theme.path').'main/footer');
|
|
*/
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
public function store()
|
|
{
|
|
//Demo Mode
|
|
if(env('demo.mode')??false){
|
|
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
|
return redirect()->to('/usuarios/group');
|
|
}
|
|
|
|
$session = session();
|
|
helper('form');
|
|
|
|
$rules = [
|
|
'title' => 'required',
|
|
'dashboard' => 'required'
|
|
];
|
|
$rules_error = [
|
|
'title' => [
|
|
'required' => lang("App.group_rules_title_r")
|
|
],
|
|
'dashboard' => [
|
|
'required' => lang("App.group_rules_dashboard_r")
|
|
],
|
|
];
|
|
|
|
if ($this->validate($rules,$rules_error)){
|
|
if($listPost = $this->request->getPost()){
|
|
|
|
$getChecked = $this->request->getPost();
|
|
|
|
unset($getChecked['id_group']);
|
|
unset($getChecked['title']);
|
|
unset($getChecked['dashboard']);
|
|
|
|
$controller = null;
|
|
$rules_access = null;
|
|
|
|
foreach ($getChecked as $key=>$value){
|
|
$exp = explode('_',$key);
|
|
$controller[] = $exp[0];
|
|
}
|
|
|
|
if($controller != null){
|
|
foreach (array_unique($controller) as $item){
|
|
$rules_access[$item] = [];
|
|
|
|
foreach ($getChecked as $key=>$value){
|
|
$exp = explode('_',$key);
|
|
if($exp[0] == $item){
|
|
array_push($rules_access[$item],str_replace($exp[0].'_','',$key)) ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$listPost['rules'] = json_encode($rules_access??'{}');
|
|
|
|
if(empty($listPost['id_group'])){
|
|
$listPost['token'] = md5(uniqid(rand(), true));
|
|
}
|
|
|
|
$this->group_model->save($listPost);
|
|
|
|
if(empty($listPost['id_group'])){
|
|
$session->setFlashdata('sweet', ['success',lang("App.group_alert_add")]);
|
|
return redirect()->to('/usuarios/group');
|
|
}else{
|
|
if($session->get('group') == $this->request->getPost('token')){
|
|
$session->set('rules', $listPost['rules']);
|
|
}
|
|
$session->setFlashdata('sweet', ['success',lang("App.group_alert_edit")]);
|
|
return redirect()->to('/usuarios/group');
|
|
}
|
|
}
|
|
}else{
|
|
$session->setFlashdata('error','error');
|
|
$this->add();
|
|
}
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
//Demo Mode
|
|
if(env('demo.mode')??false){
|
|
session()->setFlashdata('sweet', ['warning',lang("App.general_demo_mode")]);
|
|
return redirect()->to('/usuarios/group');
|
|
}
|
|
|
|
$session = session();
|
|
if($this->user_model->where('group', $id)->countAllResults() == 0){
|
|
$this->group_model->where('token', $id)->delete();
|
|
$session->setFlashdata('sweet', ['success',lang("App.group_alert_delete")]);
|
|
}else{
|
|
$session->setFlashdata('sweet', ['error',lang("App.group_alert_error")]);
|
|
}
|
|
return redirect()->to('/usuarios/group');
|
|
}
|
|
*/
|
|
}
|