Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Defines the main subcourse settings form
19
 *
20
 * @package     mod_subcourse
21
 * @category    form
22
 * @copyright   2008 David Mudrak <david@moodle.com>
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.'/mod/subcourse/locallib.php');
29
require_once($CFG->dirroot.'/course/moodleform_mod.php');
30
 
31
/**
32
 * Subcourse settings form
33
 *
34
 * @copyright 2008 David Mudrak <david@moodle.com>
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class mod_subcourse_mod_form extends moodleform_mod {
38
 
39
    /**
40
     * Form fields definition
41
     */
42
    public function definition() {
43
        global $CFG, $DB, $COURSE;
44
 
45
        $mform = $this->_form;
46
        $config = get_config('mod_subcourse');
47
 
48
        $mform->addElement('header', 'general', get_string('general', 'form'));
49
 
50
        $mform->addElement('text', 'name', get_string('subcoursename', 'subcourse'), ['size' => '64']);
51
        if (!empty($CFG->formatstringstriptags)) {
52
            $mform->setType('name', PARAM_TEXT);
53
        } else {
54
            $mform->setType('name', PARAM_CLEANHTML);
55
        }
56
        $mform->addRule('name', null, 'required', null, 'client');
57
        $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
58
 
59
        $this->standard_intro_elements();
60
 
61
        $mform->addElement('header', 'section-refcourse', get_string('refcourse', 'subcourse'));
62
        $mform->setExpanded('section-refcourse');
63
        $mform->addHelpButton('section-refcourse', 'refcourse', 'subcourse');
64
 
65
        $mycourses = subcourse_available_courses();
66
 
67
        $currentrefcourseid = isset($this->current->refcourse) ? $this->current->refcourse : null;
68
        $currentrefcoursename = null;
69
        $currentrefcourseavailable = false;
70
 
71
        if (!empty($currentrefcourseid)) {
72
 
73
            if ($currentrefcourseid == $COURSE->id) {
74
                // Invalid self-reference.
75
                $this->current->refcourse = 0;
76
                $includenoref = true;
77
 
78
            } else {
79
                $currentrefcoursename = $DB->get_field('course', 'fullname', ['id' => $currentrefcourseid], IGNORE_MISSING);
80
            }
81
 
82
            if ($currentrefcoursename === false) {
83
                // Reference to non-existing course.
84
                $this->current->refcourse = 0;
85
                $includenoref = true;
86
 
87
            } else {
88
                // Check if the currently set value is still available.
89
                foreach ($mycourses as $mycourse) {
90
                    if ($mycourse->id == $currentrefcourseid) {
91
                        $currentrefcourseavailable = true;
92
                        break;
93
                    }
94
                }
95
            }
96
        }
97
 
98
        if (!empty($currentrefcourseid) && !$currentrefcourseavailable) {
99
            // Currently referring to a course that is not available for us.
100
            // E.g. the admin has set up this Subcourse for the teacher or the teacher lost his role in the referred course etc.
101
            // Give them a chance to just keep such a reference.
102
            $mform->addElement('checkbox', 'refcoursecurrent', get_string('refcoursecurrent', 'subcourse'),
103
                format_string($currentrefcoursename));
104
            $mform->setDefault('refcoursecurrent', 1);
105
            $includekeepref = true;
106
        }
107
 
108
        $options = [get_string('none')];
109
 
110
        if (empty($mycourses)) {
111
            if (empty($includekeepref)) {
112
                $options = [0 => get_string('nocoursesavailable', 'subcourse')];
113
                $mform->addElement('select', 'refcourse', get_string('refcourselabel', 'subcourse'), $options);
114
            } else {
115
                $mform->addElement('hidden', 'refcourse', 0);
116
                $mform->setType('refcourse', PARAM_INT);
117
            }
118
 
119
        } else {
120
            $catlist = core_course_category::make_categories_list('', 0, ' / ');
121
 
122
            foreach ($mycourses as $mycourse) {
123
                $courselabel = $catlist[$mycourse->category] . ' / ' . $mycourse->fullname.' ('.$mycourse->shortname.')';
124
                $options[$mycourse->id] = $courselabel;
125
                if (empty($mycourse->visible)) {
126
                    $hiddenlabel = ' '.get_string('hiddencourse', 'subcourse');
127
                    $options[$mycourse->id] .= $hiddenlabel;
128
                }
129
            }
130
 
131
            $mform->addElement('autocomplete', 'refcourse', get_string('refcourselabel', 'subcourse'), $options);
132
 
133
            if (!empty($includekeepref)) {
134
                $mform->disabledIf('refcourse', 'refcoursecurrent', 'checked');
135
            }
136
        }
137
 
138
        $mform->addElement('header', 'section-gradesfetching', get_string('gradesfetching', 'subcourse'));
139
 
140
        $mform->addElement('select', 'fetchpercentage', get_string('fetchgradesmode', 'subcourse'), [
141
 
142
            1 => get_string('fetchgradesmode1', 'subcourse'),
143
        ]);
144
        $mform->addHelpButton('fetchpercentage', 'fetchgradesmode', 'subcourse');
145
 
146
        $mform->addElement('header', 'section-subcourselink', get_string('linkcontrol', 'subcourse'));
147
 
148
        $mform->addElement('checkbox', 'instantredirect', get_string('instantredirect', 'subcourse'));
149
        $mform->addHelpButton('instantredirect', 'instantredirect', 'subcourse');
150
 
151
        $mform->addElement('checkbox', 'blankwindow', get_string('blankwindow', 'subcourse'));
152
        $mform->addHelpButton('blankwindow', 'blankwindow', 'subcourse');
153
 
154
        $mform->addElement('header', 'optionssection', get_string('appearance'));
155
        $mform->addElement('checkbox', 'coursepageprintprogress', get_string('displayoption:coursepageprintprogress', 'subcourse'));
156
        $mform->setDefault('coursepageprintprogress', $config->coursepageprintprogress);
157
        $mform->addElement('checkbox', 'coursepageprintgrade', get_string('displayoption:coursepageprintgrade', 'subcourse'));
158
        $mform->setDefault('coursepageprintgrade', $config->coursepageprintgrade);
159
 
160
        $this->standard_coursemodule_elements();
161
        $this->add_action_buttons();
162
    }
163
 
164
    /**
165
     * Add elements for setting the custom completion rules.
166
     *
167
     * @category completion
168
     * @return array List of added element names, or names of wrapping group elements.
169
     */
170
    public function add_completion_rules() {
171
 
172
        $mform = $this->_form;
173
 
174
        $mform->addElement('advcheckbox', 'completioncourse', get_string('completioncourse', 'mod_subcourse'),
175
            get_string('completioncourse_text', 'mod_subcourse'));
176
        $mform->addHelpButton('completioncourse', 'completioncourse', 'mod_subcourse');
177
 
178
        return ['completioncourse'];
179
    }
180
 
181
    /**
182
     * Called during validation to see whether some module-specific completion rules are selected.
183
     *
184
     * @param array $data Input data not yet validated.
185
     * @return bool True if one or more rules is enabled, false if none are.
186
     */
187
    public function completion_rule_enabled($data) {
188
        return (!empty($data['completioncourse']));
189
    }
190
}