Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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  /**
  18   * Atto text editor manage files plugin form.
  19   *
  20   * @package   tiny_media
  21   * @copyright 2022, Stevani Andolo <stevani@hotmail.com.au>
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tiny_media\form;
  26  
  27  use html_writer;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  require_once("{$CFG->libdir}/formslib.php");
  32  
  33  /**
  34   * Form allowing to edit files in one draft area.
  35   *
  36   * @package tiny_media
  37   * @copyright 2022, Stevani Andolo <stevani@hotmail.com.au>
  38   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class manage_files_form extends \moodleform {
  41  
  42      public function definition() {
  43          global $PAGE, $USER;
  44          $mform = $this->_form;
  45  
  46          $mform->setDisableShortforms(true);
  47  
  48          $itemid = $this->_customdata['draftitemid'];
  49          $elementid = $this->_customdata['elementid'];
  50          $options = $this->_customdata['options'];
  51          $files = $this->_customdata['files'];
  52          $usercontext = $this->_customdata['context'];
  53          $removeorphaneddrafts = $this->_customdata['removeorphaneddrafts'] ?? false;
  54  
  55          $mform->addElement('header', 'filemanagerhdr', get_string('filemanager', 'tiny_media'));
  56  
  57          $mform->addElement('hidden', 'itemid');
  58          $mform->setType('itemid', PARAM_INT);
  59  
  60          $mform->addElement('hidden', 'maxbytes');
  61          $mform->setType('maxbytes', PARAM_INT);
  62  
  63          $mform->addElement('hidden', 'subdirs');
  64          $mform->setType('subdirs', PARAM_INT);
  65  
  66          $mform->addElement('hidden', 'accepted_types');
  67          $mform->setType('accepted_types', PARAM_RAW);
  68  
  69          $mform->addElement('hidden', 'return_types');
  70          $mform->setType('return_types', PARAM_INT);
  71  
  72          $mform->addElement('hidden', 'context');
  73          $mform->setType('context', PARAM_INT);
  74  
  75          $mform->addElement('hidden', 'areamaxbytes');
  76          $mform->setType('areamaxbytes', PARAM_INT);
  77  
  78          $mform->addElement('hidden', 'elementid');
  79          $mform->setType('elementid', PARAM_TEXT);
  80  
  81          $mform->addElement('filemanager', 'files_filemanager', '', null, $options);
  82  
  83          // Let the user know that any drafts not referenced in the text will be removed automatically.
  84          if ($removeorphaneddrafts) {
  85              $mform->addElement('static', '', '', html_writer::tag(
  86                  'div',
  87                  get_string('unusedfilesremovalnotice', 'tiny_media')
  88              ));
  89          }
  90  
  91          $mform->addElement('header', 'missingfileshdr', get_string('missingfiles', 'tiny_media'));
  92          $mform->addElement('static', '', '',
  93              html_writer::tag(
  94                  'div',
  95                  html_writer::tag('div', get_string('hasmissingfiles', 'tiny_media')) .
  96                  html_writer::tag('div', '', ['class' => 'missing-files']
  97              ),
  98              ['class' => 'file-status'])
  99          );
 100  
 101          $mform->addElement('header', 'deletefileshdr', get_string('unusedfilesheader', 'tiny_media'));
 102          $mform->addElement('static', '', '', html_writer::tag('div', get_string('unusedfilesdesc', 'tiny_media')));
 103  
 104          foreach ($files as $hash => $file) {
 105              $mform->addElement('checkbox', "deletefile[{$hash}]", '', $file, ['data-filename' => $file]);
 106              $mform->setType("deletefile[{$hash}]", PARAM_INT);
 107          }
 108  
 109          $mform->addElement('submit', 'delete', get_string('deleteselected', 'tiny_media'));
 110  
 111          $PAGE->requires->js_call_amd('tiny_media/usedfiles', 'init', [
 112              'files' => array_flip($files),
 113              'usercontext' => $usercontext->id,
 114              'itemid' => $itemid,
 115              'elementid' => $elementid,
 116          ]);
 117      }
 118  }