Merge branch 'MDL-51524-master' of git://github.com/andrewnicols/moodle
[moodle.git] / mod / folder / mod_form.php
blob7c6764ca806298b3e23c7a3b0b8e753045d872a6
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);
66 //-------------------------------------------------------
67 $this->standard_coursemodule_elements();
69 //-------------------------------------------------------
70 $this->add_action_buttons();
72 //-------------------------------------------------------
73 $mform->addElement('hidden', 'revision');
74 $mform->setType('revision', PARAM_INT);
75 $mform->setDefault('revision', 1);
78 function data_preprocessing(&$default_values) {
79 if ($this->current->instance) {
80 // editing existing instance - copy existing files into draft area
81 $draftitemid = file_get_submitted_draft_itemid('files');
82 file_prepare_draft_area($draftitemid, $this->context->id, 'mod_folder', 'content', 0, array('subdirs'=>true));
83 $default_values['files'] = $draftitemid;
87 function validation($data, $files) {
88 $errors = parent::validation($data, $files);
90 // Completion: Automatic on-view completion can not work together with
91 // "display inline" option
92 if (empty($errors['completion']) &&
93 array_key_exists('completion', $data) &&
94 $data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
95 !empty($data['completionview']) &&
96 $data['display'] == FOLDER_DISPLAY_INLINE) {
97 $errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
100 return $errors;