Vista para ver encuesta respondidad por usuario

This commit is contained in:
Sergio 2022-08-31 10:50:42 -05:00
parent 6f3d980784
commit bdd7a0ba03
5 changed files with 91 additions and 2 deletions

View File

@ -75,6 +75,7 @@ $routes->group('admin', ['filter' => 'admin_filter'], static function ($routes)
$routes->match(['get', 'post'], 'encuesta/editar/(:segment)', 'Admin::editarEncuesta/$1', ['as' => 'admin_encuesta_editar']); $routes->match(['get', 'post'], 'encuesta/editar/(:segment)', 'Admin::editarEncuesta/$1', ['as' => 'admin_encuesta_editar']);
$routes->get('encuesta/eliminar/(:segment)', 'Admin::eliminarEncuesta/$1', ['as' => 'admin_encuesta_eliminar']); $routes->get('encuesta/eliminar/(:segment)', 'Admin::eliminarEncuesta/$1', ['as' => 'admin_encuesta_eliminar']);
$routes->get('respuestas/', 'Admin::respuestas', ['as' => 'admin_respuestas']); $routes->get('respuestas/', 'Admin::respuestas', ['as' => 'admin_respuestas']);
$routes->get('respuesta/(:segment)/(:segment)', 'Admin::respuesta/$1/$2', ['as' => 'admin_respuesta']);
// PREGUNTAS // PREGUNTAS
$routes->match(['get', 'post'], 'encuesta/(:segment)/pregunta/', 'Admin::nuevaPregunta/$1', ['as' => 'admin_pregunta_nueva']); $routes->match(['get', 'post'], 'encuesta/(:segment)/pregunta/', 'Admin::nuevaPregunta/$1', ['as' => 'admin_pregunta_nueva']);

View File

@ -9,6 +9,7 @@ use App\Models\PrestadorModel;
use App\Models\PrestadorSolicitudModel as ModelsPrestadorSolicitudModel; use App\Models\PrestadorSolicitudModel as ModelsPrestadorSolicitudModel;
use App\Models\SurveyUserModel; use App\Models\SurveyUserModel;
use App\Models\UserModel; use App\Models\UserModel;
use PHPUnit\Framework\MockObject\Stub\ReturnReference;
class Admin extends BaseController class Admin extends BaseController
{ {
@ -313,6 +314,22 @@ class Admin extends BaseController
return view('Admin/respuestas', $data); return view('Admin/respuestas', $data);
} }
public function respuesta($surveyId, $userId)
{
if (!$respuestas = model(RespuestaModel::class)->getRespuestas($surveyId, $userId)) {
return redirect()->route('admin_respuestas')->with('msg', array(
'type' => 'danger',
'body' => 'No se encontraron respuestas de este usuario.',
));
}
$data = [
'respuestas' => $respuestas,
];
return view('Admin/respuesta', $data);
}
// PREGUNTAS // PREGUNTAS
public function nuevaPregunta($id) public function nuevaPregunta($id)

View File

@ -4,7 +4,7 @@ namespace App\Models;
use CodeIgniter\Model; use CodeIgniter\Model;
class PreguntaModel extends Model class RespuestaModel extends Model
{ {
protected $table = 'answers'; protected $table = 'answers';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
@ -18,4 +18,11 @@ class PreguntaModel extends Model
'answer' => 'required', 'answer' => 'required',
'question_id' => 'required', 'question_id' => 'required',
]; ];
public function getRespuestas($survey_id, $user_id)
{
return $this
->where(['survey_id' => $survey_id, 'user_id' => $user_id])
->findAll();
}
} }

View File

@ -0,0 +1,64 @@
<?= $this->extend('templates/baseAdmin') ?>
<?= $this->section('content') ?>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap5.min.js"></script>
<div class="card">
<div class="card-body">
<table id="table-solicitudes" class="table table-bordered table-striped">
<thead>
<th>Pregunta ID</th>
<th>Respuesta</th>
</thead>
<tbody>
<?php foreach ($respuestas as $respuesta) : ?>
<tr>
<td><?= $respuesta['question_id'] ?></td>
<td><?= $respuesta['answer'] ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
let table = new DataTable('#table-solicitudes', {
'searching': true,
'ordering': true,
'language': {
"decimal": "",
"emptyTable": "No hay información",
"info": "Mostrando _START_ a _END_ de _TOTAL_ registros",
"infoEmpty": "Mostrando 0 to 0 of 0 registros",
"infoFiltered": "(Filtrado de _MAX_ total registros)",
"infoPostFix": "",
"thousands": ",",
"lengthMenu": "Mostrar _MENU_ registros",
"loadingRecords": "Cargando...",
"processing": "Procesando...",
"search": "Buscar:",
"zeroRecords": "No se encontraron resultados",
"paginate": {
"first": "Primero",
"last": "Ultimo",
"next": "Siguiente",
"previous": "Anterior"
}
},
'order': [],
});
});
</script>
<?= $this->endSection() ?>

View File

@ -25,7 +25,7 @@
<td><?= $respuesta['user_id'] ?></td> <td><?= $respuesta['user_id'] ?></td>
<td><?= $respuesta['created_at'] ?></td> <td><?= $respuesta['created_at'] ?></td>
<td> <td>
<a href="#" class="btn btn-info">Ver respuestas</a> <a href="<?= route_to('admin_respuesta', $respuesta['survey_id'], $respuesta['user_id']) ?>" class="btn btn-info">Ver respuestas</a>
</td> </td>
</tr> </tr>
<?php endforeach ?> <?php endforeach ?>