media_question.class.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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()
  8. {
  9. parent::question();
  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. $new_params = array(
  28. 'c_id' => $this->course['real_id'],
  29. 'question' => $params['questionName'],
  30. 'description' => $params['questionDescription'],
  31. 'parent_id' => 0,
  32. 'type' => MEDIA_QUESTION
  33. );
  34. if (isset($this->id) && !empty($this->id)) {
  35. Database::update($table_question, $new_params, array('iid = ? and c_id = ?' => array($this->id, $this->course['real_id'])));
  36. } else {
  37. return Database::insert($table_question, $new_params);
  38. }
  39. }
  40. /**
  41. * @param \FormValidator $form
  42. */
  43. public function createAnswersForm ($form)
  44. {
  45. $form->addElement('button', 'submitQuestion', get_lang('Save'));
  46. }
  47. }