mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadido cliente id a users
This commit is contained in:
@ -55,6 +55,8 @@ class Users extends \App\Controllers\GoBaseController {
|
|||||||
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]);
|
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Users.user')]);
|
||||||
$this->viewData['user_model'] = $this->user_model;
|
$this->viewData['user_model'] = $this->user_model;
|
||||||
|
|
||||||
|
$this->viewData['userList2'] = $this->user_model->getUsersList();
|
||||||
|
|
||||||
parent::index();
|
parent::index();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -136,6 +138,7 @@ class Users extends \App\Controllers\GoBaseController {
|
|||||||
endif; // ($requestMethod === 'post')
|
endif; // ($requestMethod === 'post')
|
||||||
|
|
||||||
$this->viewData['user'] = isset($sanitizedData) ? new UserEntity($sanitizedData) : new UserEntity();
|
$this->viewData['user'] = isset($sanitizedData) ? new UserEntity($sanitizedData) : new UserEntity();
|
||||||
|
$this->viewData['clienteList'] = $this->getClienteListItems();
|
||||||
$this->viewData['formAction'] = route_to('createUser');
|
$this->viewData['formAction'] = route_to('createUser');
|
||||||
$this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll();
|
$this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll();
|
||||||
$this->viewData['boxTitle'] = lang('Basic.global.addNew') .lang('Users.user').' '.lang('Basic.global.addNewSuffix');
|
$this->viewData['boxTitle'] = lang('Basic.global.addNew') .lang('Users.user').' '.lang('Basic.global.addNewSuffix');
|
||||||
@ -176,7 +179,22 @@ class Users extends \App\Controllers\GoBaseController {
|
|||||||
|
|
||||||
if ($this->canValidate()) :
|
if ($this->canValidate()) :
|
||||||
try {
|
try {
|
||||||
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
if (in_array('cliente-editor', $currentGroups) || in_array('cliente-administrador', $currentGroups)) {
|
||||||
|
if(!array_key_exists('cliente_id', $sanitizedData) || is_null($sanitizedData['cliente_id'])) {
|
||||||
|
$this->viewData['errorMessage'] = lang('Users.errors.cliente_sin_clienteID');
|
||||||
|
$this->session->setFlashdata('formErrors', $this->model->errors());
|
||||||
|
|
||||||
|
$successfulResult = false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$successfulResult = $this->model->skipValidation(true)->update($id, $sanitizedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$noException = false;
|
$noException = false;
|
||||||
$this->dealWithException($e);
|
$this->dealWithException($e);
|
||||||
@ -221,6 +239,7 @@ class Users extends \App\Controllers\GoBaseController {
|
|||||||
endif; // ($requestMethod === 'post')
|
endif; // ($requestMethod === 'post')
|
||||||
|
|
||||||
$this->viewData['user'] = $user;
|
$this->viewData['user'] = $user;
|
||||||
|
$this->viewData['clienteList'] = $this->getClienteListItems($user->cliente_id);
|
||||||
$this->viewData['formAction'] = route_to('updateUser', $id);
|
$this->viewData['formAction'] = route_to('updateUser', $id);
|
||||||
$this->viewData['selectedGroups'] = $this->group_model->getUsersRoles($requestedId);
|
$this->viewData['selectedGroups'] = $this->group_model->getUsersRoles($requestedId);
|
||||||
$this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll();
|
$this->viewData['groups'] = $this->group_model->select('keyword, title')->findAll();
|
||||||
@ -329,5 +348,19 @@ class Users extends \App\Controllers\GoBaseController {
|
|||||||
|
|
||||||
return $registers;
|
return $registers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getClienteListItems($selId = null)
|
||||||
|
{
|
||||||
|
$data = ['' => ""];
|
||||||
|
if (!empty($selId)) :
|
||||||
|
$clienteModel = model('App\Models\Clientes\ClienteModel');
|
||||||
|
|
||||||
|
$selOption = $clienteModel->where('id', $selId)->findColumn('nombre');
|
||||||
|
if (!empty($selOption)) :
|
||||||
|
$data[$selId] = $selOption[0];
|
||||||
|
endif;
|
||||||
|
endif;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,36 +6,23 @@ use CodeIgniter\Entity;
|
|||||||
class UserEntity extends \CodeIgniter\Entity\Entity
|
class UserEntity extends \CodeIgniter\Entity\Entity
|
||||||
{
|
{
|
||||||
protected $attributes = [
|
protected $attributes = [
|
||||||
"id_user" => null,
|
"id" => null,
|
||||||
"first_name" => null,
|
"first_name" => null,
|
||||||
"last_name" => null,
|
"last_name" => null,
|
||||||
"date_birth" => null,
|
"cliente_id" => null,
|
||||||
"address" => "",
|
"status" => null,
|
||||||
"city" => "",
|
"status_message" => null,
|
||||||
"state" => "",
|
'active' => null,
|
||||||
"country" => "",
|
"last_active" => null,
|
||||||
"zip_code" => "",
|
|
||||||
"mobile" => null,
|
|
||||||
"email" => null,
|
|
||||||
"password" => null,
|
|
||||||
"last_ip" => null,
|
|
||||||
"last_access" => null,
|
|
||||||
"picture" => "/assets/img/default-user.png",
|
|
||||||
"language" => null,
|
|
||||||
"tfa" => false,
|
|
||||||
"tfa_secret" => "",
|
|
||||||
"tfa_code" => "",
|
|
||||||
"blocked" => null,
|
|
||||||
"email_confirmed" => 0,
|
|
||||||
"token" => null,
|
|
||||||
"status" => false,
|
|
||||||
"created_at" => null,
|
"created_at" => null,
|
||||||
"updated_at" => null,
|
"updated_at" => null,
|
||||||
|
"deleted_at" => null,
|
||||||
|
|
||||||
];
|
];
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
"tfa" => "boolean",
|
"id" => "int",
|
||||||
"email_confirmed" => "int",
|
"cliente_id" => "int",
|
||||||
"status" => "boolean",
|
"active" => "boolean",
|
||||||
];
|
];
|
||||||
/**
|
/**
|
||||||
* Returns a full name: "first last"
|
* Returns a full name: "first last"
|
||||||
|
|||||||
@ -38,6 +38,23 @@ return [
|
|||||||
'userList' => 'User List',
|
'userList' => 'User List',
|
||||||
'users' => 'Users',
|
'users' => 'Users',
|
||||||
'zipCode' => 'Zip Code',
|
'zipCode' => 'Zip Code',
|
||||||
|
|
||||||
|
'admin' => 'Administrator',
|
||||||
|
'cliente-admin' => 'Client administrator',
|
||||||
|
'cliente-editor' => 'Client editor',
|
||||||
|
'comercial' => 'Commercial',
|
||||||
|
'produccion' => 'Production',
|
||||||
|
'maquina' => 'Machine',
|
||||||
|
'maquetador' => 'Layout designer',
|
||||||
|
'director' => 'Director',
|
||||||
|
'contabilidad' => 'Accounting',
|
||||||
|
'editor' => 'Editor',
|
||||||
|
'beta' => 'Beta',
|
||||||
|
|
||||||
|
'errors' => [
|
||||||
|
'cliente_sin_clienteID' => 'The user must have a client assigned when using any client role.',
|
||||||
|
],
|
||||||
|
|
||||||
'validation' => [
|
'validation' => [
|
||||||
'address' => [
|
'address' => [
|
||||||
'max_length' => 'The {field} field cannot exceed {param} characters in length.',
|
'max_length' => 'The {field} field cannot exceed {param} characters in length.',
|
||||||
|
|||||||
@ -38,6 +38,23 @@ return [
|
|||||||
'userList' => 'Lista de usuarios',
|
'userList' => 'Lista de usuarios',
|
||||||
'users' => 'Usuarios',
|
'users' => 'Usuarios',
|
||||||
'zipCode' => 'Código postal',
|
'zipCode' => 'Código postal',
|
||||||
|
|
||||||
|
'admin' => 'Administrador',
|
||||||
|
'cliente-admin' => 'Cliente administrador',
|
||||||
|
'cliente-editor' => 'Cliente editor',
|
||||||
|
'comercial' => 'Comercial',
|
||||||
|
'produccion' => 'Producción',
|
||||||
|
'maquina' => 'Máquina',
|
||||||
|
'maquetador' => 'Maquetador',
|
||||||
|
'director' => 'Director',
|
||||||
|
'contabilidad' => 'Contabilidad',
|
||||||
|
'editor' => 'Editor',
|
||||||
|
'beta' => 'Beta',
|
||||||
|
|
||||||
|
'errors' => [
|
||||||
|
'cliente_sin_clienteID' => 'El usuario debe de tener un cliente asignado cuando se usa algún rol de cliente.',
|
||||||
|
],
|
||||||
|
|
||||||
'validation' => [
|
'validation' => [
|
||||||
'address' => [
|
'address' => [
|
||||||
'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.',
|
'max_length' => 'El campo {field} no puede exceder {param} caracteres en longitud.',
|
||||||
|
|||||||
@ -16,9 +16,17 @@ class UserModel extends ShieldUserModel
|
|||||||
...$this->allowedFields,
|
...$this->allowedFields,
|
||||||
'first_name', // Añadido
|
'first_name', // Añadido
|
||||||
'last_name', // Añadido
|
'last_name', // Añadido
|
||||||
|
'cliente_id', // Añadido
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected $useSoftDeletes = true;
|
||||||
|
protected $useTimestamps = true;
|
||||||
|
protected $createdField = 'created_at';
|
||||||
|
protected $updatedField = 'updated_at';
|
||||||
|
protected $deletedField = 'deleted_at';
|
||||||
|
|
||||||
|
|
||||||
protected $validationRules = [
|
protected $validationRules = [
|
||||||
"username" => [
|
"username" => [
|
||||||
"label" => "correo duplicado",
|
"label" => "correo duplicado",
|
||||||
@ -42,4 +50,18 @@ class UserModel extends ShieldUserModel
|
|||||||
return $builder->get()->getResult();
|
return $builder->get()->getResult();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUsersList(){
|
||||||
|
$builder = $this->db
|
||||||
|
->table("users" . " t1")
|
||||||
|
->select(
|
||||||
|
"t1.id AS id, t1.first_name AS first_name, t1.last_name AS last_name, t1.last_active AS last_active, t2.group AS group"
|
||||||
|
);
|
||||||
|
|
||||||
|
$builder->where('t1.deleted_at', null);
|
||||||
|
$builder->join("auth_groups_users t2", "t1.id = t2.user_id", "left");
|
||||||
|
|
||||||
|
return $builder->get()->getResult();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,5 +73,22 @@
|
|||||||
</div><!--//.mb-3 -->
|
</div><!--//.mb-3 -->
|
||||||
|
|
||||||
</div><!--//.col -->
|
</div><!--//.col -->
|
||||||
|
<div class="col-md-12 col-lg-6 px-4">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="cliente_id" class="form-label">
|
||||||
|
<?= lang('Presupuestos.clienteId') ?>
|
||||||
|
</label>
|
||||||
|
<select id="cliente_id" name="cliente_id" class="form-control select2bs2" style="width: 100%;">
|
||||||
|
|
||||||
|
<?php if (isset($clienteList) && is_array($clienteList) && !empty($clienteList)) :
|
||||||
|
foreach ($clienteList as $k => $v) : ?>
|
||||||
|
<option value="<?= $k ?>" <?= $k == $user->cliente_id ? ' selected' : '' ?>>
|
||||||
|
<?= $v ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach;
|
||||||
|
endif; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div><!--//.col -->
|
||||||
|
|
||||||
</div><!-- //.row -->
|
</div><!-- //.row -->
|
||||||
@ -1,4 +1,5 @@
|
|||||||
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
|
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
|
||||||
|
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
|
||||||
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
|
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
|
||||||
<?= $this->section("content") ?>
|
<?= $this->section("content") ?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -28,3 +29,33 @@
|
|||||||
</div><!--//.col -->
|
</div><!--//.col -->
|
||||||
</div><!--//.row -->
|
</div><!--//.row -->
|
||||||
<?= $this->endSection() ?>
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
|
<?= $this->section("additionalInlineJs") ?>
|
||||||
|
|
||||||
|
$('#cliente_id').select2({
|
||||||
|
allowClear: false,
|
||||||
|
ajax: {
|
||||||
|
url: '<?= route_to("menuItemsOfClientes") ?>',
|
||||||
|
type: 'post',
|
||||||
|
dataType: 'json',
|
||||||
|
|
||||||
|
data: function(params) {
|
||||||
|
return {
|
||||||
|
id: 'id',
|
||||||
|
text: 'nombre',
|
||||||
|
searchTerm: params.term,
|
||||||
|
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v
|
||||||
|
};
|
||||||
|
},
|
||||||
|
delay: 60,
|
||||||
|
processResults: function(response) {
|
||||||
|
yeniden(response.<?= csrf_token() ?>);
|
||||||
|
return {
|
||||||
|
results: response.menu
|
||||||
|
};
|
||||||
|
},
|
||||||
|
cache: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
<?= $this->endSection() ?>
|
||||||
|
|||||||
@ -17,9 +17,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th><?= lang('Users.firstName') ?></th>
|
<th><?= lang('Users.firstName') ?></th>
|
||||||
<th><?= lang('Users.lastName') ?></th>
|
<th><?= lang('Users.lastName') ?></th>
|
||||||
<th><?= lang('Users.lastAccess') ?></th>
|
|
||||||
<?php /*
|
|
||||||
<th><?= lang('Users.group') ?></th>
|
<th><?= lang('Users.group') ?></th>
|
||||||
|
<th><?= lang('Users.lastAccess') ?></th>
|
||||||
|
<?php /*
|
||||||
<th><?= lang('Users.mobile') ?></th>
|
<th><?= lang('Users.mobile') ?></th>
|
||||||
<th><?= lang('Users.email') ?></th>
|
<th><?= lang('Users.email') ?></th>
|
||||||
<th><?= lang('Users.address') ?></th>
|
<th><?= lang('Users.address') ?></th>
|
||||||
@ -38,7 +38,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($userList as $item ) : ?>
|
<?php foreach ($userList2 as $item ) : ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<?= empty($item->first_name) || strlen($item->first_name) < 51 ? esc($item->first_name) : character_limiter(esc($item->first_name), 50) ?>
|
<?= empty($item->first_name) || strlen($item->first_name) < 51 ? esc($item->first_name) : character_limiter(esc($item->first_name), 50) ?>
|
||||||
@ -46,6 +46,9 @@
|
|||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
<?= empty($item->last_name) || strlen($item->last_name) < 51 ? esc($item->last_name) : character_limiter(esc($item->last_name), 50) ?>
|
<?= empty($item->last_name) || strlen($item->last_name) < 51 ? esc($item->last_name) : character_limiter(esc($item->last_name), 50) ?>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="align-middle">
|
||||||
|
<?= empty($item->group) ? "" : character_limiter(esc(lang('Users.' . $item->group)), 50) ?>
|
||||||
|
</td>
|
||||||
|
|
||||||
<td class="align-middle text-nowrap">
|
<td class="align-middle text-nowrap">
|
||||||
<?= empty($item->last_active) ? '' : date('d/m/Y H:m:s', strtotime($item->last_active)) ?>
|
<?= empty($item->last_active) ? '' : date('d/m/Y H:m:s', strtotime($item->last_active)) ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user