Annotation.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class Annotation
  5. * Allow instanciate an object of type HotSpot extending the class question.
  6. *
  7. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  8. */
  9. class Annotation extends Question
  10. {
  11. public $typePicture = 'annotation.png';
  12. public $explanationLangVar = 'Annotation';
  13. /**
  14. * Annotation constructor.
  15. */
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. $this->type = ANNOTATION;
  20. $this->isContent = $this->getIsContent();
  21. }
  22. public function display()
  23. {
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function createForm(&$form, $exercise)
  29. {
  30. parent::createForm($form, $exercise);
  31. $form->addElement(
  32. 'number',
  33. 'weighting',
  34. get_lang('Score'),
  35. ['step' => '0.1']
  36. );
  37. if (!empty($this->id)) {
  38. $form->setDefaults(['weighting' => float_format($this->weighting, 1)]);
  39. } else {
  40. if ($this->isContent == 1) {
  41. $form->setDefaults(['weighting' => '10']);
  42. }
  43. }
  44. global $text;
  45. if (isset($_GET['editQuestion'])) {
  46. $form->addButtonUpdate($text, 'submitQuestion');
  47. return;
  48. }
  49. $form->addElement(
  50. 'file',
  51. 'imageUpload',
  52. [
  53. Display::img(
  54. Display::return_icon(
  55. 'annotation.png',
  56. null,
  57. null,
  58. ICON_SIZE_BIG,
  59. false,
  60. true
  61. )
  62. ),
  63. get_lang('Upload image (jpg, png or gif) to apply hotspots.'),
  64. ]
  65. );
  66. $form->addButtonSave(get_lang('Go to question'), 'submitQuestion');
  67. $form->addRule(
  68. 'imageUpload',
  69. get_lang('Only PNG, JPG or GIF images allowed'),
  70. 'filetype',
  71. ['jpg', 'jpeg', 'png', 'gif']
  72. );
  73. $form->addRule('imageUpload', get_lang('Please select an image'), 'uploadedfile');
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function processCreation($form, $exercise)
  79. {
  80. $fileInfo = $form->getSubmitValue('imageUpload');
  81. parent::processCreation($form, $exercise);
  82. if (!empty($fileInfo['tmp_name'])) {
  83. $result = $this->uploadPicture($fileInfo['tmp_name']);
  84. if ($result) {
  85. $this->weighting = $form->getSubmitValue('weighting');
  86. $this->save($exercise);
  87. return true;
  88. }
  89. return false;
  90. }
  91. return false;
  92. }
  93. /**
  94. * @param FormValidator $form
  95. */
  96. public function createAnswersForm($form)
  97. {
  98. }
  99. /**
  100. * {@inheritdoc}
  101. */
  102. public function processAnswersCreation($form, $exercise)
  103. {
  104. $this->weighting = $form->getSubmitValue('weighting');
  105. $this->save($exercise);
  106. }
  107. /**
  108. * {@inheritdoc}
  109. */
  110. public function return_header(Exercise $exercise, $counter = null, $score = [])
  111. {
  112. $score['revised'] = $this->isQuestionWaitingReview($score);
  113. return parent::return_header($exercise, $counter, $score); // TODO: Change the autogenerated stub
  114. }
  115. }