freeanswer.class.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /**
  15. * @package chamilo.exercise
  16. */
  17. class FreeAnswer extends Question
  18. {
  19. static $typePicture = 'open_answer.gif';
  20. static $explanationLangVar = 'FreeAnswer';
  21. /**
  22. * Constructor
  23. */
  24. public function __construct()
  25. {
  26. parent::question();
  27. $this->type = FREE_ANSWER;
  28. $this->isContent = $this->getIsContent();
  29. }
  30. /**
  31. * function which redefines Question::createAnswersForm
  32. * @param FormValidator instance
  33. */
  34. public function createAnswersForm($form)
  35. {
  36. if ($this->exercise->getModelType() == EXERCISE_MODEL_TYPE_NORMAL) {
  37. $form->addElement('text', 'weighting', get_lang('Weighting'), array('class' => 'span1'));
  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. if ($form->isFrozen() == false) {
  47. // Setting the save button here and not in the question class.php.
  48. $form->addElement('style_submit_button', 'submitQuestion', $this->submitText, 'class="'.$this->submitClass.'"');
  49. }
  50. }
  51. /**
  52. * abstract function which creates the form to create / edit the answers of the question
  53. * @param FormValidator instance
  54. */
  55. public function processAnswersCreation($form)
  56. {
  57. $this->weighting = $form->getSubmitValue('weighting');
  58. $this->save();
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. function return_header($feedback_type = null, $counter = null, $score = null, $show_media = false, $hideTitle = 0)
  64. {
  65. if (!empty($score['comments']) || $score['score'] > 0) {
  66. $score['revised'] = true;
  67. } else {
  68. $score['revised'] = false;
  69. }
  70. $header = parent::return_header($feedback_type, $counter, $score, $show_media, $hideTitle);
  71. $header .= '<table class="'.$this->question_table_class.'" >
  72. <tr>
  73. <th>'.get_lang("Answer").'</th>
  74. </tr>';
  75. return $header;
  76. }
  77. }