Mostrar encuesta respondida por usuario
This commit is contained in:
parent
bdd7a0ba03
commit
54e18459e8
@ -302,14 +302,10 @@ class Admin extends BaseController
|
|||||||
|
|
||||||
public function respuestas()
|
public function respuestas()
|
||||||
{
|
{
|
||||||
$respuestas = model(SurveyUserModel::class)->find();
|
$respuestas = model(SurveyUserModel::class)->getEncuestasContestadas();
|
||||||
$encuestas = model(EncuestaModel::class)->find();
|
|
||||||
$prestadores = model(PrestadorModel::class)->getPrestadoresActivos();
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'respuestas' => $respuestas,
|
'respuestas' => $respuestas,
|
||||||
'encuestas' => $encuestas,
|
|
||||||
'prestadores' => $prestadores,
|
|
||||||
];
|
];
|
||||||
return view('Admin/respuestas', $data);
|
return view('Admin/respuestas', $data);
|
||||||
}
|
}
|
||||||
@ -323,10 +319,25 @@ class Admin extends BaseController
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Agrupar respuestas de opción múltipe
|
||||||
|
$respuestas = array_reduce($respuestas, function (array $accumulator, array $element) {
|
||||||
|
$accumulator[$element['question_id']][] = $element;
|
||||||
|
return $accumulator;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Datos de prestador
|
||||||
|
$prestadorId = model(UserModel::class)->find($userId)->idprestador;
|
||||||
|
$prestador = model(PrestadorModel::class)->find($prestadorId);
|
||||||
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
'tituloEncuesta' => model(EncuestaModel::class)->find($surveyId)['title'],
|
||||||
|
'prestador' => $prestador,
|
||||||
'respuestas' => $respuestas,
|
'respuestas' => $respuestas,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
return view('Admin/respuesta', $data);
|
return view('Admin/respuesta', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +21,12 @@ class RespuestaModel extends Model
|
|||||||
|
|
||||||
public function getRespuestas($survey_id, $user_id)
|
public function getRespuestas($survey_id, $user_id)
|
||||||
{
|
{
|
||||||
|
$db = db_connect();
|
||||||
|
$where = 'answers.survey_id = ' . $db->escape($survey_id) . ' AND answers.user_id = ' . $db->escape($user_id);
|
||||||
return $this
|
return $this
|
||||||
->where(['survey_id' => $survey_id, 'user_id' => $user_id])
|
->select('answers.id, answers.survey_id, answers.user_id, answers.answer,answers.question_id, questions.question, questions.type')
|
||||||
|
->join('questions', 'answers.question_id = questions.id')
|
||||||
|
->where($where)
|
||||||
->findAll();
|
->findAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,4 +24,14 @@ class SurveyUserModel extends Model
|
|||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
])->countAllResults();
|
])->countAllResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getEncuestasContestadas()
|
||||||
|
{
|
||||||
|
return $this
|
||||||
|
->join('survey_set', 'survey_user.survey_id = survey_set.id')
|
||||||
|
->join('users', 'survey_user.user_id = users.id')
|
||||||
|
->join('prestador', 'users.idprestador = prestador.idprestador')
|
||||||
|
->findAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,21 +6,34 @@
|
|||||||
<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/jquery.dataTables.min.js"></script>
|
||||||
<script src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap5.min.js"></script>
|
<script src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap5.min.js"></script>
|
||||||
|
|
||||||
|
<h1><?= $tituloEncuesta ?></h1>
|
||||||
|
<p>Respuestas de: <span class="font-weight-bolder"><?= $prestador['nombre'] . ' ' . $prestador['apaterno'] . ' ' . $prestador['amaterno'] ?></span></p>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
||||||
<table id="table-solicitudes" class="table table-bordered table-striped">
|
<table id="table-solicitudes" class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Pregunta ID</th>
|
<th>Pregunta</th>
|
||||||
<th>Respuesta</th>
|
<th>Respuesta</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<?php foreach ($respuestas as $respuesta) : ?>
|
<?php foreach ($respuestas as $respuesta) : ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= $respuesta['question_id'] ?></td>
|
<td><?= $respuesta[0]['question'] ?></td>
|
||||||
<td><?= $respuesta['answer'] ?></td>
|
|
||||||
|
<!-- Respuestas de opción múltiple -->
|
||||||
|
<?php if ($respuesta[0]['type'] === '3') : ?>
|
||||||
|
<td>
|
||||||
|
<?php foreach ($respuesta as $opcion) : ?>
|
||||||
|
<?= $opcion['answer'] ?>
|
||||||
|
<br>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</td>
|
||||||
|
<?php else : ?>
|
||||||
|
<td><?= $respuesta[0]['answer'] ?></td>
|
||||||
|
<?php endif ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach ?>
|
<?php endforeach ?>
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
<table id="table-solicitudes" class="table table-bordered table-striped">
|
<table id="table-solicitudes" class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<th>Encuesta ID</th>
|
<th>Encuesta</th>
|
||||||
<th>Prestador ID</th>
|
<th>Prestador</th>
|
||||||
<th>Fecha</th>
|
<th>Fecha</th>
|
||||||
<th>Respuestas</th>
|
<th>Respuestas</th>
|
||||||
</thead>
|
</thead>
|
||||||
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
<?php foreach ($respuestas as $respuesta) : ?>
|
<?php foreach ($respuestas as $respuesta) : ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= $respuesta['survey_id'] ?></td>
|
<td><?= $respuesta['title'] ?></td>
|
||||||
<td><?= $respuesta['user_id'] ?></td>
|
<td><?= $respuesta['nombre'] . ' ' . $respuesta['apaterno'] . ' ' . $respuesta['amaterno'] ?></td>
|
||||||
<td><?= $respuesta['created_at'] ?></td>
|
<td><?= $respuesta['created_at'] ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="<?= route_to('admin_respuesta', $respuesta['survey_id'], $respuesta['user_id']) ?>" 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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user