Annotation.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. * @package chamilo.
  8. */
  9. class Annotation extends Question
  10. {
  11. public static $typePicture = 'annotation.png';
  12. public static $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('Weighting'),
  35. ['step' => '0.1']
  36. );
  37. if (!empty($this->id)) {
  38. $form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
  39. } else {
  40. if ($this->isContent == 1) {
  41. $form->setDefaults(array('weighting' => '10'));
  42. }
  43. }
  44. if (isset($_GET['editQuestion'])) {
  45. $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion');
  46. return;
  47. }
  48. $form->addElement(
  49. 'file',
  50. 'imageUpload',
  51. array(
  52. Display::img(
  53. Display::return_icon(
  54. 'annotation.png',
  55. null,
  56. null,
  57. ICON_SIZE_BIG,
  58. false,
  59. true
  60. )
  61. ),
  62. get_lang('UploadJpgPicture'),
  63. )
  64. );
  65. $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
  66. $form->addRule(
  67. 'imageUpload',
  68. get_lang('OnlyImagesAllowed'),
  69. 'filetype',
  70. array('jpg', 'jpeg', 'png', 'gif')
  71. );
  72. $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. public function processCreation($form, $exercise)
  78. {
  79. $fileInfo = $form->getSubmitValue('imageUpload');
  80. parent::processCreation($form, $exercise);
  81. if (!empty($fileInfo['tmp_name'])) {
  82. $result = $this->uploadPicture($fileInfo['tmp_name']);
  83. if ($result) {
  84. $this->weighting = $form->getSubmitValue('weighting');
  85. $this->save($exercise);
  86. return true;
  87. }
  88. return false;
  89. }
  90. return false;
  91. }
  92. /**
  93. * @param FormValidator $form
  94. */
  95. public function createAnswersForm($form)
  96. {
  97. // nothing
  98. }
  99. /**
  100. * @inheritdoc
  101. */
  102. public function processAnswersCreation($form, $exercise)
  103. {
  104. $this->weighting = $form->getSubmitValue('weighting');
  105. $this->save($exercise);
  106. }
  107. }