media_question.class.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. class MediaQuestion extends Question
  4. {
  5. static $typePicture = 'media-question.png';
  6. static $explanationLangVar = 'MediaQuestion';
  7. public function __construct($course_code = null)
  8. {
  9. parent::question($course_code);
  10. $this->type = MEDIA_QUESTION;
  11. }
  12. /**
  13. * @param \FormValidator $form
  14. */
  15. public function processAnswersCreation($form)
  16. {
  17. $params = $form->getSubmitValues();
  18. $this->saveMedia($params);
  19. }
  20. /**
  21. * @param array $params
  22. * @return int
  23. */
  24. public function saveMedia($params)
  25. {
  26. $table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
  27. $course_id = '';
  28. $questionName = '';
  29. if (!empty($this->course['real_id'])) {
  30. $course_id = $this->course['real_id'];
  31. } else {
  32. throw new Exception('Missing $this->course info in MediaQuestion::saveMedia()');
  33. }
  34. if (isset($params['questionName'])) {
  35. $questionName = $params['questionName'];
  36. } else {
  37. throw new Exception('Missing questionName in $params in MediaQuestion::saveMedia()');
  38. }
  39. $questionDescription = isset($params['questionDescription']) ? $params['questionDescription'] : '';
  40. $new_params = array(
  41. 'c_id' => $course_id,
  42. 'question' => $questionName,
  43. 'description' => $questionDescription,
  44. 'parent_id' => 0,
  45. 'type' => MEDIA_QUESTION
  46. );
  47. if (isset($this->id) && !empty($this->id)) {
  48. Database::update($table_question, $new_params, array('iid = ? and c_id = ?' => array($this->id, $course_id)));
  49. } else {
  50. return Database::insert($table_question, $new_params);
  51. }
  52. }
  53. /**
  54. * @param \FormValidator $form
  55. */
  56. public function createAnswersForm ($form)
  57. {
  58. $form->addElement('button', 'submitQuestion', get_lang('Save'));
  59. }
  60. }