From 6f6c9e5c6a8269d3906b9070231a736a6e974f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 26 Aug 2012 16:37:49 +0200 Subject: [PATCH 1/2] MDL-35072 coding style cleanup in enrol_manual --- enrol/manual/ajax.php | 10 +++----- enrol/manual/bulkchangeforms.php | 6 ++--- enrol/manual/db/access.php | 6 ++++- enrol/manual/db/install.php | 4 +-- enrol/manual/edit.php | 8 +++--- enrol/manual/edit_form.php | 6 ++--- enrol/manual/editenrolment.php | 38 ++++++++++++----------------- enrol/manual/editenrolment_form.php | 6 ++--- enrol/manual/externallib.php | 33 ++++++++++++------------- enrol/manual/lib.php | 24 +++++++++--------- enrol/manual/locallib.php | 26 +++++++++----------- enrol/manual/manage.php | 11 ++++----- enrol/manual/settings.php | 5 +--- enrol/manual/unenrolself.php | 8 +++--- enrol/manual/version.php | 3 +-- 15 files changed, 84 insertions(+), 110 deletions(-) diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index 140b4cd8dfe..556170e94b5 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -20,8 +20,7 @@ * The general idea behind this file is that any errors should throw exceptions * which will be returned and acted upon by the calling AJAX script. * - * @package enrol - * @subpackage manual + * @package enrol_manual * @copyright 2010 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -32,8 +31,7 @@ require('../../config.php'); require_once($CFG->dirroot.'/enrol/locallib.php'); require_once($CFG->dirroot.'/group/lib.php'); -// Must have the sesskey -$id = required_param('id', PARAM_INT); // course id +$id = required_param('id', PARAM_INT); // Course id. $action = required_param('action', PARAM_ALPHANUMEXT); $PAGE->set_url(new moodle_url('/enrol/ajax.php', array('id'=>$id, 'action'=>$action))); @@ -49,7 +47,7 @@ require_login($course); require_capability('moodle/course:enrolreview', $context); require_sesskey(); -echo $OUTPUT->header(); // send headers +echo $OUTPUT->header(); // Send headers. $manager = new course_enrolment_manager($PAGE, $course); @@ -135,4 +133,4 @@ switch ($action) { throw new enrol_ajax_exception('unknowajaxaction'); } -echo json_encode($outcome); \ No newline at end of file +echo json_encode($outcome); diff --git a/enrol/manual/bulkchangeforms.php b/enrol/manual/bulkchangeforms.php index 8ee73008cdc..05980e6f60c 100644 --- a/enrol/manual/bulkchangeforms.php +++ b/enrol/manual/bulkchangeforms.php @@ -1,5 +1,4 @@ dirroot/enrol/bulkchange_forms.php"); /** - * The form to collect required information when bulk editing users enrolments + * The form to collect required information when bulk editing users enrolments. * * @copyright 2011 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/enrol/manual/db/access.php b/enrol/manual/db/access.php index 561ef29a39d..5f14032f9e2 100644 --- a/enrol/manual/db/access.php +++ b/enrol/manual/db/access.php @@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die(); $capabilities = array( + /* Add, edit or remove manual enrol instance. */ 'enrol/manual:config' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, @@ -34,6 +35,7 @@ $capabilities = array( ) ), + /* Enrol anybody. */ 'enrol/manual:enrol' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, @@ -43,6 +45,7 @@ $capabilities = array( ) ), + /* Manage enrolments of users. */ 'enrol/manual:manage' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, @@ -52,6 +55,7 @@ $capabilities = array( ) ), + /* Unenrol anybody (including self) - watch out for data loss. */ 'enrol/manual:unenrol' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, @@ -61,6 +65,7 @@ $capabilities = array( ) ), + /* Unenrol self - watch out for data loss. */ 'enrol/manual:unenrolself' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, @@ -69,4 +74,3 @@ $capabilities = array( ), ); - diff --git a/enrol/manual/db/install.php b/enrol/manual/db/install.php index 3d995428812..99584351821 100644 --- a/enrol/manual/db/install.php +++ b/enrol/manual/db/install.php @@ -1,5 +1,4 @@ get_records('enrol', array('courseid'=>$course->id, 'enrol'=>'manual'), 'id ASC')) { $instance = array_shift($instances); if ($instances) { - // oh - we allow only one instance per course!! + // Oh - we allow only one instance per course!! foreach ($instances as $del) { $plugin->delete_instance($del); } } } else { require_capability('moodle/course:enrolconfig', $context); - // no instance yet, we have to add new instance + // No instance yet, we have to add new instance. navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id))); $instance = new stdClass(); $instance->id = null; diff --git a/enrol/manual/edit_form.php b/enrol/manual/edit_form.php index 7ff2792d34b..eb210991167 100644 --- a/enrol/manual/edit_form.php +++ b/enrol/manual/edit_form.php @@ -1,5 +1,4 @@ set_data($instance); } -} \ No newline at end of file +} diff --git a/enrol/manual/editenrolment.php b/enrol/manual/editenrolment.php index 2d8a7003751..b0f0b2fb1db 100644 --- a/enrol/manual/editenrolment.php +++ b/enrol/manual/editenrolment.php @@ -20,46 +20,42 @@ * This page allows the current user to edit a manual user enrolment. * It is not compatible with the frontpage. * - * @package enrol - * @subpackage manual + * @package enrol_manual * @copyright 2011 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require('../../config.php'); require_once("$CFG->dirroot/enrol/locallib.php"); -require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment manager table +require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment manager table. require_once("$CFG->dirroot/enrol/manual/editenrolment_form.php"); -$ueid = required_param('ue', PARAM_INT); // user enrolment id +$ueid = required_param('ue', PARAM_INT); // User enrolment id. $filter = optional_param('ifilter', 0, PARAM_INT); -// Get the user enrolment object -$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST); -// Get the user for whom the enrolment is -$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST); -// Get the course the enrolment is to -list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); -$sql = "SELECT c.* $ctxsql +// Get the user enrolment object. +$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST); +// Get the user for whom the enrolment is. +$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST); +// Get the course the enrolment is to. +$sql = "SELECT c.* FROM {course} c LEFT JOIN {enrol} e ON e.courseid = c.id - $ctxjoin WHERE e.id = :enrolid"; $params = array('enrolid' => $ue->enrolid); $course = $DB->get_record_sql($sql, $params, MUST_EXIST); -context_instance_preload($course); -// Make sure its not the front page course +// Make sure its not the front page course. if ($course->id == SITEID) { redirect(new moodle_url('/')); } -// Obviously +// Obviously. require_login($course); -// Make sure the user can manage manual enrolments for this course +// Make sure the user can manage manual enrolments for this course. require_capability("enrol/manual:manage", context_course::instance($course->id, MUST_EXIST)); -// Get the enrolment manager for this course +// Get the enrolment manager for this course. $manager = new course_enrolment_manager($PAGE, $course, $filter); // Get an enrolment users table object. Doign this will automatically retrieve the the URL params // relating to table the user was viewing before coming here, and allows us to return the user to the @@ -70,7 +66,7 @@ $table = new course_enrolment_users_table($manager, $PAGE); $usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id)); // The URl to return the user too after this screen. $returnurl = new moodle_url($usersurl, $manager->get_url_params()+$table->get_url_params()); -// The URL of this page +// The URL of this page. $url = new moodle_url('/enrol/manual/editenrolment.php', $returnurl->params()); $PAGE->set_url($url); @@ -88,9 +84,7 @@ $mform->set_data($PAGE->url->params()); // Check the form hasn't been cancelled if ($mform->is_cancelled()) { redirect($returnurl); -} else if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) { - // The forms been submit, validated and the sesskey has been checked ... edit the enrolment. - $data = $mform->get_data(); +} else if ($data = $mform->get_data()) { if ($manager->edit_enrolment($ue, $data)) { redirect($returnurl); } @@ -107,4 +101,4 @@ $PAGE->navbar->add($fullname); echo $OUTPUT->header(); echo $OUTPUT->heading($fullname); $mform->display(); -echo $OUTPUT->footer(); \ No newline at end of file +echo $OUTPUT->footer(); diff --git a/enrol/manual/editenrolment_form.php b/enrol/manual/editenrolment_form.php index ea9205d2e17..b73fc7c0804 100644 --- a/enrol/manual/editenrolment_form.php +++ b/enrol/manual/editenrolment_form.php @@ -1,5 +1,4 @@ . - /** * External course participation api. * @@ -32,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/externallib.php"); /** - * Manual enrolment external functions + * Manual enrolment external functions. * * @package enrol_manual * @category external @@ -43,7 +42,7 @@ require_once("$CFG->libdir/externallib.php"); class enrol_manual_external extends external_api { /** - * Returns description of method parameters + * Returns description of method parameters. * * @return external_function_parameters * @since Moodle 2.2 @@ -68,7 +67,7 @@ class enrol_manual_external extends external_api { } /** - * Enrolment of users + * Enrolment of users. * * Function throw an exception at the first error encountered. * @param array $enrolments An array of user enrolment @@ -82,24 +81,24 @@ class enrol_manual_external extends external_api { $params = self::validate_parameters(self::enrol_users_parameters(), array('enrolments' => $enrolments)); - $transaction = $DB->start_delegated_transaction(); //rollback all enrolment if an error occurs - //(except if the DB doesn't support it) + $transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs + // (except if the DB doesn't support it). - //retrieve the manual enrolment plugin + // Retrieve the manual enrolment plugin. $enrol = enrol_get_plugin('manual'); if (empty($enrol)) { throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual'); } foreach ($params['enrolments'] as $enrolment) { - // Ensure the current user is allowed to run this function in the enrolment context + // Ensure the current user is allowed to run this function in the enrolment context. $context = context_course::instance($enrolment['courseid'], IGNORE_MISSING); self::validate_context($context); - //check that the user has the permission to manual enrol + // Check that the user has the permission to manual enrol. require_capability('enrol/manual:enrol', $context); - //throw an exception if user is not able to assign the role + // Throw an exception if user is not able to assign the role. $roles = get_assignable_roles($context); if (!key_exists($enrolment['roleid'], $roles)) { $errorparams = new stdClass(); @@ -109,7 +108,7 @@ class enrol_manual_external extends external_api { throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams); } - //check manual enrolment plugin instance is enabled/exist + // Check manual enrolment plugin instance is enabled/exist. $enrolinstances = enrol_get_instances($enrolment['courseid'], true); foreach ($enrolinstances as $courseenrolinstance) { if ($courseenrolinstance->enrol == "manual") { @@ -123,7 +122,7 @@ class enrol_manual_external extends external_api { throw new moodle_exception('wsnoinstance', 'enrol_manual', $errorparams); } - //check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin) + // Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin). if (!$enrol->allow_enrol($instance)) { $errorparams = new stdClass(); $errorparams->roleid = $enrolment['roleid']; @@ -132,7 +131,7 @@ class enrol_manual_external extends external_api { throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams); } - //finally proceed the enrolment + // Finally proceed the enrolment. $enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0; $enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0; $enrolment['status'] = (isset($enrolment['suspend']) && !empty($enrolment['suspend'])) ? @@ -147,7 +146,7 @@ class enrol_manual_external extends external_api { } /** - * Returns description of method result value + * Returns description of method result value. * * @return null * @since Moodle 2.2 @@ -159,7 +158,7 @@ class enrol_manual_external extends external_api { } /** - * Deprecated manual enrolment external functions + * Deprecated manual enrolment external functions. * * @package enrol_manual * @copyright 2011 Jerome Mouneyrac @@ -172,7 +171,7 @@ class enrol_manual_external extends external_api { class moodle_enrol_manual_external extends external_api { /** - * Returns description of method parameters + * Returns description of method parameters. * * @return external_function_parameters * @since Moodle 2.0 @@ -199,7 +198,7 @@ class moodle_enrol_manual_external extends external_api { } /** - * Returns description of method result value + * Returns description of method result value. * * @return nul * @since Moodle 2.0 diff --git a/enrol/manual/lib.php b/enrol/manual/lib.php index 5320f6aae54..2cf94bb7793 100644 --- a/enrol/manual/lib.php +++ b/enrol/manual/lib.php @@ -1,5 +1,4 @@ dirroot . '/enrol/locallib.php'); /** - * Enrol candidates + * Enrol candidates. */ class enrol_manual_potential_participant extends user_selector_base { protected $enrolid; @@ -42,12 +41,12 @@ class enrol_manual_potential_participant extends user_selector_base { /** * Candidate users - * @param $search + * @param string $search * @return array */ public function find_users($search) { global $DB; - //by default wherecondition retrieves all users except the deleted, not confirmed and guest + // By default wherecondition retrieves all users except the deleted, not confirmed and guest. list($wherecondition, $params) = $this->search_sql($search, 'u'); $params['enrolid'] = $this->enrolid; @@ -92,7 +91,7 @@ class enrol_manual_potential_participant extends user_selector_base { } /** - * Enroled users + * Enrolled users. */ class enrol_manual_current_participant extends user_selector_base { protected $courseid; @@ -105,12 +104,12 @@ class enrol_manual_current_participant extends user_selector_base { /** * Candidate users - * @param $search + * @param string $search * @return array */ public function find_users($search) { global $DB; - //by default wherecondition retrieves all users except the deleted, not confirmed and guest + // By default wherecondition retrieves all users except the deleted, not confirmed and guest. list($wherecondition, $params) = $this->search_sql($search, 'u'); $params['enrolid'] = $this->enrolid; @@ -182,7 +181,6 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper /** * Processes the bulk operation request for the given userids with the provided properties. * - * @global moodle_database $DB * @param course_enrolment_manager $manager * @param array $userids * @param stdClass $properties The data returned by the form. @@ -194,7 +192,7 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper return false; } - // Get all of the user enrolment id's + // Get all of the user enrolment id's. $ueids = array(); $instances = array(); foreach ($users as $user) { @@ -237,15 +235,15 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper return true; } - // Update the modifierid + // Update the modifierid. $updatesql[] = 'modifierid = :modifierid'; $params['modifierid'] = (int)$USER->id; - // Update the time modified + // Update the time modified. $updatesql[] = 'timemodified = :timemodified'; $params['timemodified'] = time(); - // Build the SQL statement + // Build the SQL statement. $updatesql = join(', ', $updatesql); $sql = "UPDATE {user_enrolments} SET $updatesql @@ -353,4 +351,4 @@ class enrol_manual_deleteselectedusers_operation extends enrol_bulk_enrolment_op } return true; } -} \ No newline at end of file +} diff --git a/enrol/manual/manage.php b/enrol/manual/manage.php index 0a4f69865a9..46d1b77e874 100644 --- a/enrol/manual/manage.php +++ b/enrol/manual/manage.php @@ -17,8 +17,7 @@ /** * Manual user enrolment UI. * - * @package enrol - * @subpackage manual + * @package enrol_manual * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -47,7 +46,7 @@ $roles = get_assignable_roles($context); $roles = array('0'=>get_string('none')) + $roles; if (!isset($roles[$roleid])) { - // weird - security always first! + // Weird - security always first! $roleid = 0; } @@ -88,14 +87,14 @@ $timeformat = get_string('strftimedatefullshort'); $today = time(); $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); -// enrolment start +// Enrolment start. $basemenu = array(); if ($course->startdate > 0) { $basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')'; } $basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ; -// process add and removes +// Process add and removes. if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { $userstoassign = $potentialuserselector->get_selected_users(); if (!empty($userstoassign)) { @@ -126,7 +125,7 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { } } -// Process incoming role unassignments +// Process incoming role unassignments. if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { $userstounassign = $currentuserselector->get_selected_users(); if (!empty($userstounassign)) { diff --git a/enrol/manual/settings.php b/enrol/manual/settings.php index 13d72ed9259..79686aab792 100644 --- a/enrol/manual/settings.php +++ b/enrol/manual/settings.php @@ -1,5 +1,4 @@ fulltree) { get_string('defaultrole', 'role'), '', $student->id, $options)); } } - diff --git a/enrol/manual/unenrolself.php b/enrol/manual/unenrolself.php index fb1744de716..c7304fb5f58 100644 --- a/enrol/manual/unenrolself.php +++ b/enrol/manual/unenrolself.php @@ -1,5 +1,4 @@ get_unenrolself_link($instance)) { redirect(new moodle_url('/course/view.php', array('id'=>$course->id))); } @@ -51,7 +49,7 @@ $PAGE->set_title($plugin->get_instance_name($instance)); if ($confirm and confirm_sesskey()) { $plugin->unenrol_user($instance, $USER->id); - add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! + add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere! redirect(new moodle_url('/index.php')); } diff --git a/enrol/manual/version.php b/enrol/manual/version.php index 8d2ff58fe7b..2107a671994 100644 --- a/enrol/manual/version.php +++ b/enrol/manual/version.php @@ -17,8 +17,7 @@ /** * Manual enrolment plugin version specification. * - * @package enrol - * @subpackage manual + * @package enrol_manual * @copyright 2010 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ From 764094585bbffa8399241558237e63754523a9fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Mon, 27 Aug 2012 17:19:07 +0200 Subject: [PATCH 2/2] MDL-35072 fix bogus left enrol join Credit goes to Eloy, thanks. --- enrol/manual/editenrolment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enrol/manual/editenrolment.php b/enrol/manual/editenrolment.php index b0f0b2fb1db..538f45818f9 100644 --- a/enrol/manual/editenrolment.php +++ b/enrol/manual/editenrolment.php @@ -40,7 +40,7 @@ $user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST); // Get the course the enrolment is to. $sql = "SELECT c.* FROM {course} c - LEFT JOIN {enrol} e ON e.courseid = c.id + JOIN {enrol} e ON e.courseid = c.id WHERE e.id = :enrolid"; $params = array('enrolid' => $ue->enrolid); $course = $DB->get_record_sql($sql, $params, MUST_EXIST);