PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/editor/atto/plugins/managefiles/manage_form.php

https://bitbucket.org/moodle/moodle
PHP | 119 lines | 71 code | 17 blank | 31 comment | 2 complexity | 0c3b29192d8fa801682f860015ed09f1 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Atto text editor manage files plugin form.
  18. *
  19. * @package atto_managefiles
  20. * @copyright 2014 Frédéric Massart
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once($CFG->libdir."/formslib.php");
  25. /**
  26. * Form allowing to edit files in one draft area.
  27. *
  28. * No buttons are necessary since the draft area files are saved immediately using AJAX.
  29. *
  30. * @package atto_managefiles
  31. * @copyright 2014 Frédéric Massart
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class atto_managefiles_manage_form extends moodleform {
  35. function definition() {
  36. global $PAGE, $USER;
  37. $mform = $this->_form;
  38. $mform->setDisableShortforms(true);
  39. $itemid = $this->_customdata['draftitemid'];
  40. $elementid = $this->_customdata['elementid'];
  41. $options = $this->_customdata['options'];
  42. $files = $this->_customdata['files'];
  43. $removeorphaneddrafts = $this->_customdata['removeorphaneddrafts'] ?? false;
  44. $mform->addElement('header', 'filemanagerhdr', get_string('filemanager', 'atto_managefiles'));
  45. $mform->addElement('hidden', 'itemid');
  46. $mform->setType('itemid', PARAM_INT);
  47. $mform->addElement('hidden', 'maxbytes');
  48. $mform->setType('maxbytes', PARAM_INT);
  49. $mform->addElement('hidden', 'subdirs');
  50. $mform->setType('subdirs', PARAM_INT);
  51. $mform->addElement('hidden', 'accepted_types');
  52. $mform->setType('accepted_types', PARAM_RAW);
  53. $mform->addElement('hidden', 'return_types');
  54. $mform->setType('return_types', PARAM_INT);
  55. $mform->addElement('hidden', 'context');
  56. $mform->setType('context', PARAM_INT);
  57. $mform->addElement('hidden', 'areamaxbytes');
  58. $mform->setType('areamaxbytes', PARAM_INT);
  59. $mform->addElement('hidden', 'elementid');
  60. $mform->setType('elementid', PARAM_TEXT);
  61. $mform->addElement('filemanager', 'files_filemanager', '', null, $options);
  62. // Let the user know that any drafts not referenced in the text will be removed automatically.
  63. if ($removeorphaneddrafts) {
  64. $mform->addElement('static', '', '',
  65. html_writer::tag('div', get_string('unusedfilesremovalnotice', 'atto_managefiles')));
  66. }
  67. $mform->addElement('header', 'missingfileshdr', get_string('missingfiles', 'atto_managefiles'));
  68. $mform->addElement('static', '', '',
  69. html_writer::tag('div',
  70. html_writer::tag('div', get_string('hasmissingfiles', 'atto_managefiles')) .
  71. html_writer::tag('div', '', array('class' => 'missing-files')
  72. ),
  73. array('class' => 'file-status'))
  74. );
  75. $mform->addElement('header', 'deletefileshdr', get_string('unusedfilesheader', 'atto_managefiles'));
  76. $mform->addElement('static', '', '',
  77. html_writer::tag('div', get_string('unusedfilesdesc', 'atto_managefiles')));
  78. foreach ($files as $hash => $file) {
  79. $mform->addElement('checkbox', 'deletefile[' . $hash . ']', '', $file, array('data-filename' => $file));
  80. $mform->setType('deletefile[' . $hash . ']', PARAM_INT);
  81. }
  82. $mform->addElement('submit', 'delete', get_string('deleteselected', 'atto_managefiles'));
  83. $PAGE->requires->yui_module('moodle-atto_managefiles-usedfiles', 'M.atto_managefiles.usedfiles.init',
  84. array(array(
  85. 'files' => array_flip($files),
  86. 'usercontext' => context_user::instance($USER->id)->id,
  87. 'itemid' => $itemid,
  88. 'elementid' => $elementid,
  89. )));
  90. $this->set_data(array(
  91. 'files_filemanager' => $itemid,
  92. 'itemid' => $itemid,
  93. 'elementid' => $elementid,
  94. 'subdirs' => $options['subdirs'],
  95. 'maxbytes' => $options['maxbytes'],
  96. 'areamaxbytes' => $options['areamaxbytes'],
  97. 'accepted_types' => $options['accepted_types'],
  98. 'return_types' => $options['return_types'],
  99. 'context' => $options['context']->id,
  100. ));
  101. }
  102. }