hotspot.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class HotSpot
  5. *
  6. * This class allows to instantiate an object of type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER),
  7. * extending the class question
  8. *
  9. * @author Eric Marguin
  10. * @package chamilo.exercise
  11. **/
  12. class HotSpot extends Question
  13. {
  14. static $typePicture = 'hotspot.png';
  15. static $explanationLangVar = 'HotSpot';
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. $this -> type = HOT_SPOT;
  20. }
  21. public function display()
  22. {
  23. }
  24. /**
  25. * @param FormValidator $form
  26. * @param int $fck_config
  27. */
  28. public function createForm (&$form, $fck_config=0)
  29. {
  30. parent::createForm($form, $fck_config);
  31. if (!isset($_GET['editQuestion'])) {
  32. $form->addElement('file','imageUpload',array('<img src="../img/hotspots.png" />', get_lang('UploadJpgPicture')) );
  33. // setting the save button here and not in the question class.php
  34. // Saving a question
  35. $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
  36. //$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
  37. $form->addRule('imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif'));
  38. $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
  39. } else {
  40. // setting the save button here and not in the question class.php
  41. // Editing a question
  42. $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion');
  43. }
  44. }
  45. /**
  46. * @param FormValidator $form
  47. * @param null $objExercise
  48. * @return bool
  49. */
  50. public function processCreation($form, $objExercise = null)
  51. {
  52. $file_info = $form->getSubmitValue('imageUpload');
  53. $_course = api_get_course_info();
  54. parent::processCreation($form, $objExercise);
  55. if(!empty($file_info['tmp_name'])) {
  56. $this->uploadPicture($file_info['tmp_name'], $file_info['name']);
  57. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  58. $picturePath = $documentPath.'/images';
  59. // fixed width ang height
  60. if (file_exists($picturePath.'/'.$this->picture)) {
  61. list($width,$height) = @getimagesize($picturePath.'/'.$this->picture);
  62. if ($width > $height) {
  63. $this->resizePicture('width', 545);
  64. } else {
  65. $this->resizePicture('height', 350);
  66. }
  67. $this->save();
  68. } else {
  69. return false;
  70. }
  71. }
  72. }
  73. function createAnswersForm ($form)
  74. {
  75. // nothing
  76. }
  77. function processAnswersCreation ($form)
  78. {
  79. // nothing
  80. }
  81. }
  82. /**
  83. * Class HotSpotDelineation
  84. */
  85. class HotSpotDelineation extends HotSpot
  86. {
  87. static $typePicture = 'hotspot_delineation.gif';
  88. static $explanationLangVar = 'HotspotDelineation';
  89. function __construct()
  90. {
  91. parent::__construct();
  92. $this -> type = HOT_SPOT_DELINEATION;
  93. }
  94. function createForm (&$form, $fck_config=0)
  95. {
  96. parent::createForm ($form, $fck_config);
  97. }
  98. function processCreation ($form, $objExercise = null)
  99. {
  100. $file_info = $form -> getSubmitValue('imageUpload');
  101. parent::processCreation ($form, $objExercise);
  102. }
  103. function createAnswersForm ($form)
  104. {
  105. parent::createAnswersForm ($form);
  106. }
  107. function processAnswersCreation ($form)
  108. {
  109. parent::processAnswersCreation ($form);
  110. }
  111. }