Annotation.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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('number', 'weighting', get_lang('Weighting'), ['step' => '0.1']);
  33. if (!empty($this->id)) {
  34. $form->setDefaults(array('weighting' => float_format($this->weighting, 1)));
  35. } else {
  36. if ($this->isContent == 1) {
  37. $form->setDefaults(array('weighting' => '10'));
  38. }
  39. }
  40. if (isset($_GET['editQuestion'])) {
  41. $form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion');
  42. return;
  43. }
  44. $form->addElement(
  45. 'file',
  46. 'imageUpload',
  47. array(
  48. Display::img(
  49. Display::return_icon('annotation.png', null, null, ICON_SIZE_BIG, false, true)
  50. ),
  51. get_lang('UploadJpgPicture'),
  52. )
  53. );
  54. $form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion');
  55. $form->addRule('imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
  56. $form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile');
  57. }
  58. /**
  59. * @param FormValidator $form
  60. * @param null $objExercise
  61. * @return bool
  62. */
  63. public function processCreation($form, $objExercise = null)
  64. {
  65. $fileInfo = $form->getSubmitValue('imageUpload');
  66. parent::processCreation($form, $objExercise);
  67. if (!empty($fileInfo['tmp_name'])) {
  68. $result = $this->uploadPicture($fileInfo['tmp_name']);
  69. if ($result) {
  70. $this->weighting = $form->getSubmitValue('weighting');
  71. $this->save();
  72. return true;
  73. }
  74. return false;
  75. }
  76. return false;
  77. }
  78. /**
  79. * @param FormValidator $form
  80. */
  81. function createAnswersForm($form)
  82. {
  83. // nothing
  84. }
  85. /**
  86. * @param FormValidator $form
  87. */
  88. function processAnswersCreation($form)
  89. {
  90. $this->weighting = $form->getSubmitValue('weighting');
  91. $this->save();
  92. }
  93. }