MDL-35070 coding style cleanup in enrol_self

This commit is contained in:
Petr Škoda
2012-08-26 15:50:40 +02:00
parent dd6b1f15cf
commit d9669db9b3
12 changed files with 72 additions and 94 deletions

View File

@@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die();
$capabilities = array(
/* Add or edit enrol-self instance in course. */
'enrol/self:config' => array(
'captype' => 'write',
@@ -36,6 +37,7 @@ $capabilities = array(
)
),
/* Manage user self-enrolments. */
'enrol/self:manage' => array(
'captype' => 'write',
@@ -46,6 +48,7 @@ $capabilities = array(
)
),
/* Voluntarily unenrol self from course - watch out for data loss. */
'enrol/self:unenrolself' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
@@ -54,6 +57,7 @@ $capabilities = array(
)
),
/* Unenrol anybody from course (including self) - watch out for data loss. */
'enrol/self:unenrol' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
@@ -64,5 +68,3 @@ $capabilities = array(
),
);

View File

@@ -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
@@ -18,8 +17,7 @@
/**
* Self enrol plugin installation script
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View File

@@ -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
@@ -19,8 +18,7 @@
* Adds new instance of enrol_self to specified course
* or edits current instance.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -29,7 +27,7 @@ require('../../config.php');
require_once('edit_form.php');
$courseid = required_param('courseid', PARAM_INT);
$instanceid = optional_param('id', 0, PARAM_INT); // instanceid
$instanceid = optional_param('id', 0, PARAM_INT);
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
@@ -51,7 +49,7 @@ if ($instanceid) {
$instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'self', 'id'=>$instanceid), '*', MUST_EXIST);
} 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;

View File

@@ -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
@@ -19,8 +18,7 @@
* Adds new instance of enrol_self to specified course
* or edits current instance.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -193,7 +191,7 @@ class enrol_self_edit_form extends moodleform {
}
/**
* Gets a list of roles that this user can assign for the course as the default for self-enrolment
* Gets a list of roles that this user can assign for the course as the default for self-enrolment.
*
* @param context $context the context.
* @param integer $defaultrole the id of the role that is set as the default for self-enrolment

View File

@@ -20,48 +20,44 @@
* This page allows the current user to edit a self user enrolment.
* It is not compatible with the frontpage.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @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"); // Required for the course enrolment manager
require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment users table
require_once("$CFG->dirroot/enrol/self/editenrolment_form.php"); // Forms for this page
require_once("$CFG->dirroot/enrol/locallib.php"); // Required for the course enrolment manager.
require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment users table.
require_once("$CFG->dirroot/enrol/self/editenrolment_form.php"); // Forms for this page.
$ueid = required_param('ue', PARAM_INT); // user enrolment id
$filter = optional_param('ifilter', 0, PARAM_INT); // table filter for return url
$ueid = required_param('ue', PARAM_INT);
$filter = optional_param('ifilter', 0, PARAM_INT); // Table filter for return url.
// Get the user enrolment object
// Get the user enrolment object.
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
// Get the user for whom the enrolment is
// 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 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 the course isn't the front page
// Make sure the course isn't the front page.
if ($course->id == SITEID) {
redirect(new moodle_url('/'));
}
// Obvioulsy
// Obviously.
require_login($course);
// The user must be able to manage self enrolments within the course
// The user must be able to manage self enrolments within the course.
require_capability("enrol/self: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
// Get an enrolment users table object. Doing 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
// exact page of the users screen they can from.
$table = new course_enrolment_users_table($manager, $PAGE);
@@ -70,30 +66,28 @@ $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/self/editenrolment.php', $returnurl->params());
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
navigation_node::override_active_url($usersurl);
// Gets the compontents of the user enrolment
// Gets the components of the user enrolment.
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
// Check that the user can manage this instance, and that the instance is of the correct type
// Check that the user can manage this instance, and that the instance is of the correct type.
if (!$plugin->allow_manage($instance) || $instance->enrol != 'self' || !($plugin instanceof enrol_self_plugin)) {
print_error('erroreditenrolment', 'enrol');
}
// Get the self enrolment edit form
// Get the self enrolment edit form.
$mform = new enrol_self_user_enrolment_form($url, array('user'=>$user, 'course'=>$course, 'ue'=>$ue));
$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);
}

View File

@@ -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
@@ -18,8 +17,7 @@
/**
* Contains the form used to edit self enrolments for a user.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2011 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View File

@@ -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
@@ -16,10 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'enrol_self', language 'en', branch 'MOODLE_20_STABLE'
* Strings for component 'enrol_self', language 'en'.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View File

@@ -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
@@ -18,8 +17,7 @@
/**
* Self enrolment plugin.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -66,7 +64,7 @@ class enrol_self_plugin extends enrol_plugin {
/**
* Returns localised name of enrol instance
*
* @param object $instance (null is accepted too)
* @param stdClass $instance (null is accepted too)
* @return string
*/
public function get_instance_name($instance) {
@@ -86,17 +84,17 @@ class enrol_self_plugin extends enrol_plugin {
}
public function roles_protected() {
// users may tweak the roles later
// Users may tweak the roles later.
return false;
}
public function allow_unenrol(stdClass $instance) {
// users with unenrol cap may unenrol other users manually manually
// Users with unenrol cap may unenrol other users manually manually.
return true;
}
public function allow_manage(stdClass $instance) {
// users with manage cap may tweak period and status
// Users with manage cap may tweak period and status.
return true;
}
@@ -116,7 +114,8 @@ class enrol_self_plugin extends enrol_plugin {
/**
* Sets up navigation entries.
*
* @param object $instance
* @param stdClass $instancesnode
* @param stdClass $instance
* @return void
*/
public function add_course_navigation($instancesnode, stdClass $instance) {
@@ -165,7 +164,7 @@ class enrol_self_plugin extends enrol_plugin {
if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/self:config', $context)) {
return NULL;
}
// multiple instances supported - different roles with different password
// Multiple instances supported - different roles with different password.
return new moodle_url('/enrol/self/edit.php', array('courseid'=>$courseid));
}
@@ -180,7 +179,7 @@ class enrol_self_plugin extends enrol_plugin {
global $CFG, $OUTPUT, $SESSION, $USER, $DB;
if (isguestuser()) {
// can not enrol guest!!
// Can not enrol guest!!
return null;
}
if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) {
@@ -227,7 +226,7 @@ class enrol_self_plugin extends enrol_plugin {
}
$this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend);
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //TODO: There should be userid somewhere!
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
// it must be a group enrolment, let's assign group too
@@ -242,7 +241,7 @@ class enrol_self_plugin extends enrol_plugin {
}
}
}
// send welcome
// Send welcome message.
if ($instance->customint4) {
$this->email_welcome_message($instance, $USER);
}
@@ -258,7 +257,7 @@ class enrol_self_plugin extends enrol_plugin {
/**
* Add new instance of enrol plugin with default settings.
* @param object $course
* @param stdClass $course
* @return int id of new instance
*/
public function add_default_instance($course) {
@@ -279,10 +278,10 @@ class enrol_self_plugin extends enrol_plugin {
}
/**
* Send welcome email to specified user
* Send welcome email to specified user.
*
* @param object $instance
* @param object $user user record
* @param stdClass $instance
* @param stdClass $user user record
* @return void
*/
protected function email_welcome_message($instance, $user) {
@@ -326,12 +325,12 @@ class enrol_self_plugin extends enrol_plugin {
$contact = generate_email_supportuser();
}
//directly emailing welcome message rather than using messaging
// Directly emailing welcome message rather than using messaging.
email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
}
/**
* Enrol self cron support
* Enrol self cron support.
* @return void
*/
public function cron() {
@@ -345,10 +344,10 @@ class enrol_self_plugin extends enrol_plugin {
$now = time();
//note: the logic of self enrolment guarantees that user logged in at least once (=== u.lastaccess set)
// and that user accessed course at least once too (=== user_lastaccess record exists)
// Note: the logic of self enrolment guarantees that user logged in at least once (=== u.lastaccess set)
// and that user accessed course at least once too (=== user_lastaccess record exists).
// first deal with users that did not log in for a really long time
// First deal with users that did not log in for a really long time.
$sql = "SELECT e.*, ue.userid
FROM {user_enrolments} ue
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'self' AND e.customint2 > 0)
@@ -363,7 +362,7 @@ class enrol_self_plugin extends enrol_plugin {
}
$rs->close();
// now unenrol from course user did not visit for a long time
// Now unenrol from course user did not visit for a long time.
$sql = "SELECT e.*, ue.userid
FROM {user_enrolments} ue
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'self' AND e.customint2 > 0)
@@ -382,7 +381,7 @@ class enrol_self_plugin extends enrol_plugin {
}
/**
* Gets an array of the user enrolment actions
* Gets an array of the user enrolment actions.
*
* @param course_enrolment_manager $manager
* @param stdClass $ue A user enrolment object
@@ -410,7 +409,7 @@ class enrol_self_plugin extends enrol_plugin {
* Indicates API features that the enrol plugin supports.
*
* @param string $feature
* @return mixed True if yes (some features may use other values)
* @return mixed true if yes (some features may use other values)
*/
function enrol_self_supports($feature) {
switch($feature) {

View File

@@ -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
@@ -18,8 +17,7 @@
/**
* Self enrol plugin implementation.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -33,7 +31,7 @@ class enrol_self_enrol_form extends moodleform {
protected $toomany = false;
/**
* Overriding this function to get unique form id for multiple self enrolments
* Overriding this function to get unique form id for multiple self enrolments.
*
* @return string form identifier
*/
@@ -54,10 +52,10 @@ class enrol_self_enrol_form extends moodleform {
$mform->addElement('header', 'selfheader', $heading);
if ($instance->customint3 > 0) {
// max enrol limit specified
// Max enrol limit specified.
$count = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id));
if ($count >= $instance->customint3) {
// bad luck, no more self enrolments here
// Bad luck, no more self enrolments here.
$this->toomany = true;
$mform->addElement('static', 'notice', '', get_string('maxenrolledreached', 'enrol_self'));
return;
@@ -65,7 +63,7 @@ class enrol_self_enrol_form extends moodleform {
}
if ($instance->password) {
//change the id of self enrolment key input as there can be multiple self enrolment methods
// Change the id of self enrolment key input as there can be multiple self enrolment methods.
$mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_self'),
array('id' => 'enrolpassword_'.$instance->id));
} else {
@@ -109,7 +107,7 @@ class enrol_self_enrol_form extends moodleform {
}
}
if (!$found) {
// we can not hint because there are probably multiple passwords
// We can not hint because there are probably multiple passwords.
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
}

View File

@@ -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
@@ -18,8 +17,7 @@
/**
* Self enrolment plugin settings and presets.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View File

@@ -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
@@ -18,8 +17,7 @@
/**
* Self enrolment plugin - support for user self unenrolment.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -41,7 +39,7 @@ require_login($course);
$plugin = enrol_get_plugin('self');
// security defined inside following function
// Security defined inside following function.
if (!$plugin->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'));
}

View File

@@ -17,8 +17,7 @@
/**
* Self enrolment plugin version specification.
*
* @package enrol
* @subpackage self
* @package enrol_self
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/