| Línea 12... |
Línea 12... |
| 12 |
// GNU General Public License for more details.
|
12 |
// GNU General Public License for more details.
|
| 13 |
//
|
13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
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/>.
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
| Línea 16... |
Línea -... |
| 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 |
|
16 |
|
| Línea 25... |
Línea 17... |
| 25 |
defined('MOODLE_INTERNAL') || die();
|
17 |
defined('MOODLE_INTERNAL') || die();
|
| 26 |
|
18 |
|
| Línea 27... |
Línea 19... |
| 27 |
require_once $CFG->libdir.'/formslib.php';
|
19 |
require_once($CFG->libdir.'/formslib.php');
|
| 28 |
require_once($CFG->dirroot . '/course/lib.php');
|
20 |
require_once($CFG->dirroot . '/course/lib.php');
|
| 29 |
|
21 |
|
| - |
|
22 |
/**
|
| 30 |
/**
|
23 |
* Defines the course reset settings form.
|
| 31 |
* Defines the course reset settings form.
|
24 |
*
|
| 32 |
*
|
25 |
* @package core_course
|
| 33 |
* @copyright 2007 Petr Skoda
|
26 |
* @copyright 2007 Petr Skoda
|
| - |
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| - |
|
28 |
*/
|
| - |
|
29 |
class course_reset_form extends moodleform {
|
| - |
|
30 |
|
| 34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
31 |
/**
|
| 35 |
*/
|
32 |
* Form definition.
|
| Línea 36... |
Línea 33... |
| 36 |
class course_reset_form extends moodleform {
|
33 |
*/
|
| Línea 37... |
Línea 34... |
| 37 |
function definition(){
|
34 |
public function definition() {
|
| 38 |
global $CFG, $COURSE, $DB;
|
- |
|
| 39 |
|
35 |
global $CFG, $COURSE, $DB;
|
| 40 |
$mform =& $this->_form;
|
36 |
|
| 41 |
|
37 |
$mform = $this->_form;
|
| 42 |
$mform->addElement('header', 'generalheader', get_string('general'));
|
38 |
|
| - |
|
39 |
$mform->addElement('header', 'generalheader', get_string('general'));
|
| 43 |
|
40 |
$mform->addElement('date_time_selector', 'reset_start_date', get_string('startdate'), ['optional' => true]);
|
| 44 |
$mform->addElement('date_time_selector', 'reset_start_date', get_string('startdate'), array('optional' => true));
|
41 |
$mform->addHelpButton('reset_start_date', 'startdate');
|
| 45 |
$mform->addHelpButton('reset_start_date', 'startdate');
|
42 |
$mform->addElement('date_time_selector', 'reset_end_date', get_string('enddate'), ['optional' => true]);
|
| 46 |
$mform->addElement('date_time_selector', 'reset_end_date', get_string('enddate'), array('optional' => true));
|
43 |
$mform->addHelpButton('reset_end_date', 'enddate');
|
| 47 |
$mform->addHelpButton('reset_end_date', 'enddate');
|
44 |
$mform->addElement('static', 'generaldelete', get_string('delete'));
|
| 48 |
$mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
|
45 |
$mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
|
| 49 |
$mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
|
46 |
$mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
|
| Línea 50... |
Línea 47... |
| 50 |
$mform->addElement('checkbox', 'reset_comments', get_string('deleteallcomments', 'moodle'));
|
47 |
$mform->addElement('checkbox', 'reset_comments', get_string('deleteallcomments', 'moodle'));
|
| 51 |
$mform->addElement('checkbox', 'reset_completion', get_string('deletecompletiondata', 'completion'));
|
- |
|
| 52 |
$mform->addElement('checkbox', 'delete_blog_associations', get_string('deleteblogassociations', 'blog'));
|
48 |
$mform->addElement('checkbox', 'reset_completion', get_string('deletecompletiondata', 'completion'));
|
| 53 |
$mform->addHelpButton('delete_blog_associations', 'deleteblogassociations', 'blog');
|
49 |
$mform->addElement('checkbox', 'delete_blog_associations', get_string('deleteblogassociations', 'blog'));
|
| 54 |
$mform->addElement('checkbox', 'reset_competency_ratings', get_string('deletecompetencyratings', 'core_competency'));
|
50 |
$mform->addHelpButton('delete_blog_associations', 'deleteblogassociations', 'blog');
|
| - |
|
51 |
$mform->addElement('checkbox', 'reset_competency_ratings', get_string('deletecompetencyratings', 'core_competency'));
|
| - |
|
52 |
|
| - |
|
53 |
$mform->addElement('header', 'rolesheader', get_string('roles'));
|
| 55 |
|
54 |
$roles = get_assignable_roles(context_course::instance($COURSE->id));
|
| 56 |
$mform->addElement('header', 'rolesheader', get_string('roles'));
|
55 |
$roles[0] = get_string('noroles', 'role');
|
| 57 |
|
56 |
$roles = array_reverse($roles, true);
|
| 58 |
$roles = get_assignable_roles(context_course::instance($COURSE->id));
|
- |
|
| 59 |
$roles[0] = get_string('noroles', 'role');
|
57 |
$attributes = [
|
| 60 |
$roles = array_reverse($roles, true);
|
- |
|
| - |
|
58 |
'multiple' => 1,
|
| Línea 61... |
Línea 59... |
| 61 |
|
59 |
'size' => min(count($roles), 10),
|
| 62 |
$mform->addElement('select', 'unenrol_users', get_string('unenrolroleusers', 'enrol'), $roles, array('multiple' => 'multiple'));
|
- |
|
| - |
|
60 |
];
|
| 63 |
$mform->addElement('checkbox', 'reset_roles_overrides', get_string('deletecourseoverrides', 'role'));
|
61 |
$mform->addElement('select', 'unenrol_users', get_string('unenrolroleusers', 'enrol'), $roles, $attributes);
|
| 64 |
$mform->setAdvanced('reset_roles_overrides');
|
62 |
$mform->addElement('static', 'rolesdelete', get_string('delete'));
|
| 65 |
$mform->addElement('checkbox', 'reset_roles_local', get_string('deletelocalroles', 'role'));
|
63 |
$mform->addElement('checkbox', 'reset_roles_local', get_string('deletelocalroles', 'role'));
|
| 66 |
|
64 |
$mform->addElement('checkbox', 'reset_roles_overrides', get_string('deletecourseoverrides', 'role'));
|
| 67 |
|
65 |
|
| Línea 68... |
Línea -... |
| 68 |
$mform->addElement('header', 'gradebookheader', get_string('gradebook', 'grades'));
|
- |
|
| 69 |
|
66 |
$mform->addElement('header', 'gradebookheader', get_string('gradebook', 'grades'));
|
| 70 |
$mform->addElement('checkbox', 'reset_gradebook_items', get_string('removeallcourseitems', 'grades'));
|
- |
|
| - |
|
67 |
$mform->addElement('static', 'gradebookdelete', get_string('delete'));
|
| 71 |
$mform->addHelpButton('reset_gradebook_items', 'removeallcourseitems', 'grades');
|
68 |
$mform->addElement('checkbox', 'reset_gradebook_items', get_string('removeallcourseitems', 'grades'));
|
| 72 |
$mform->addElement('checkbox', 'reset_gradebook_grades', get_string('removeallcoursegrades', 'grades'));
|
69 |
$mform->addHelpButton('reset_gradebook_items', 'removeallcourseitems', 'grades');
|
| 73 |
$mform->addHelpButton('reset_gradebook_grades', 'removeallcoursegrades', 'grades');
|
70 |
$mform->addElement('checkbox', 'reset_gradebook_grades', get_string('removeallcoursegrades', 'grades'));
|
| 74 |
$mform->disabledIf('reset_gradebook_grades', 'reset_gradebook_items', 'checked');
|
- |
|
| 75 |
|
71 |
$mform->addHelpButton('reset_gradebook_grades', 'removeallcoursegrades', 'grades');
|
| 76 |
|
72 |
$mform->disabledIf('reset_gradebook_grades', 'reset_gradebook_items', 'checked');
|
| 77 |
$mform->addElement('header', 'groupheader', get_string('groups'));
|
73 |
|
| Línea 78... |
Línea 74... |
| 78 |
|
74 |
$mform->addElement('header', 'groupheader', get_string('groups'));
|
| 79 |
$mform->addElement('checkbox', 'reset_groups_remove', get_string('deleteallgroups', 'group'));
|
75 |
$mform->addElement('static', 'groupdelete', get_string('delete'));
|
| 80 |
$mform->addElement('checkbox', 'reset_groups_members', get_string('removegroupsmembers', 'group'));
|
76 |
$mform->addElement('checkbox', 'reset_groups_remove', get_string('deleteallgroups', 'group'));
|
| 81 |
$mform->disabledIf('reset_groups_members', 'reset_groups_remove', 'checked');
|
77 |
$mform->addElement('checkbox', 'reset_groups_members', get_string('removegroupsmembers', 'group'));
|
| 82 |
|
78 |
$mform->disabledIf('reset_groups_members', 'reset_groups_remove', 'checked');
|
| 83 |
$mform->addElement('checkbox', 'reset_groupings_remove', get_string('deleteallgroupings', 'group'));
|
79 |
$mform->addElement('checkbox', 'reset_groupings_remove', get_string('deleteallgroupings', 'group'));
|
| 84 |
$mform->addElement('checkbox', 'reset_groupings_members', get_string('removegroupingsmembers', 'group'));
|
80 |
$mform->addElement('checkbox', 'reset_groupings_members', get_string('removegroupingsmembers', 'group'));
|
| 85 |
$mform->disabledIf('reset_groupings_members', 'reset_groupings_remove', 'checked');
|
81 |
$mform->disabledIf('reset_groupings_members', 'reset_groupings_remove', 'checked');
|
| 86 |
|
82 |
|
| 87 |
$unsupported_mods = array();
|
83 |
$unsupportedmods = [];
|
| 88 |
if ($allmods = $DB->get_records('modules') ) {
|
84 |
if ($allmods = $DB->get_records('modules') ) {
|
| 89 |
foreach ($allmods as $mod) {
|
85 |
foreach ($allmods as $mod) {
|
| 90 |
$modname = $mod->name;
|
86 |
$modname = $mod->name;
|
| 91 |
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
87 |
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
| 92 |
$mod_reset_course_form_definition = $modname.'_reset_course_form_definition';
|
88 |
$modresetcourseformdefinition = $modname.'_reset_course_form_definition';
|
| 93 |
$mod_reset__userdata = $modname.'_reset_userdata';
|
89 |
$modresetuserdata = $modname.'_reset_userdata';
|
| 94 |
if (file_exists($modfile)) {
|
90 |
if (file_exists($modfile)) {
|
| 95 |
if (!$DB->count_records($modname, array('course'=>$COURSE->id))) {
|
91 |
if (!$DB->count_records($modname, ['course' => $COURSE->id])) {
|
| 96 |
continue; // Skip mods with no instances
|
92 |
continue; // Skip mods with no instances.
|
| 97 |
}
|
93 |
}
|
| 98 |
include_once($modfile);
|
94 |
include_once($modfile);
|
| 99 |
if (function_exists($mod_reset_course_form_definition)) {
|
95 |
if (function_exists($modresetcourseformdefinition)) {
|
| 100 |
$mod_reset_course_form_definition($mform);
|
96 |
$modresetcourseformdefinition($mform);
|
| 101 |
} else if (!function_exists($mod_reset__userdata)) {
|
97 |
} else if (!function_exists($modresetuserdata)) {
|
| 102 |
$unsupported_mods[] = $mod;
|
98 |
$unsupportedmods[] = $mod;
|
| - |
|
99 |
}
|
| 103 |
}
|
100 |
} else {
|
| 104 |
} else {
|
101 |
debugging('Missing lib.php in '.$modname.' module');
|
| - |
|
102 |
}
|
| - |
|
103 |
}
|
| - |
|
104 |
}
|
| - |
|
105 |
// Mention unsupported mods.
|
| - |
|
106 |
if (!empty($unsupportedmods)) {
|
| - |
|
107 |
$mform->addElement('header', 'unsupportedheader', get_string('resetnotimplemented'));
|
| 105 |
debugging('Missing lib.php in '.$modname.' module');
|
108 |
$mform->addElement('static', 'unsupportedinfo', get_string('resetnotimplementedinfo'));
|
| 106 |
}
|
109 |
foreach ($unsupportedmods as $mod) {
|
| 107 |
}
|
110 |
$mform->addElement('static', 'unsup'.$mod->name, get_string('modulenameplural', $mod->name));
|
| Línea 108... |
Línea 111... |
| 108 |
}
|
111 |
}
|
| 109 |
// mention unsupported mods
|
112 |
}
|
| Línea 110... |
Línea 113... |
| 110 |
if (!empty($unsupported_mods)) {
|
113 |
|
| 111 |
$mform->addElement('header', 'unsupportedheader', get_string('resetnotimplemented'));
|
114 |
$elements = $mform->_elements;
|
| - |
|
115 |
foreach ($elements as $element) {
|
| - |
|
116 |
if (is_a($element, 'HTML_QuickForm_header')) {
|
| 112 |
foreach($unsupported_mods as $mod) {
|
117 |
$mform->setExpanded($element->getName());
|
| - |
|
118 |
}
|
| - |
|
119 |
}
|
| 113 |
$mform->addElement('static', 'unsup'.$mod->name, get_string('modulenameplural', $mod->name));
|
120 |
|
| - |
|
121 |
$mform->addElement('hidden', 'id', $COURSE->id);
|
| 114 |
$mform->setAdvanced('unsup'.$mod->name);
|
122 |
$mform->setType('id', PARAM_INT);
|
| - |
|
123 |
|
| - |
|
124 |
$buttonarray = [];
|
| - |
|
125 |
$buttonarray[] = $mform->createElement(
|
| - |
|
126 |
'submit',
|
| - |
|
127 |
'selectdefault',
|
| - |
|
128 |
get_string('selectdefault'),
|
| - |
|
129 |
null,
|
| 115 |
}
|
130 |
null,
|
| - |
|
131 |
['customclassoverride' => 'btn-secondary'],
|
| - |
|
132 |
);
|
| - |
|
133 |
$buttonarray[] = $mform->createElement(
|
| - |
|
134 |
'submit',
|
| - |
|
135 |
'deselectall',
|
| - |
|
136 |
get_string('deselectall'),
|
| - |
|
137 |
null,
|
| - |
|
138 |
null,
|
| - |
|
139 |
['customclassoverride' => 'btn-secondary'],
|
| - |
|
140 |
);
|
| - |
|
141 |
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
|
| - |
|
142 |
|
| - |
|
143 |
$mform->addElement(
|
| - |
|
144 |
'submit',
|
| - |
|
145 |
'submitbutton',
|
| 116 |
}
|
146 |
get_string('resetcourse'),
|
| 117 |
|
147 |
[
|
| Línea -... |
Línea 148... |
| - |
|
148 |
'data-action' => 'resetcourse',
|
| - |
|
149 |
'data-courseid' => $COURSE->id,
|
| - |
|
150 |
'data-coursename' => $COURSE->fullname,
|
| 118 |
$mform->addElement('hidden', 'id', $COURSE->id);
|
151 |
],
|
| 119 |
$mform->setType('id', PARAM_INT);
|
152 |
null,
|
| Línea 120... |
Línea 153... |
| 120 |
|
153 |
['customclassoverride' => 'btn-danger'],
|
| Línea -... |
Línea 154... |
| - |
|
154 |
);
|
| - |
|
155 |
$mform->set_sticky_footer('submitbutton');
|
| - |
|
156 |
|
| 121 |
$buttonarray = array();
|
157 |
$mform->closeHeaderBefore('buttonar');
|
| - |
|
158 |
}
|
| - |
|
159 |
|
| Línea 122... |
Línea 160... |
| 122 |
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('resetcourse'));
|
160 |
/**
|
| 123 |
$buttonarray[] = &$mform->createElement('submit', 'selectdefault', get_string('selectdefault'));
|
161 |
* Method to load default values for the reset course form.
|
| 124 |
$buttonarray[] = &$mform->createElement('submit', 'deselectall', get_string('deselectall'));
|
162 |
*/
|
| 125 |
$buttonarray[] = &$mform->createElement('cancel');
|
163 |
public function load_defaults() {
|
| Línea 126... |
Línea 164... |
| 126 |
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
164 |
global $CFG, $COURSE, $DB;
|
| 127 |
$mform->closeHeaderBefore('buttonar');
|
165 |
|
| 128 |
}
|
166 |
$mform = $this->_form;
|
| 129 |
|
167 |
|
| 130 |
function load_defaults() {
|
168 |
$defaults = [
|
| 131 |
global $CFG, $COURSE, $DB;
|
169 |
'reset_events' => 1,
|
| 132 |
|
170 |
'reset_roles_local' => 1,
|
| 133 |
$mform =& $this->_form;
|
171 |
'reset_gradebook_grades' => 1,
|
| 134 |
|
172 |
'reset_notes' => 1,
|
| 135 |
$defaults = array ('reset_events'=>1, 'reset_roles_local'=>1, 'reset_gradebook_grades'=>1, 'reset_notes'=>1);
|
173 |
];
|
| 136 |
|
174 |
|
| 137 |
// Set student as default in unenrol user list, if role with student archetype exist.
|
175 |
// Set student as default in unenrol user list, if role with student archetype exist.
|
| 138 |
if ($studentrole = get_archetype_roles('student')) {
|
176 |
if ($studentrole = get_archetype_roles('student')) {
|
| 139 |
$defaults['unenrol_users'] = array_keys($studentrole);
|
177 |
$defaults['unenrol_users'] = array_keys($studentrole);
|
| 140 |
}
|
178 |
}
|
| Línea 141... |
Línea 179... |
| 141 |
|
179 |
|
| 142 |
if ($allmods = $DB->get_records('modules') ) {
|
180 |
if ($allmods = $DB->get_records('modules') ) {
|
| 143 |
foreach ($allmods as $mod) {
|
181 |
foreach ($allmods as $mod) {
|
| 144 |
$modname = $mod->name;
|
182 |
$modname = $mod->name;
|
| Línea 145... |
Línea 183... |
| 145 |
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
183 |
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
| Línea 166... |
Línea 204... |
| 166 |
* @param array $data
|
204 |
* @param array $data
|
| 167 |
* @param array $files
|
205 |
* @param array $files
|
| 168 |
* @return array the errors that were found
|
206 |
* @return array the errors that were found
|
| 169 |
*/
|
207 |
*/
|
| 170 |
public function validation($data, $files) {
|
208 |
public function validation($data, $files) {
|
| 171 |
global $DB;
|
- |
|
| 172 |
|
- |
|
| 173 |
$course = get_course($data['id']);
|
209 |
$course = get_course($data['id']);
|
| Línea 174... |
Línea 210... |
| 174 |
|
210 |
|
| Línea 175... |
Línea 211... |
| 175 |
$errors = parent::validation($data, $files);
|
211 |
$errors = parent::validation($data, $files);
|
| Línea 184... |
Línea 220... |
| 184 |
if ($data['reset_end_date'] != 0) {
|
220 |
if ($data['reset_end_date'] != 0) {
|
| 185 |
// End date set by the user has preference.
|
221 |
// End date set by the user has preference.
|
| 186 |
$coursedata['enddate'] = $data['reset_end_date'];
|
222 |
$coursedata['enddate'] = $data['reset_end_date'];
|
| 187 |
} else if ($data['reset_start_date'] > 0 && $course->enddate != 0) {
|
223 |
} else if ($data['reset_start_date'] > 0 && $course->enddate != 0) {
|
| 188 |
// Otherwise, if the current course enddate is set, reset_course_userdata will add the start date time shift to it.
|
224 |
// Otherwise, if the current course enddate is set, reset_course_userdata will add the start date time shift to it.
|
| 189 |
$timeshift = $data['reset_start_date'] - usergetmidnight($course->startdate);
|
225 |
$timeshift = $data['reset_start_date'] - $course->startdate;
|
| 190 |
$coursedata['enddate'] = $course->enddate + $timeshift;
|
226 |
$coursedata['enddate'] = $course->enddate + $timeshift;
|
| 191 |
} else {
|
227 |
} else {
|
| 192 |
$coursedata['enddate'] = $course->enddate;
|
228 |
$coursedata['enddate'] = $course->enddate;
|
| 193 |
}
|
229 |
}
|