Annotation.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. * @param FormValidator $form
  27. * @param int $fck_config
  28. */
  29. public function createForm(&$form, $fck_config = 0)
  30. {
  31. parent::createForm($form, $fck_config);
  32. $form->addElement(
  33. 'number',
  34. 'weighting',
  35. get_lang('Weighting'),
  36. ['step' => '0.1']
  37. );
  38. if (!empty($this->id)) {
  39. $form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
  40. } else {
  41. if ($this->isContent == 1) {
  42. $form->setDefaults(array('weighting' => '10'));
  43. }
  44. }
  45. if (isset($_GET['editQuestion'])) {
  46. $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion');
  47. return;
  48. }
  49. $form->addElement(
  50. 'file',
  51. 'imageUpload',
  52. array(
  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('UploadJpgPicture'),
  64. )
  65. );
  66. $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
  67. $form->addRule(
  68. 'imageUpload',
  69. get_lang('OnlyImagesAllowed'),
  70. 'filetype',
  71. array('jpg', 'jpeg', 'png', 'gif')
  72. );
  73. $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
  74. }
  75. /**
  76. * @param FormValidator $form
  77. * @param null $objExercise
  78. * @return bool
  79. */
  80. public function processCreation($form, $objExercise = null)
  81. {
  82. $fileInfo = $form->getSubmitValue('imageUpload');
  83. parent::processCreation($form, $objExercise);
  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();
  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. // nothing
  101. }
  102. /**
  103. * @param FormValidator $form
  104. */
  105. public function processAnswersCreation($form)
  106. {
  107. $this->weighting = $form->getSubmitValue('weighting');
  108. $this->save();
  109. }
  110. }