Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
        // Adding option to enable viewing of individual files.
73
        $mform->addElement('advcheckbox', 'forcedownload', get_string('forcedownload', 'folder'));
74
        $mform->addHelpButton('forcedownload', 'forcedownload', 'mod_folder');
75
        $mform->setDefault('forcedownload', true);
76
 
77
        //-------------------------------------------------------
78
        $this->standard_coursemodule_elements();
79
 
80
        //-------------------------------------------------------
81
        $this->add_action_buttons();
82
 
83
        //-------------------------------------------------------
84
        $mform->addElement('hidden', 'revision');
85
        $mform->setType('revision', PARAM_INT);
86
        $mform->setDefault('revision', 1);
87
    }
88
 
89
    function data_preprocessing(&$default_values) {
90
        if ($this->current->instance) {
91
            // editing existing instance - copy existing files into draft area
92
            $draftitemid = file_get_submitted_draft_itemid('files');
93
            file_prepare_draft_area($draftitemid, $this->context->id, 'mod_folder', 'content', 0, array('subdirs'=>true));
94
            $default_values['files'] = $draftitemid;
95
        }
96
    }
97
 
98
    function validation($data, $files) {
99
        $errors = parent::validation($data, $files);
100
 
101
        // Completion: Automatic on-view completion can not work together with
102
        // "display inline" option
103
        if (empty($errors['completion']) &&
104
                array_key_exists('completion', $data) &&
105
                $data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
106
                !empty($data['completionview']) &&
107
                $data['display'] == FOLDER_DISPLAY_INLINE) {
108
            $errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
109
        }
110
 
111
        return $errors;
112
    }
113
}