hotspot.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class HotSpot.
  5. *
  6. * This class allows to instantiate an object of
  7. * type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER)
  8. * extending the class question
  9. *
  10. * @author Eric Marguin
  11. *
  12. * @package chamilo.exercise
  13. */
  14. class HotSpot extends Question
  15. {
  16. public static $typePicture = 'hotspot.png';
  17. public static $explanationLangVar = 'HotSpot';
  18. /**
  19. * HotSpot constructor.
  20. */
  21. public function __construct()
  22. {
  23. parent::__construct();
  24. $this->type = HOT_SPOT;
  25. }
  26. public function display()
  27. {
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function createForm(&$form, $exercise)
  33. {
  34. parent::createForm($form, $exercise);
  35. if (!isset($_GET['editQuestion'])) {
  36. $icon = Display::return_icon(
  37. 'hotspot.png',
  38. null,
  39. null,
  40. ICON_SIZE_BIG,
  41. false,
  42. true
  43. );
  44. $form->addElement(
  45. 'file',
  46. 'imageUpload',
  47. [
  48. '<img src="'.$icon.'" />',
  49. get_lang('UploadJpgPicture'),
  50. ]
  51. );
  52. // setting the save button here and not in the question class.php
  53. // Saving a question
  54. $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
  55. $form->addRule(
  56. 'imageUpload',
  57. get_lang('OnlyImagesAllowed'),
  58. 'filetype',
  59. ['jpg', 'jpeg', 'png', 'gif']
  60. );
  61. $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
  62. } else {
  63. // setting the save button here and not in the question class.php
  64. // Editing a question
  65. $form->addButtonUpdate(get_lang('ModifyQuestion'), 'submitQuestion');
  66. }
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function processCreation($form, $exercise)
  72. {
  73. $fileInfo = $form->getSubmitValue('imageUpload');
  74. parent::processCreation($form, $exercise);
  75. if (!empty($fileInfo['tmp_name'])) {
  76. $result = $this->uploadPicture($fileInfo['tmp_name']);
  77. if ($result) {
  78. $this->save($exercise);
  79. return true;
  80. }
  81. }
  82. return false;
  83. }
  84. public function createAnswersForm($form)
  85. {
  86. // nothing
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function processAnswersCreation($form, $exercise)
  92. {
  93. // nothing
  94. }
  95. }
  96. /**
  97. * Class HotSpotDelineation.
  98. */
  99. class HotSpotDelineation extends HotSpot
  100. {
  101. public static $typePicture = 'hotspot-delineation.png';
  102. public static $explanationLangVar = 'HotspotDelineation';
  103. /**
  104. * HotSpotDelineation constructor.
  105. */
  106. public function __construct()
  107. {
  108. parent::__construct();
  109. $this->type = HOT_SPOT_DELINEATION;
  110. }
  111. /**
  112. * {@inheritdoc}
  113. */
  114. public function createForm(&$form, $exercise)
  115. {
  116. parent::createForm($form, $exercise);
  117. }
  118. /**
  119. * {@inheritdoc}
  120. */
  121. public function processCreation($form, $exercise)
  122. {
  123. parent::processCreation($form, $exercise);
  124. }
  125. public function createAnswersForm($form)
  126. {
  127. parent::createAnswersForm($form);
  128. }
  129. /**
  130. * {@inheritdoc}
  131. */
  132. public function processAnswersCreation($form, $exercise)
  133. {
  134. parent::processAnswersCreation($form, $exercise);
  135. }
  136. }