|
- <?php
-
- namespace App\Models;
-
- use CodeIgniter\Model;
-
- class RespuestaModel extends Model
- {
- protected $table = 'answers';
- protected $primaryKey = 'id';
- protected $useTimestamps = true;
-
- protected $allowedFields = ['survey_id', 'user_id', 'answer', 'question_id'];
-
- protected $validationRules = [
- 'survey_id' => 'required',
- 'user_id' => 'required',
- 'answer' => 'required',
- 'question_id' => 'required',
- ];
-
- 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
- ->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();
- }
-
- public function getRespuestasAll($survey_id)
- {
- $db = db_connect();
- $where = 'answers.survey_id = ' . $db->escape($survey_id);
- return $this
- ->select('answers.id, answers.survey_id, answers.user_id, answers.answer,answers.question_id, answers.created_at')
- ->select('questions.question, questions.type')
- ->select('prestador.idprestador, prestador.nombre, prestador.apaterno, prestador.amaterno')
- ->join('questions', 'answers.question_id = questions.id')
- ->join('users', 'answers.user_id = users.id')
- ->join('prestador', 'users.idprestador = prestador.idprestador')
- ->where($where)
- ->findAll();
- }
- }
|