25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.7KB

  1. <?php
  2. namespace App\Models;
  3. use CodeIgniter\Model;
  4. class RespuestaModel extends Model
  5. {
  6. protected $table = 'answers';
  7. protected $primaryKey = 'id';
  8. protected $useTimestamps = true;
  9. protected $allowedFields = ['survey_id', 'user_id', 'answer', 'question_id'];
  10. protected $validationRules = [
  11. 'survey_id' => 'required',
  12. 'user_id' => 'required',
  13. 'answer' => 'required',
  14. 'question_id' => 'required',
  15. ];
  16. public function getRespuestas($survey_id, $user_id)
  17. {
  18. $db = db_connect();
  19. $where = 'answers.survey_id = ' . $db->escape($survey_id) . ' AND answers.user_id = ' . $db->escape($user_id);
  20. return $this
  21. ->select('answers.id, answers.survey_id, answers.user_id, answers.answer,answers.question_id, questions.question, questions.type')
  22. ->join('questions', 'answers.question_id = questions.id')
  23. ->where($where)
  24. ->findAll();
  25. }
  26. public function getRespuestasAll($survey_id)
  27. {
  28. $db = db_connect();
  29. $where = 'answers.survey_id = ' . $db->escape($survey_id);
  30. return $this
  31. ->select('answers.id, answers.survey_id, answers.user_id, answers.answer,answers.question_id, answers.created_at')
  32. ->select('questions.question, questions.type')
  33. ->select('prestador.idprestador, prestador.nombre, prestador.apaterno, prestador.amaterno')
  34. ->join('questions', 'answers.question_id = questions.id')
  35. ->join('users', 'answers.user_id = users.id')
  36. ->join('prestador', 'users.idprestador = prestador.idprestador')
  37. ->where($where)
  38. ->findAll();
  39. }
  40. }