2009-11-04 08:11:02 +00:00
|
|
|
<?php
|
2014-09-17 15:38:59 +02:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides the course_reset_form class.
|
|
|
|
*
|
|
|
|
* @package core
|
|
|
|
* @copyright 2007 Petr Skoda
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
2010-05-13 02:02:05 +00:00
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
require_once $CFG->libdir.'/formslib.php';
|
2016-09-01 13:29:19 +08:00
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
2007-11-29 14:43:04 +00:00
|
|
|
|
2014-09-17 15:38:59 +02:00
|
|
|
/**
|
|
|
|
* Defines the course reset settings form.
|
|
|
|
*
|
|
|
|
* @copyright 2007 Petr Skoda
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2007-11-29 14:43:04 +00:00
|
|
|
class course_reset_form extends moodleform {
|
|
|
|
function definition (){
|
2008-06-02 08:13:24 +00:00
|
|
|
global $CFG, $COURSE, $DB;
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
$mform =& $this->_form;
|
|
|
|
|
|
|
|
$mform->addElement('header', 'generalheader', get_string('general'));
|
|
|
|
|
2017-12-14 19:48:31 -05:00
|
|
|
$mform->addElement('date_time_selector', 'reset_start_date', get_string('startdate'), array('optional' => true));
|
2010-05-06 18:32:03 +00:00
|
|
|
$mform->addHelpButton('reset_start_date', 'startdate');
|
2017-12-14 19:48:31 -05:00
|
|
|
$mform->addElement('date_time_selector', 'reset_end_date', get_string('enddate'), array('optional' => true));
|
2016-09-01 13:29:19 +08:00
|
|
|
$mform->addHelpButton('reset_end_date', 'enddate');
|
2007-11-29 14:43:04 +00:00
|
|
|
$mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
|
|
|
|
$mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
|
2010-09-16 07:38:52 +00:00
|
|
|
$mform->addElement('checkbox', 'reset_comments', get_string('deleteallcomments', 'moodle'));
|
2012-08-10 14:37:19 +01:00
|
|
|
$mform->addElement('checkbox', 'reset_completion', get_string('deletecompletiondata', 'completion'));
|
2009-10-30 07:27:19 +00:00
|
|
|
$mform->addElement('checkbox', 'delete_blog_associations', get_string('deleteblogassociations', 'blog'));
|
MDL-21695 Replaced help/blog
AMOS BEGIN
HLP blog/deleteblogassociations.html,[deleteblogassociations_help,core_blog]
HLP blog/description.html,[description_help,core_blog]
HLP blog/filtertags.html,[filtertags_help,core_blog]
HLP blog/name.html,[name_help,core_blog]
HLP blog/publish_state.html,[publishto_help,core_blog]
HLP blog/tags.html,[autotags_help,core_blog]
HLP blog/url.html,[url_help,core_blog]
AMOS END
2010-07-19 18:31:13 +00:00
|
|
|
$mform->addHelpButton('delete_blog_associations', 'deleteblogassociations', 'blog');
|
2016-04-11 18:21:11 +08:00
|
|
|
$mform->addElement('checkbox', 'reset_competency_ratings', get_string('deletecompetencyratings', 'core_competency'));
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
$mform->addElement('header', 'rolesheader', get_string('roles'));
|
|
|
|
|
2012-07-23 15:59:04 +08:00
|
|
|
$roles = get_assignable_roles(context_course::instance($COURSE->id));
|
2012-03-16 10:55:30 +01:00
|
|
|
$roles[0] = get_string('noroles', 'role');
|
|
|
|
$roles = array_reverse($roles, true);
|
|
|
|
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
$mform->addElement('select', 'unenrol_users', get_string('unenrolroleusers', 'enrol'), $roles, array('multiple' => 'multiple'));
|
2007-11-29 14:43:04 +00:00
|
|
|
$mform->addElement('checkbox', 'reset_roles_overrides', get_string('deletecourseoverrides', 'role'));
|
|
|
|
$mform->setAdvanced('reset_roles_overrides');
|
|
|
|
$mform->addElement('checkbox', 'reset_roles_local', get_string('deletelocalroles', 'role'));
|
|
|
|
|
|
|
|
|
|
|
|
$mform->addElement('header', 'gradebookheader', get_string('gradebook', 'grades'));
|
|
|
|
|
|
|
|
$mform->addElement('checkbox', 'reset_gradebook_items', get_string('removeallcourseitems', 'grades'));
|
2014-12-11 13:58:07 +08:00
|
|
|
$mform->addHelpButton('reset_gradebook_items', 'removeallcourseitems', 'grades');
|
2007-11-29 14:43:04 +00:00
|
|
|
$mform->addElement('checkbox', 'reset_gradebook_grades', get_string('removeallcoursegrades', 'grades'));
|
2014-12-11 13:58:07 +08:00
|
|
|
$mform->addHelpButton('reset_gradebook_grades', 'removeallcoursegrades', 'grades');
|
2007-11-29 14:43:04 +00:00
|
|
|
$mform->disabledIf('reset_gradebook_grades', 'reset_gradebook_items', 'checked');
|
|
|
|
|
|
|
|
|
|
|
|
$mform->addElement('header', 'groupheader', get_string('groups'));
|
|
|
|
|
|
|
|
$mform->addElement('checkbox', 'reset_groups_remove', get_string('deleteallgroups', 'group'));
|
|
|
|
$mform->addElement('checkbox', 'reset_groups_members', get_string('removegroupsmembers', 'group'));
|
|
|
|
$mform->disabledIf('reset_groups_members', 'reset_groups_remove', 'checked');
|
|
|
|
|
2010-04-07 07:37:12 +00:00
|
|
|
$mform->addElement('checkbox', 'reset_groupings_remove', get_string('deleteallgroupings', 'group'));
|
|
|
|
$mform->addElement('checkbox', 'reset_groupings_members', get_string('removegroupingsmembers', 'group'));
|
|
|
|
$mform->disabledIf('reset_groupings_members', 'reset_groupings_remove', 'checked');
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
$unsupported_mods = array();
|
2008-06-02 08:13:24 +00:00
|
|
|
if ($allmods = $DB->get_records('modules') ) {
|
2007-11-29 14:43:04 +00:00
|
|
|
foreach ($allmods as $mod) {
|
|
|
|
$modname = $mod->name;
|
|
|
|
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
|
|
|
$mod_reset_course_form_definition = $modname.'_reset_course_form_definition';
|
|
|
|
$mod_reset__userdata = $modname.'_reset_userdata';
|
|
|
|
if (file_exists($modfile)) {
|
2012-08-20 14:33:01 +08:00
|
|
|
if (!$DB->count_records($modname, array('course'=>$COURSE->id))) {
|
|
|
|
continue; // Skip mods with no instances
|
|
|
|
}
|
2007-11-29 14:43:04 +00:00
|
|
|
include_once($modfile);
|
|
|
|
if (function_exists($mod_reset_course_form_definition)) {
|
|
|
|
$mod_reset_course_form_definition($mform);
|
|
|
|
} else if (!function_exists($mod_reset__userdata)) {
|
|
|
|
$unsupported_mods[] = $mod;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
debugging('Missing lib.php in '.$modname.' module');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// mention unsupported mods
|
|
|
|
if (!empty($unsupported_mods)) {
|
|
|
|
$mform->addElement('header', 'unsupportedheader', get_string('resetnotimplemented'));
|
|
|
|
foreach($unsupported_mods as $mod) {
|
|
|
|
$mform->addElement('static', 'unsup'.$mod->name, get_string('modulenameplural', $mod->name));
|
|
|
|
$mform->setAdvanced('unsup'.$mod->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('hidden', 'id', $COURSE->id);
|
2009-09-26 17:07:08 +00:00
|
|
|
$mform->setType('id', PARAM_INT);
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
$buttonarray = array();
|
|
|
|
$buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('resetcourse'));
|
|
|
|
$buttonarray[] = &$mform->createElement('submit', 'selectdefault', get_string('selectdefault'));
|
|
|
|
$buttonarray[] = &$mform->createElement('submit', 'deselectall', get_string('deselectall'));
|
|
|
|
$buttonarray[] = &$mform->createElement('cancel');
|
|
|
|
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
|
|
|
$mform->closeHeaderBefore('buttonar');
|
|
|
|
}
|
|
|
|
|
|
|
|
function load_defaults() {
|
2008-06-02 08:13:24 +00:00
|
|
|
global $CFG, $COURSE, $DB;
|
2007-11-29 14:43:04 +00:00
|
|
|
|
|
|
|
$mform =& $this->_form;
|
|
|
|
|
2014-06-10 13:48:34 +08:00
|
|
|
$defaults = array ('reset_events'=>1, 'reset_roles_local'=>1, 'reset_gradebook_grades'=>1, 'reset_notes'=>1);
|
2007-11-29 14:43:04 +00:00
|
|
|
|
2013-01-18 10:10:57 +08:00
|
|
|
// Set student as default in unenrol user list, if role with student archetype exist.
|
|
|
|
if ($studentrole = get_archetype_roles('student')) {
|
|
|
|
$defaults['unenrol_users'] = array_keys($studentrole);
|
|
|
|
}
|
|
|
|
|
2008-06-02 08:13:24 +00:00
|
|
|
if ($allmods = $DB->get_records('modules') ) {
|
2007-11-29 14:43:04 +00:00
|
|
|
foreach ($allmods as $mod) {
|
|
|
|
$modname = $mod->name;
|
|
|
|
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
|
|
|
$mod_reset_course_form_defaults = $modname.'_reset_course_form_defaults';
|
|
|
|
if (file_exists($modfile)) {
|
|
|
|
@include_once($modfile);
|
|
|
|
if (function_exists($mod_reset_course_form_defaults)) {
|
2009-04-05 19:32:33 +00:00
|
|
|
if ($moddefs = $mod_reset_course_form_defaults($COURSE)) {
|
|
|
|
$defaults = $defaults + $moddefs;
|
|
|
|
}
|
2007-11-29 14:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($defaults as $element=>$default) {
|
|
|
|
$mform->setDefault($element, $default);
|
|
|
|
}
|
|
|
|
}
|
2016-09-01 13:29:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validation.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param array $files
|
|
|
|
* @return array the errors that were found
|
|
|
|
*/
|
|
|
|
public function validation($data, $files) {
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$course = get_course($data['id']);
|
|
|
|
|
|
|
|
$errors = parent::validation($data, $files);
|
|
|
|
|
|
|
|
// We check the values that would be used as start and end.
|
|
|
|
if ($data['reset_start_date'] != 0) {
|
|
|
|
$coursedata['startdate'] = $data['reset_start_date'];
|
|
|
|
} else {
|
|
|
|
$coursedata['startdate'] = $course->startdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($data['reset_end_date'] != 0) {
|
|
|
|
// End date set by the user has preference.
|
|
|
|
$coursedata['enddate'] = $data['reset_end_date'];
|
2016-10-06 10:07:22 +08:00
|
|
|
} else if ($data['reset_start_date'] > 0 && $course->enddate != 0) {
|
|
|
|
// Otherwise, if the current course enddate is set, reset_course_userdata will add the start date time shift to it.
|
2016-09-01 13:29:19 +08:00
|
|
|
$timeshift = $data['reset_start_date'] - usergetmidnight($course->startdate);
|
|
|
|
$coursedata['enddate'] = $course->enddate + $timeshift;
|
|
|
|
} else {
|
|
|
|
$coursedata['enddate'] = $course->enddate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($errorcode = course_validate_dates($coursedata)) {
|
|
|
|
$errors['reset_end_date'] = get_string($errorcode, 'error');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
2007-11-29 14:43:04 +00:00
|
|
|
}
|