freeanswer.class.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. static $typePicture = 'open_answer.png';
  13. 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. * function which redifines Question::createAnswersForm
  25. * @param formvalidator $form
  26. */
  27. function createAnswersForm($form)
  28. {
  29. $form->addElement('text', 'weighting', get_lang('Weighting'));
  30. global $text, $class;
  31. // setting the save button here and not in the question class.php
  32. $form->addButtonSave($text, 'submitQuestion');
  33. if (!empty($this->id)) {
  34. $form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
  35. } else {
  36. if ($this->isContent == 1) {
  37. $form->setDefaults(array('weighting' => '10'));
  38. }
  39. }
  40. }
  41. /**
  42. * abstract function which creates the form to create/edit the answers of the question
  43. * @param FormValidator $form
  44. */
  45. function processAnswersCreation($form)
  46. {
  47. $this->weighting = $form->getSubmitValue('weighting');
  48. $this->save();
  49. }
  50. function return_header($feedback_type = null, $counter = null, $score = null)
  51. {
  52. if (!empty($score['comments']) || $score['score'] > 0) {
  53. $score['revised'] = true;
  54. } else {
  55. $score['revised'] = false;
  56. }
  57. $header = parent::return_header($feedback_type, $counter, $score);
  58. $header .= '<table class="' . $this->question_table_class . '" >
  59. <tr>
  60. <th>' . get_lang("Answer") . '</th>
  61. </tr>';
  62. return $header;
  63. }
  64. }