freeanswer.class.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  10. */
  11. /**
  12. * Code
  13. */
  14. if (!class_exists('FreeAnswer')):
  15. /**
  16. * @package chamilo.exercise
  17. */
  18. class FreeAnswer extends Question {
  19. static $typePicture = 'open_answer.gif';
  20. static $explanationLangVar = 'FreeAnswer';
  21. /**
  22. * Constructor
  23. */
  24. function FreeAnswer() {
  25. parent::question();
  26. $this->type = FREE_ANSWER;
  27. $this->isContent = $this->getIsContent();
  28. }
  29. /**
  30. * function which redifines Question::createAnswersForm
  31. * @param the formvalidator instance
  32. */
  33. function createAnswersForm($form) {
  34. $form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1'));
  35. global $text, $class;
  36. // setting the save button here and not in the question class.php
  37. $form->addElement('style_submit_button', 'submitQuestion', $text, 'class="' . $class . '"');
  38. if (!empty($this->id)) {
  39. $form->setDefaults(array('weighting' => Text::float_format($this->weighting, 1)));
  40. } else {
  41. if ($this->isContent == 1) {
  42. $form->setDefaults(array('weighting' => '10'));
  43. }
  44. }
  45. }
  46. /**
  47. * abstract function which creates the form to create / edit the answers of the question
  48. * @param the formvalidator instance
  49. */
  50. function processAnswersCreation($form) {
  51. $this->weighting = $form->getSubmitValue('weighting');
  52. $this->save();
  53. }
  54. function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false) {
  55. if (!empty($score['comments']) || $score['score'] > 0) {
  56. $score['revised'] = true;
  57. } else {
  58. $score['revised'] = false;
  59. }
  60. $header = parent::return_header($feedback_type, $counter, $score, $show_media);
  61. $header .= '<table class="' . $this->question_table_class . '" >
  62. <tr>
  63. <th>' . get_lang("Answer") . '</th>
  64. </tr>';
  65. return $header;
  66. }
  67. }
  68. endif;