Merge branch 'MDL-58281-file-missing-500' of https://github.com/brendanheywood/moodle
[moodle.git] / mod / folder / mod_form.php
blobec57d86cd4032bcc327459ccc390515162fb5645
1 <?php
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.
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/>.
18 /**
19 * Folder configuration form
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
26 defined('MOODLE_INTERNAL') || die();
28 require_once ($CFG->dirroot.'/course/moodleform_mod.php');
30 class mod_folder_mod_form extends moodleform_mod {
31 function definition() {
32 global $CFG;
33 $mform = $this->_form;
35 $config = get_config('folder');
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);
45 $mform->addRule('name', null, 'required', null, 'client');
46 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
47 $this->standard_intro_elements();
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');
60 $mform->setExpanded('content');
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);
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();
74 //-------------------------------------------------------
75 $this->add_action_buttons();
77 //-------------------------------------------------------
78 $mform->addElement('hidden', 'revision');
79 $mform->setType('revision', PARAM_INT);
80 $mform->setDefault('revision', 1);
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;
92 function validation($data, $files) {
93 $errors = parent::validation($data, $files);
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');
105 return $errors;