freeanswer.class.php 1.9 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. * @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. * abstract function which creates the form to create/edit the answers of the question
  42. * @param FormValidator $form
  43. */
  44. function processAnswersCreation($form)
  45. {
  46. $this->weighting = $form->getSubmitValue('weighting');
  47. $this->save();
  48. }
  49. function return_header($feedback_type = null, $counter = null, $score = null)
  50. {
  51. if (!empty($score['comments']) || $score['score'] > 0) {
  52. $score['revised'] = true;
  53. } else {
  54. $score['revised'] = false;
  55. }
  56. $header = parent::return_header($feedback_type, $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. }