Sfoglia il codice sorgente

Vista para ver encuesta respondidad por usuario

encuestas-excel
Sergio 2 anni fa
parent
commit
bdd7a0ba03
5 ha cambiato i file con 91 aggiunte e 2 eliminazioni
  1. +1
    -0
      app/Config/Routes.php
  2. +17
    -0
      app/Controllers/Admin.php
  3. +8
    -1
      app/Models/RespuestaModel.php
  4. +64
    -0
      app/Views/Admin/respuesta.php
  5. +1
    -1
      app/Views/Admin/respuestas.php

+ 1
- 0
app/Config/Routes.php Vedi 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->get('encuesta/eliminar/(:segment)', 'Admin::eliminarEncuesta/$1', ['as' => 'admin_encuesta_eliminar']);
$routes->get('respuestas/', 'Admin::respuestas', ['as' => 'admin_respuestas']);
$routes->get('respuesta/(:segment)/(:segment)', 'Admin::respuesta/$1/$2', ['as' => 'admin_respuesta']);

// PREGUNTAS
$routes->match(['get', 'post'], 'encuesta/(:segment)/pregunta/', 'Admin::nuevaPregunta/$1', ['as' => 'admin_pregunta_nueva']);


+ 17
- 0
app/Controllers/Admin.php Vedi File

@@ -9,6 +9,7 @@ use App\Models\PrestadorModel;
use App\Models\PrestadorSolicitudModel as ModelsPrestadorSolicitudModel;
use App\Models\SurveyUserModel;
use App\Models\UserModel;
use PHPUnit\Framework\MockObject\Stub\ReturnReference;

class Admin extends BaseController
{
@@ -313,6 +314,22 @@ class Admin extends BaseController
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

public function nuevaPregunta($id)


+ 8
- 1
app/Models/RespuestaModel.php Vedi File

@@ -4,7 +4,7 @@ namespace App\Models;

use CodeIgniter\Model;

class PreguntaModel extends Model
class RespuestaModel extends Model
{
protected $table = 'answers';
protected $primaryKey = 'id';
@@ -18,4 +18,11 @@ class PreguntaModel extends Model
'answer' => 'required',
'question_id' => 'required',
];

public function getRespuestas($survey_id, $user_id)
{
return $this
->where(['survey_id' => $survey_id, 'user_id' => $user_id])
->findAll();
}
}

+ 64
- 0
app/Views/Admin/respuesta.php Vedi 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() ?>

+ 1
- 1
app/Views/Admin/respuestas.php Vedi File

@@ -25,7 +25,7 @@
<td><?= $respuesta['user_id'] ?></td>
<td><?= $respuesta['created_at'] ?></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>
</tr>
<?php endforeach ?>


Loading…
Annulla
Salva