hotspot.class.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 $typePicture = 'hotspot.png';
  17. public $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. }