mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en user y groups con el nuevo formato
This commit is contained in:
@ -1,45 +1,40 @@
|
||||
<?php
|
||||
<?php namespace App\Controllers\Usuarios;
|
||||
|
||||
namespace App\Controllers\Usuarios;
|
||||
use App\Controllers\BaseController;
|
||||
use App\Entities\Usuarios\UserGroupEntity;
|
||||
|
||||
use App\Models\UserModel;
|
||||
use App\Models\UserGroupModel;
|
||||
use App\Controllers\GoBaseResourceController;
|
||||
use App\Models\Usuarios\UserGroupModel;
|
||||
|
||||
class Group extends BaseController
|
||||
class Group extends \App\Controllers\GoBaseController
|
||||
{
|
||||
private $user_model;
|
||||
private $group_model;
|
||||
use \CodeIgniter\API\ResponseTrait;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->user_model = new UserModel();
|
||||
$this->group_model = new UserGroupModel();
|
||||
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()
|
||||
{
|
||||
$data['title'] = [
|
||||
'module' => lang("App.group_title"),
|
||||
'page' => lang("App.group_subtitle"),
|
||||
'icon' => 'fas fa-user-lock'
|
||||
];
|
||||
|
||||
$data['breadcrumb'] = [
|
||||
['title' => lang("App.menu_dashboard"), 'route' => "/home", 'active' => false],
|
||||
['title' => lang("App.group_title"), 'route' => "", 'active' => true]
|
||||
];
|
||||
|
||||
$data['btn_add'] = [
|
||||
'title' => lang("App.group_btn_add"),
|
||||
'route' => '/usuarios/group/add',
|
||||
'class' => 'btn btn-lg btn-primary float-md-right',
|
||||
'icon' => 'fas fa-plus'
|
||||
];
|
||||
|
||||
echo view(getenv('theme.path').'main/header');
|
||||
echo view(getenv('theme.path').'form/group/index',$data);
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
$this->viewData['usingClientSideDataTable'] = true;
|
||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Groups.group')]);
|
||||
|
||||
parent::index();
|
||||
}
|
||||
|
||||
public function add()
|
||||
@ -77,8 +72,81 @@ class Group extends BaseController
|
||||
echo view(getenv('theme.path').'main/footer');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
//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'] = [
|
||||
@ -115,8 +183,13 @@ class Group extends BaseController
|
||||
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
|
||||
@ -214,4 +287,5 @@ class Group extends BaseController
|
||||
}
|
||||
return redirect()->to('/usuarios/group');
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user