mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-81872 course: Fix coding style
This commit is contained in:
parent
d32844ce29
commit
c088bec544
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -22,9 +21,9 @@
|
||||
* specific data. Each module must be modified to take advantage of this new feature.
|
||||
* The feature will also reset the start date of the course if necessary.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright Mark Flach and moodle.com
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @package course
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require('../config.php');
|
||||
@ -35,11 +34,11 @@ require_once($CFG->dirroot . '/backup/util/helper/backup_helper.class.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id'=>$id))) {
|
||||
throw new \moodle_exception("invalidcourseid");
|
||||
if (!$course = $DB->get_record('course', ['id' => $id])) {
|
||||
throw new \moodle_exception('invalidcourseid');
|
||||
}
|
||||
|
||||
$PAGE->set_url('/course/reset.php', array('id'=>$id));
|
||||
$PAGE->set_url('/course/reset.php', ['id' => $id]);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
|
||||
require_login($course);
|
||||
@ -56,17 +55,17 @@ $PAGE->set_secondary_active_tab('coursereuse');
|
||||
$mform = new course_reset_form();
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($CFG->wwwroot.'/course/view.php?id='.$id);
|
||||
redirect($CFG->wwwroot . '/course/view.php?id='.$id);
|
||||
|
||||
} else if ($data = $mform->get_data()) { // no magic quotes
|
||||
} else if ($data = $mform->get_data()) { // No magic quotes.
|
||||
|
||||
if (isset($data->selectdefault)) {
|
||||
$_POST = array();
|
||||
$_POST = [];
|
||||
$mform = new course_reset_form();
|
||||
$mform->load_defaults();
|
||||
|
||||
} else if (isset($data->deselectall)) {
|
||||
$_POST = array();
|
||||
$_POST = [];
|
||||
$mform = new course_reset_form();
|
||||
|
||||
} else {
|
||||
@ -77,9 +76,9 @@ if ($mform->is_cancelled()) {
|
||||
$data->reset_end_date_old = $course->enddate;
|
||||
$status = reset_course_userdata($data);
|
||||
|
||||
$data = array();
|
||||
$data = [];
|
||||
foreach ($status as $item) {
|
||||
$line = array();
|
||||
$line = [];
|
||||
$line[] = $item['component'];
|
||||
$line[] = $item['item'];
|
||||
$line[] = ($item['error'] === false) ? get_string('statusok') : '<div class="notifyproblem">'.$item['error'].'</div>';
|
||||
@ -87,14 +86,14 @@ if ($mform->is_cancelled()) {
|
||||
}
|
||||
|
||||
$table = new html_table();
|
||||
$table->head = array(get_string('resetcomponent'), get_string('resettask'), get_string('resetstatus'));
|
||||
$table->size = array('20%', '40%', '40%');
|
||||
$table->align = array('left', 'left', 'left');
|
||||
$table->head = [get_string('resetcomponent'), get_string('resettask'), get_string('resetstatus')];
|
||||
$table->size = ['20%', '40%', '40%'];
|
||||
$table->align = ['left', 'left', 'left'];
|
||||
$table->width = '80%';
|
||||
$table->data = $data;
|
||||
echo html_writer::table($table);
|
||||
|
||||
echo $OUTPUT->continue_button('view.php?id='.$course->id); // Back to course page
|
||||
echo $OUTPUT->continue_button('view.php?id=' . $course->id); // Back to course page.
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
}
|
||||
|
@ -14,36 +14,32 @@
|
||||
// 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();
|
||||
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
require_once($CFG->dirroot . '/course/lib.php');
|
||||
|
||||
/**
|
||||
* Defines the course reset settings form.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2007 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class course_reset_form extends moodleform {
|
||||
function definition(){
|
||||
|
||||
/**
|
||||
* Form definition.
|
||||
*/
|
||||
public function definition() {
|
||||
global $CFG, $COURSE, $DB;
|
||||
|
||||
$mform =& $this->_form;
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('header', 'generalheader', get_string('general'));
|
||||
|
||||
$mform->addElement('date_time_selector', 'reset_start_date', get_string('startdate'), array('optional' => true));
|
||||
$mform->addElement('date_time_selector', 'reset_start_date', get_string('startdate'), ['optional' => true]);
|
||||
$mform->addHelpButton('reset_start_date', 'startdate');
|
||||
$mform->addElement('date_time_selector', 'reset_end_date', get_string('enddate'), array('optional' => true));
|
||||
$mform->addElement('date_time_selector', 'reset_end_date', get_string('enddate'), ['optional' => true]);
|
||||
$mform->addHelpButton('reset_end_date', 'enddate');
|
||||
$mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
|
||||
$mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
|
||||
@ -54,62 +50,55 @@ class course_reset_form extends moodleform {
|
||||
$mform->addElement('checkbox', 'reset_competency_ratings', get_string('deletecompetencyratings', 'core_competency'));
|
||||
|
||||
$mform->addElement('header', 'rolesheader', get_string('roles'));
|
||||
|
||||
$roles = get_assignable_roles(context_course::instance($COURSE->id));
|
||||
$roles[0] = get_string('noroles', 'role');
|
||||
$roles = array_reverse($roles, true);
|
||||
|
||||
$mform->addElement('select', 'unenrol_users', get_string('unenrolroleusers', 'enrol'), $roles, array('multiple' => 'multiple'));
|
||||
$mform->addElement('select', 'unenrol_users', get_string('unenrolroleusers', 'enrol'), $roles, ['multiple' => 'multiple']);
|
||||
$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'));
|
||||
$mform->addHelpButton('reset_gradebook_items', 'removeallcourseitems', 'grades');
|
||||
$mform->addElement('checkbox', 'reset_gradebook_grades', get_string('removeallcoursegrades', 'grades'));
|
||||
$mform->addHelpButton('reset_gradebook_grades', 'removeallcoursegrades', 'grades');
|
||||
$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');
|
||||
|
||||
$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');
|
||||
|
||||
$unsupported_mods = array();
|
||||
$unsupportedmods = [];
|
||||
if ($allmods = $DB->get_records('modules') ) {
|
||||
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';
|
||||
$modresetcourseformdefinition = $modname.'_reset_course_form_definition';
|
||||
$modresetuserdata = $modname.'_reset_userdata';
|
||||
if (file_exists($modfile)) {
|
||||
if (!$DB->count_records($modname, array('course'=>$COURSE->id))) {
|
||||
continue; // Skip mods with no instances
|
||||
if (!$DB->count_records($modname, ['course' => $COURSE->id])) {
|
||||
continue; // Skip mods with no instances.
|
||||
}
|
||||
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;
|
||||
if (function_exists($modresetcourseformdefinition)) {
|
||||
$modresetcourseformdefinition($mform);
|
||||
} else if (!function_exists($modresetuserdata)) {
|
||||
$unsupportedmods[] = $mod;
|
||||
}
|
||||
} else {
|
||||
debugging('Missing lib.php in '.$modname.' module');
|
||||
}
|
||||
}
|
||||
}
|
||||
// mention unsupported mods
|
||||
if (!empty($unsupported_mods)) {
|
||||
// Mention unsupported mods.
|
||||
if (!empty($unsupportedmods)) {
|
||||
$mform->addElement('header', 'unsupportedheader', get_string('resetnotimplemented'));
|
||||
foreach($unsupported_mods as $mod) {
|
||||
foreach ($unsupportedmods as $mod) {
|
||||
$mform->addElement('static', 'unsup'.$mod->name, get_string('modulenameplural', $mod->name));
|
||||
$mform->setAdvanced('unsup'.$mod->name);
|
||||
}
|
||||
@ -118,21 +107,29 @@ class course_reset_form extends moodleform {
|
||||
$mform->addElement('hidden', 'id', $COURSE->id);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$buttonarray = array();
|
||||
$buttonarray = [];
|
||||
$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->addGroup($buttonarray, 'buttonar', '', [' '], false);
|
||||
$mform->closeHeaderBefore('buttonar');
|
||||
}
|
||||
|
||||
function load_defaults() {
|
||||
/**
|
||||
* Method to load default values for the reset course form.
|
||||
*/
|
||||
public function load_defaults() {
|
||||
global $CFG, $COURSE, $DB;
|
||||
|
||||
$mform =& $this->_form;
|
||||
$mform = $this->_form;
|
||||
|
||||
$defaults = array ('reset_events'=>1, 'reset_roles_local'=>1, 'reset_gradebook_grades'=>1, 'reset_notes'=>1);
|
||||
$defaults = [
|
||||
'reset_events' => 1,
|
||||
'reset_roles_local' => 1,
|
||||
'reset_gradebook_grades' => 1,
|
||||
'reset_notes' => 1,
|
||||
];
|
||||
|
||||
// Set student as default in unenrol user list, if role with student archetype exist.
|
||||
if ($studentrole = get_archetype_roles('student')) {
|
||||
@ -143,11 +140,11 @@ class course_reset_form extends moodleform {
|
||||
foreach ($allmods as $mod) {
|
||||
$modname = $mod->name;
|
||||
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
||||
$mod_reset_course_form_defaults = $modname.'_reset_course_form_defaults';
|
||||
$modresetcourseformdefaults = $modname.'_reset_course_form_defaults';
|
||||
if (file_exists($modfile)) {
|
||||
@include_once($modfile);
|
||||
if (function_exists($mod_reset_course_form_defaults)) {
|
||||
if ($moddefs = $mod_reset_course_form_defaults($COURSE)) {
|
||||
if (function_exists($modresetcourseformdefaults)) {
|
||||
if ($moddefs = $modresetcourseformdefaults($COURSE)) {
|
||||
$defaults = $defaults + $moddefs;
|
||||
}
|
||||
}
|
||||
@ -155,7 +152,7 @@ class course_reset_form extends moodleform {
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($defaults as $element=>$default) {
|
||||
foreach ($defaults as $element => $default) {
|
||||
$mform->setDefault($element, $default);
|
||||
}
|
||||
}
|
||||
@ -168,8 +165,6 @@ class course_reset_form extends moodleform {
|
||||
* @return array the errors that were found
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
global $DB;
|
||||
|
||||
$course = get_course($data['id']);
|
||||
|
||||
$errors = parent::validation($data, $files);
|
||||
|
Loading…
x
Reference in New Issue
Block a user