Skip to content

Commit

Permalink
MDL-35070 coding style cleanup in enrol_self
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Aug 26, 2012
1 parent dd6b1f1 commit d9669db
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 96 deletions.
6 changes: 4 additions & 2 deletions enrol/self/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

$capabilities = array(

/* Add or edit enrol-self instance in course. */
'enrol/self:config' => array(

'captype' => 'write',
Expand All @@ -36,6 +37,7 @@
)
),

/* Manage user self-enrolments. */
'enrol/self:manage' => array(

'captype' => 'write',
Expand All @@ -46,6 +48,7 @@
)
),

/* Voluntarily unenrol self from course - watch out for data loss. */
'enrol/self:unenrolself' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
Expand All @@ -54,6 +57,7 @@
)
),

/* Unenrol anybody from course (including self) - watch out for data loss. */
'enrol/self:unenrol' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
Expand All @@ -64,5 +68,3 @@
),

);


4 changes: 1 addition & 3 deletions enrol/self/db/install.php
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*/
Expand Down
8 changes: 3 additions & 5 deletions enrol/self/edit.php
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*/
Expand All @@ -29,7 +27,7 @@
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);
Expand All @@ -51,7 +49,7 @@
$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;
Expand Down
6 changes: 2 additions & 4 deletions enrol/self/edit_form.php
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -193,7 +191,7 @@ function validation($data, $files) {
}

/**
* 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
Expand Down
58 changes: 26 additions & 32 deletions enrol/self/editenrolment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

$ueid = required_param('ue', PARAM_INT); // user enrolment id
$filter = optional_param('ifilter', 0, PARAM_INT); // table filter for return url

// 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
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);
$filter = optional_param('ifilter', 0, PARAM_INT); // Table filter for return url.

// 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 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);
Expand All @@ -70,30 +66,28 @@
$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);
}
Expand All @@ -110,4 +104,4 @@
echo $OUTPUT->header();
echo $OUTPUT->heading($fullname);
$mform->display();
echo $OUTPUT->footer();
echo $OUTPUT->footer();
6 changes: 2 additions & 4 deletions enrol/self/editenrolment_form.php
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -80,4 +78,4 @@ function validation($data, $files) {

return $errors;
}
}
}
6 changes: 2 additions & 4 deletions enrol/self/lang/en/enrol_self.php
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*/
Expand Down
Loading

0 comments on commit d9669db

Please sign in to comment.