freeanswer.class.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * File containing the FreeAnswer class.
  5. * This class allows to instantiate an object of type FREE_ANSWER,
  6. * extending the class question.
  7. *
  8. * @package chamilo.exercise
  9. *
  10. * @author Eric Marguin
  11. */
  12. class FreeAnswer extends Question
  13. {
  14. public $typePicture = 'open_answer.png';
  15. public $explanationLangVar = 'FreeAnswer';
  16. /**
  17. * Constructor.
  18. */
  19. public function __construct()
  20. {
  21. parent::__construct();
  22. $this->type = FREE_ANSWER;
  23. $this->isContent = $this->getIsContent();
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function createAnswersForm($form)
  29. {
  30. $form->addElement('text', 'weighting', get_lang('Weighting'));
  31. global $text;
  32. // setting the save button here and not in the question class.php
  33. $form->addButtonSave($text, 'submitQuestion');
  34. if (!empty($this->id)) {
  35. $form->setDefaults(['weighting' => float_format($this->weighting, 1)]);
  36. } else {
  37. if ($this->isContent == 1) {
  38. $form->setDefaults(['weighting' => '10']);
  39. }
  40. }
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function processAnswersCreation($form, $exercise)
  46. {
  47. $this->weighting = $form->getSubmitValue('weighting');
  48. $this->save($exercise);
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function return_header(Exercise $exercise, $counter = null, $score = [])
  54. {
  55. $score['revised'] = $this->isQuestionWaitingReview($score);
  56. $header = parent::return_header($exercise, $counter, $score);
  57. $header .= '<table class="'.$this->question_table_class.'" >
  58. <tr>
  59. <th>'.get_lang('Answer').'</th>
  60. </tr>';
  61. return $header;
  62. }
  63. }