Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Folder configuration form
  20   *
  21   * @package   mod_folder
  22   * @copyright 2009 Petr Skoda  {@link http://skodak.org}
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once ($CFG->dirroot.'/course/moodleform_mod.php');
  29  
  30  class mod_folder_mod_form extends moodleform_mod {
  31      function definition() {
  32          global $CFG;
  33          $mform = $this->_form;
  34  
  35          $config = get_config('folder');
  36  
  37          //-------------------------------------------------------
  38          $mform->addElement('header', 'general', get_string('general', 'form'));
  39          $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
  40          if (!empty($CFG->formatstringstriptags)) {
  41              $mform->setType('name', PARAM_TEXT);
  42          } else {
  43              $mform->setType('name', PARAM_CLEANHTML);
  44          }
  45          $mform->addRule('name', null, 'required', null, 'client');
  46          $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
  47          $this->standard_intro_elements();
  48  
  49          //-------------------------------------------------------
  50          $mform->addElement('header', 'content', get_string('contentheader', 'folder'));
  51          $mform->addElement('filemanager', 'files', get_string('files'), null, array('subdirs'=>1, 'accepted_types'=>'*'));
  52          $mform->addElement('select', 'display', get_string('display', 'mod_folder'),
  53                  array(FOLDER_DISPLAY_PAGE => get_string('displaypage', 'mod_folder'),
  54                      FOLDER_DISPLAY_INLINE => get_string('displayinline', 'mod_folder')));
  55          $mform->addHelpButton('display', 'display', 'mod_folder');
  56          if (!$this->courseformat->has_view_page()) {
  57              $mform->setConstant('display', FOLDER_DISPLAY_PAGE);
  58              $mform->hardFreeze('display');
  59          }
  60          $mform->setExpanded('content');
  61  
  62          // Adding option to show sub-folders expanded or collapsed by default.
  63          $mform->addElement('advcheckbox', 'showexpanded', get_string('showexpanded', 'folder'));
  64          $mform->addHelpButton('showexpanded', 'showexpanded', 'mod_folder');
  65          $mform->setDefault('showexpanded', $config->showexpanded);
  66  
  67          // Adding option to enable downloading archive of folder.
  68          $mform->addElement('advcheckbox', 'showdownloadfolder', get_string('showdownloadfolder', 'folder'));
  69          $mform->addHelpButton('showdownloadfolder', 'showdownloadfolder', 'mod_folder');
  70          $mform->setDefault('showdownloadfolder', true);
  71          //-------------------------------------------------------
  72          $this->standard_coursemodule_elements();
  73  
  74          //-------------------------------------------------------
  75          $this->add_action_buttons();
  76  
  77          //-------------------------------------------------------
  78          $mform->addElement('hidden', 'revision');
  79          $mform->setType('revision', PARAM_INT);
  80          $mform->setDefault('revision', 1);
  81      }
  82  
  83      function data_preprocessing(&$default_values) {
  84          if ($this->current->instance) {
  85              // editing existing instance - copy existing files into draft area
  86              $draftitemid = file_get_submitted_draft_itemid('files');
  87              file_prepare_draft_area($draftitemid, $this->context->id, 'mod_folder', 'content', 0, array('subdirs'=>true));
  88              $default_values['files'] = $draftitemid;
  89          }
  90      }
  91  
  92      function validation($data, $files) {
  93          $errors = parent::validation($data, $files);
  94  
  95          // Completion: Automatic on-view completion can not work together with
  96          // "display inline" option
  97          if (empty($errors['completion']) &&
  98                  array_key_exists('completion', $data) &&
  99                  $data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
 100                  !empty($data['completionview']) &&
 101                  $data['display'] == FOLDER_DISPLAY_INLINE) {
 102              $errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
 103          }
 104  
 105          return $errors;
 106      }
 107  }