diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a1cc83a..a8dddce 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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']); diff --git a/app/Controllers/Admin.php b/app/Controllers/Admin.php index b63fb8e..8aed0cc 100644 --- a/app/Controllers/Admin.php +++ b/app/Controllers/Admin.php @@ -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) diff --git a/app/Models/RespuestaModel.php b/app/Models/RespuestaModel.php index 4cd140d..020a20d 100644 --- a/app/Models/RespuestaModel.php +++ b/app/Models/RespuestaModel.php @@ -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(); + } } diff --git a/app/Views/Admin/respuesta.php b/app/Views/Admin/respuesta.php new file mode 100644 index 0000000..5009e0a --- /dev/null +++ b/app/Views/Admin/respuesta.php @@ -0,0 +1,64 @@ +extend('templates/baseAdmin') ?> + +section('content') ?> + + + + + + +
+
+ + + + + + + + + + + + + + + + + +
Pregunta IDRespuesta
+ +
+
+ + + +endSection() ?> \ No newline at end of file diff --git a/app/Views/Admin/respuestas.php b/app/Views/Admin/respuestas.php index 4cccb35..f167cdb 100644 --- a/app/Views/Admin/respuestas.php +++ b/app/Views/Admin/respuestas.php @@ -25,7 +25,7 @@ - Ver respuestas + Ver respuestas