freeanswer.class.php 1.8 KB

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