freeanswer.class.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. {
  35. $form -> addElement('text','weighting',get_lang('Weighting'),'size="5"');
  36. global $text, $class;
  37. // setting the save button here and not in the question class.php
  38. $form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
  39. if (!empty($this->id)) {
  40. $form -> setDefaults(array('weighting' => float_format($this->weighting, 1)));
  41. } else {
  42. if ($this -> isContent == 1) {
  43. $form -> setDefaults(array('weighting' => '10'));
  44. }
  45. }
  46. }
  47. /**
  48. * abstract function which creates the form to create / edit the answers of the question
  49. * @param the formvalidator instance
  50. */
  51. function processAnswersCreation($form)
  52. {
  53. $this -> weighting = $form -> getSubmitValue('weighting');
  54. $this->save();
  55. }
  56. function return_header($feedback_type, $counter = null) {
  57. parent::return_header($feedback_type, $counter);
  58. $header = '<table width="100%" class="data_table_exercise_result_left" >
  59. <tr>
  60. <td><i>'.get_lang("Answer").'</i></td>
  61. </tr>';
  62. return $header;
  63. }
  64. }
  65. endif;
  66. ?>