MDL-31936 course: Add missing file level docblock to the reset_form.php
[moodle.git] / course / reset_form.php
CommitLineData
aa6c1ced 1<?php
e04a0f6b
DM
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 * Provides the course_reset_form class.
19 *
20 * @package core
21 * @copyright 2007 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
bfebaf64 26
0b5a80a1 27require_once $CFG->libdir.'/formslib.php';
28
e04a0f6b
DM
29/**
30 * Defines the course reset settings form.
31 *
32 * @copyright 2007 Petr Skoda
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 */
0b5a80a1 35class course_reset_form extends moodleform {
36 function definition (){
6bb08163 37 global $CFG, $COURSE, $DB;
0b5a80a1 38
39 $mform =& $this->_form;
40
41 $mform->addElement('header', 'generalheader', get_string('general'));
42
43 $mform->addElement('date_selector', 'reset_start_date', get_string('startdate'), array('optional'=>true));
5fb88219 44 $mform->addHelpButton('reset_start_date', 'startdate');
0b5a80a1 45 $mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
0b5a80a1 46 $mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
c343ddf8 47 $mform->addElement('checkbox', 'reset_comments', get_string('deleteallcomments', 'moodle'));
5ae17b09 48 $mform->addElement('checkbox', 'reset_completion', get_string('deletecompletiondata', 'completion'));
5a5cd650 49 $mform->addElement('checkbox', 'delete_blog_associations', get_string('deleteblogassociations', 'blog'));
2650f44d 50 $mform->addHelpButton('delete_blog_associations', 'deleteblogassociations', 'blog');
0b5a80a1 51
52
53 $mform->addElement('header', 'rolesheader', get_string('roles'));
54
9a5e297b 55 $roles = get_assignable_roles(context_course::instance($COURSE->id));
2e15b12b
PS
56 $roles[0] = get_string('noroles', 'role');
57 $roles = array_reverse($roles, true);
58
df997f84 59 $mform->addElement('select', 'unenrol_users', get_string('unenrolroleusers', 'enrol'), $roles, array('multiple' => 'multiple'));
0b5a80a1 60 $mform->addElement('checkbox', 'reset_roles_overrides', get_string('deletecourseoverrides', 'role'));
61 $mform->setAdvanced('reset_roles_overrides');
62 $mform->addElement('checkbox', 'reset_roles_local', get_string('deletelocalroles', 'role'));
63
64
65 $mform->addElement('header', 'gradebookheader', get_string('gradebook', 'grades'));
66
67 $mform->addElement('checkbox', 'reset_gradebook_items', get_string('removeallcourseitems', 'grades'));
68 $mform->addElement('checkbox', 'reset_gradebook_grades', get_string('removeallcoursegrades', 'grades'));
69 $mform->disabledIf('reset_gradebook_grades', 'reset_gradebook_items', 'checked');
70
71
72 $mform->addElement('header', 'groupheader', get_string('groups'));
73
74 $mform->addElement('checkbox', 'reset_groups_remove', get_string('deleteallgroups', 'group'));
75 $mform->setAdvanced('reset_groups_remove');
76 $mform->addElement('checkbox', 'reset_groups_members', get_string('removegroupsmembers', 'group'));
77 $mform->setAdvanced('reset_groups_members');
78 $mform->disabledIf('reset_groups_members', 'reset_groups_remove', 'checked');
79
98da6021
PS
80 $mform->addElement('checkbox', 'reset_groupings_remove', get_string('deleteallgroupings', 'group'));
81 $mform->setAdvanced('reset_groupings_remove');
82 $mform->addElement('checkbox', 'reset_groupings_members', get_string('removegroupingsmembers', 'group'));
83 $mform->setAdvanced('reset_groupings_members');
84 $mform->disabledIf('reset_groupings_members', 'reset_groupings_remove', 'checked');
0b5a80a1 85
86 $unsupported_mods = array();
6bb08163 87 if ($allmods = $DB->get_records('modules') ) {
0b5a80a1 88 foreach ($allmods as $mod) {
89 $modname = $mod->name;
0b5a80a1 90 $modfile = $CFG->dirroot."/mod/$modname/lib.php";
91 $mod_reset_course_form_definition = $modname.'_reset_course_form_definition';
92 $mod_reset__userdata = $modname.'_reset_userdata';
93 if (file_exists($modfile)) {
30338539
TL
94 if (!$DB->count_records($modname, array('course'=>$COURSE->id))) {
95 continue; // Skip mods with no instances
96 }
0b5a80a1 97 include_once($modfile);
98 if (function_exists($mod_reset_course_form_definition)) {
99 $mod_reset_course_form_definition($mform);
100 } else if (!function_exists($mod_reset__userdata)) {
101 $unsupported_mods[] = $mod;
102 }
103 } else {
104 debugging('Missing lib.php in '.$modname.' module');
105 }
106 }
107 }
108 // mention unsupported mods
109 if (!empty($unsupported_mods)) {
110 $mform->addElement('header', 'unsupportedheader', get_string('resetnotimplemented'));
111 foreach($unsupported_mods as $mod) {
112 $mform->addElement('static', 'unsup'.$mod->name, get_string('modulenameplural', $mod->name));
113 $mform->setAdvanced('unsup'.$mod->name);
114 }
115 }
116
117 $mform->addElement('hidden', 'id', $COURSE->id);
d18e0fe6 118 $mform->setType('id', PARAM_INT);
0b5a80a1 119
120 $buttonarray = array();
121 $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('resetcourse'));
122 $buttonarray[] = &$mform->createElement('submit', 'selectdefault', get_string('selectdefault'));
123 $buttonarray[] = &$mform->createElement('submit', 'deselectall', get_string('deselectall'));
124 $buttonarray[] = &$mform->createElement('cancel');
125 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
126 $mform->closeHeaderBefore('buttonar');
127 }
128
129 function load_defaults() {
6bb08163 130 global $CFG, $COURSE, $DB;
0b5a80a1 131
132 $mform =& $this->_form;
133
bb8d6e1a 134 $defaults = array ('reset_events'=>1, 'reset_roles_local'=>1, 'reset_gradebook_grades'=>1, 'reset_notes'=>1);
0b5a80a1 135
b2da6472
RT
136 // Set student as default in unenrol user list, if role with student archetype exist.
137 if ($studentrole = get_archetype_roles('student')) {
138 $defaults['unenrol_users'] = array_keys($studentrole);
139 }
140
6bb08163 141 if ($allmods = $DB->get_records('modules') ) {
0b5a80a1 142 foreach ($allmods as $mod) {
143 $modname = $mod->name;
144 $modfile = $CFG->dirroot."/mod/$modname/lib.php";
145 $mod_reset_course_form_defaults = $modname.'_reset_course_form_defaults';
146 if (file_exists($modfile)) {
147 @include_once($modfile);
148 if (function_exists($mod_reset_course_form_defaults)) {
97481934 149 if ($moddefs = $mod_reset_course_form_defaults($COURSE)) {
150 $defaults = $defaults + $moddefs;
151 }
0b5a80a1 152 }
153 }
154 }
155 }
156
157 foreach ($defaults as $element=>$default) {
158 $mform->setDefault($element, $default);
159 }
160 }
161}