Annotation.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. * @package chamilo.
  10. */
  11. class Annotation extends Question
  12. {
  13. public static $typePicture = 'annotation.png';
  14. public static $explanationLangVar = 'Annotation';
  15. /**
  16. * Annotation constructor.
  17. */
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. $this->type = ANNOTATION;
  22. $this->isContent = $this->getIsContent();
  23. }
  24. public function display()
  25. {
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function createForm(&$form, $exercise)
  31. {
  32. parent::createForm($form, $exercise);
  33. $form->addElement(
  34. 'number',
  35. 'weighting',
  36. get_lang('Weighting'),
  37. ['step' => '0.1']
  38. );
  39. if (!empty($this->id)) {
  40. $form->setDefaults(['weighting' => float_format($this->weighting, 1)]);
  41. } else {
  42. if ($this->isContent == 1) {
  43. $form->setDefaults(['weighting' => '10']);
  44. }
  45. }
  46. global $text;
  47. if (isset($_GET['editQuestion'])) {
  48. $form->addButtonUpdate($text, 'submitQuestion');
  49. return;
  50. }
  51. $form->addElement(
  52. 'file',
  53. 'imageUpload',
  54. [
  55. Display::img(
  56. Display::return_icon(
  57. 'annotation.png',
  58. null,
  59. null,
  60. ICON_SIZE_BIG,
  61. false,
  62. true
  63. )
  64. ),
  65. get_lang('UploadJpgPicture'),
  66. ]
  67. );
  68. $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
  69. $form->addRule(
  70. 'imageUpload',
  71. get_lang('OnlyImagesAllowed'),
  72. 'filetype',
  73. ['jpg', 'jpeg', 'png', 'gif']
  74. );
  75. $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function processCreation($form, $exercise)
  81. {
  82. $fileInfo = $form->getSubmitValue('imageUpload');
  83. parent::processCreation($form, $exercise);
  84. if (!empty($fileInfo['tmp_name'])) {
  85. $result = $this->uploadPicture($fileInfo['tmp_name']);
  86. if ($result) {
  87. $this->weighting = $form->getSubmitValue('weighting');
  88. $this->save($exercise);
  89. return true;
  90. }
  91. return false;
  92. }
  93. return false;
  94. }
  95. /**
  96. * @param FormValidator $form
  97. */
  98. public function createAnswersForm($form)
  99. {
  100. }
  101. /**
  102. * {@inheritdoc}
  103. */
  104. public function processAnswersCreation($form, $exercise)
  105. {
  106. $this->weighting = $form->getSubmitValue('weighting');
  107. $this->save($exercise);
  108. }
  109. /**
  110. * {@inheritdoc}
  111. */
  112. public function return_header(Exercise $exercise, $counter = null, $score = [])
  113. {
  114. $score['revised'] = $this->isQuestionWaitingReview($score);
  115. return parent::return_header($exercise, $counter, $score); // TODO: Change the autogenerated stub
  116. }
  117. }