hotspot.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. $file_info = $form->getSubmitValue('imageUpload');
  74. parent::processCreation($form, $exercise);
  75. if (!empty($file_info['tmp_name'])) {
  76. $result = $this->uploadPicture($file_info['tmp_name']);
  77. if ($result) {
  78. $this->save($exercise);
  79. return true;
  80. } else {
  81. return false;
  82. }
  83. }
  84. return false;
  85. }
  86. public function createAnswersForm($form)
  87. {
  88. // nothing
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function processAnswersCreation($form, $exercise)
  94. {
  95. // nothing
  96. }
  97. }
  98. /**
  99. * Class HotSpotDelineation.
  100. */
  101. class HotSpotDelineation extends HotSpot
  102. {
  103. public static $typePicture = 'hotspot-delineation.png';
  104. public static $explanationLangVar = 'HotspotDelineation';
  105. /**
  106. * HotSpotDelineation constructor.
  107. */
  108. public function __construct()
  109. {
  110. parent::__construct();
  111. $this->type = HOT_SPOT_DELINEATION;
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public function createForm(&$form, $exercise)
  117. {
  118. parent::createForm($form);
  119. }
  120. /**
  121. * {@inheritdoc}
  122. */
  123. public function processCreation($form, $exercise)
  124. {
  125. parent::processCreation($form, $exercise);
  126. }
  127. public function createAnswersForm($form)
  128. {
  129. parent::createAnswersForm($form);
  130. }
  131. /**
  132. * {@inheritdoc}
  133. */
  134. public function processAnswersCreation($form, $exercise)
  135. {
  136. parent::processAnswersCreation($form, $exercise);
  137. }
  138. }