Mostrar encuesta respondida por usuario
Tento commit je obsažen v:
rodič
bdd7a0ba03
revize
54e18459e8
app
Controllers
Models
Views/Admin
@ -302,14 +302,10 @@ class Admin extends BaseController
|
||||
|
||||
public function respuestas()
|
||||
{
|
||||
$respuestas = model(SurveyUserModel::class)->find();
|
||||
$encuestas = model(EncuestaModel::class)->find();
|
||||
$prestadores = model(PrestadorModel::class)->getPrestadoresActivos();
|
||||
$respuestas = model(SurveyUserModel::class)->getEncuestasContestadas();
|
||||
|
||||
$data = [
|
||||
'respuestas' => $respuestas,
|
||||
'encuestas' => $encuestas,
|
||||
'prestadores' => $prestadores,
|
||||
];
|
||||
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 = [
|
||||
'tituloEncuesta' => model(EncuestaModel::class)->find($surveyId)['title'],
|
||||
'prestador' => $prestador,
|
||||
'respuestas' => $respuestas,
|
||||
];
|
||||
|
||||
|
||||
return view('Admin/respuesta', $data);
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,12 @@ class RespuestaModel extends Model
|
||||
|
||||
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
|
||||
->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();
|
||||
}
|
||||
}
|
||||
|
@ -24,4 +24,14 @@ class SurveyUserModel extends Model
|
||||
'user_id' => $userId,
|
||||
])->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/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-body">
|
||||
|
||||
<table id="table-solicitudes" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<th>Pregunta ID</th>
|
||||
<th>Pregunta</th>
|
||||
<th>Respuesta</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?php foreach ($respuestas as $respuesta) : ?>
|
||||
<tr>
|
||||
<td><?= $respuesta['question_id'] ?></td>
|
||||
<td><?= $respuesta['answer'] ?></td>
|
||||
<td><?= $respuesta[0]['question'] ?></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>
|
||||
<?php endforeach ?>
|
||||
|
||||
|
@ -12,8 +12,8 @@
|
||||
|
||||
<table id="table-solicitudes" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<th>Encuesta ID</th>
|
||||
<th>Prestador ID</th>
|
||||
<th>Encuesta</th>
|
||||
<th>Prestador</th>
|
||||
<th>Fecha</th>
|
||||
<th>Respuestas</th>
|
||||
</thead>
|
||||
@ -21,8 +21,8 @@
|
||||
|
||||
<?php foreach ($respuestas as $respuesta) : ?>
|
||||
<tr>
|
||||
<td><?= $respuesta['survey_id'] ?></td>
|
||||
<td><?= $respuesta['user_id'] ?></td>
|
||||
<td><?= $respuesta['title'] ?></td>
|
||||
<td><?= $respuesta['nombre'] . ' ' . $respuesta['apaterno'] . ' ' . $respuesta['amaterno'] ?></td>
|
||||
<td><?= $respuesta['created_at'] ?></td>
|
||||
<td>
|
||||
<a href="<?= route_to('admin_respuesta', $respuesta['survey_id'], $respuesta['user_id']) ?>" class="btn btn-info">Ver respuestas</a>
|
||||
|
Načítá se…
x
Odkázat v novém úkolu
Zablokovat Uživatele