Skip to content
Browse files

Merge branch 'w12_MDL-26808_20_enrolpageurl' of git://github.com/skod…

…ak/moodle
  • Loading branch information...
2 parents ca3fce6 + 61c32b7 commit 161ba40d03b06e5da387b2ef7a4a77ef532063bb Sam Hemelryk committed Mar 21, 2011
Showing with 70 additions and 79 deletions.
  1. +4 −5 enrol/otherusers.php
  2. +45 −51 enrol/renderer.php
  3. +21 −23 enrol/users.php
View
9 enrol/otherusers.php
@@ -42,12 +42,11 @@
redirect("$CFG->wwwroot/");
}
-$PAGE->set_url('/enrol/otherusers.php', array('id'=>$course->id));
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($course, $filter);
-$table = new course_enrolment_other_users_table($manager, $PAGE->url);
-$pageurl = new moodle_url($PAGE->url, $manager->get_url_params()+$table->get_url_params());
+$table = new course_enrolment_other_users_table($manager, $PAGE);
+$PAGE->set_url('/enrol/otherusers.php', $manager->get_url_params()+$table->get_url_params());
/***
* Actions will go here
@@ -82,11 +81,11 @@
$renderer = $PAGE->get_renderer('core_enrol');
$canassign = has_capability('moodle/role:assign', $manager->get_context());
-$users = $manager->get_other_users_for_display($renderer, $pageurl, $table->sort, $table->sortdirection, $table->page, $table->perpage);
+$users = $manager->get_other_users_for_display($renderer, $PAGE->url, $table->sort, $table->sortdirection, $table->page, $table->perpage);
$assignableroles = $manager->get_assignable_roles(true);
foreach ($users as $userid=>&$user) {
$user['picture'] = $OUTPUT->render($user['picture']);
- $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $assignableroles, $canassign, $pageurl);
+ $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $assignableroles, $canassign, $PAGE->url);
}
$table->set_total_users($manager->get_total_other_users());
View
96 enrol/renderer.php
@@ -40,26 +40,26 @@ class core_enrol_renderer extends plugin_renderer_base {
*/
protected function render_course_enrolment_users_table(course_enrolment_users_table $table) {
- $table->initialise_javascript($this->page);
+ $table->initialise_javascript();
$content = '';
- $enrolmentselector = $table->get_enrolment_selector($this->page);
+ $enrolmentselector = $table->get_enrolment_selector();
if ($enrolmentselector) {
$content .= $this->output->render($enrolmentselector);
}
- $cohortenroller = $table->get_cohort_enrolment_control($this->page);
+ $cohortenroller = $table->get_cohort_enrolment_control();
if ($cohortenroller) {
$content .= $this->output->render($cohortenroller);
}
$content .= $this->output->render($table->get_enrolment_type_filter());
$content .= $this->output->render($table->get_paging_bar());
$content .= html_writer::table($table);
$content .= $this->output->render($table->get_paging_bar());
- $enrolmentselector = $table->get_enrolment_selector($this->page);
+ $enrolmentselector = $table->get_enrolment_selector();
if ($enrolmentselector) {
$content .= $this->output->render($enrolmentselector);
}
- $cohortenroller = $table->get_cohort_enrolment_control($this->page);
+ $cohortenroller = $table->get_cohort_enrolment_control();
if ($cohortenroller) {
$content .= $this->output->render($cohortenroller);
}
@@ -74,18 +74,18 @@ protected function render_course_enrolment_users_table(course_enrolment_users_ta
*/
protected function render_course_enrolment_other_users_table(course_enrolment_other_users_table $table) {
- $table->initialise_javascript($this->page);
+ $table->initialise_javascript();
$content = '';
- $searchbutton = $table->get_user_search_button($this->page);
+ $searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
$content .= html_writer::tag('div', get_string('otheruserdesc', 'enrol'), array('class'=>'otherusersdesc'));
$content .= $this->output->render($table->get_paging_bar());
$content .= html_writer::table($table);
$content .= $this->output->render($table->get_paging_bar());
- $searchbutton = $table->get_user_search_button($this->page);
+ $searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
@@ -287,9 +287,9 @@ class course_enrolment_table extends html_table implements renderable {
/**
* The URL of the page for this table
- * @var moodle_url
+ * @var moodle_page
*/
- public $pageurl;
+ public $moodlepage;
/**
* The sort field for this table, should be one of course_enrolment_table::$sortablefields
@@ -345,14 +345,14 @@ class course_enrolment_table extends html_table implements renderable {
*
* @param course_enrolment_manager $manager
*/
- public function __construct(course_enrolment_manager $manager, moodle_url $pageurl) {
+ public function __construct(course_enrolment_manager $manager, moodle_page $moodlepage) {
- $this->manager = $manager;
- $this->pageurl = $pageurl;
+ $this->manager = $manager;
+ $this->moodlepage = $moodlepage;
- $this->page = optional_param(self::PAGEVAR, 0, PARAM_INT);
- $this->perpage = optional_param(self::PERPAGEVAR, self::DEFAULTPERPAGE, PARAM_INT);
- $this->sort = optional_param(self::SORTVAR, self::DEFAULTSORT, PARAM_ALPHA);
+ $this->page = optional_param(self::PAGEVAR, 0, PARAM_INT);
+ $this->perpage = optional_param(self::PERPAGEVAR, self::DEFAULTPERPAGE, PARAM_INT);
+ $this->sort = optional_param(self::SORTVAR, self::DEFAULTSORT, PARAM_ALPHA);
$this->sortdirection = optional_param(self::SORTDIRECTIONVAR, self::DEFAULTSORTDIRECTION, PARAM_ALPHA);
$this->attributes = array('class'=>'userenrolment');
@@ -396,7 +396,7 @@ public function set_fields($fields, $output) {
$this->head = array();
$this->colclasses = array();
$this->align = array();
- $url = new moodle_url($this->pageurl, $this->get_url_params()+$this->manager->get_url_params());
+ $url = $this->moodlepage->url;
foreach ($fields as $name => $label) {
$newlabel = '';
if (is_array($label)) {
@@ -450,7 +450,7 @@ public function set_total_users($totalusers) {
* Sets the users for this table
*
* @param array $users
- * @param moodle_page $page
+ * @return void
*/
public function set_users(array $users) {
$this->users = $users;
@@ -483,9 +483,9 @@ public function set_users(array $users) {
}
}
- public function initialise_javascript(moodle_page $page) {
+ public function initialise_javascript() {
if (has_capability('moodle/role:assign', $this->manager->get_context())) {
- $page->requires->strings_for_js(array(
+ $this->moodlepage->requires->strings_for_js(array(
'assignroles',
'confirmunassign',
'confirmunassigntitle',
@@ -499,7 +499,7 @@ public function initialise_javascript(moodle_page $page) {
'userIds'=>array_keys($this->users),
'courseId'=>$this->manager->get_course()->id,
'otherusers'=>isset($this->otherusers));
- $page->requires->yui_module($modules, $function, array($arguments));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
}
@@ -510,7 +510,7 @@ public function initialise_javascript(moodle_page $page) {
*/
public function get_paging_bar() {
if ($this->pagingbar == null) {
- $this->pagingbar = new paging_bar($this->totalusers, $this->page, $this->perpage, $this->pageurl, self::PAGEVAR);
+ $this->pagingbar = new paging_bar($this->totalusers, $this->page, $this->perpage, $this->moodlepage->url, self::PAGEVAR);
}
return $this->pagingbar;
}
@@ -568,10 +568,9 @@ class course_enrolment_users_table extends course_enrolment_table {
* Returns a button to enrol cohorts or thier users
*
* @staticvar int $count
- * @param moodle_page $page
* @return single_button|false
*/
- public function get_cohort_enrolment_control(moodle_page $page) {
+ public function get_cohort_enrolment_control() {
static $count = 0;
// First make sure that cohorts is enabled
@@ -590,11 +589,10 @@ public function get_cohort_enrolment_control(moodle_page $page) {
$control->class = 'singlebutton enrolcohortbutton instance'.$count;
$control->formid = 'manuallyenrol_single_'+$count;
if ($count == 1) {
- $page->requires->strings_for_js(array('enrol','synced','enrolcohort','enrolcohortusers'), 'enrol');
- $page->requires->string_for_js('assignroles', 'role');
- $page->requires->string_for_js('cohort', 'cohort');
- $page->requires->string_for_js('users', 'moodle');
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
+ $this->moodlepage->requires->strings_for_js(array('enrol','synced','enrolcohort','enrolcohortusers'), 'enrol');
+ $this->moodlepage->requires->string_for_js('assignroles', 'role');
+ $this->moodlepage->requires->string_for_js('cohort', 'cohort');
+ $this->moodlepage->requires->string_for_js('users', 'moodle');
$hasmanualinstance = false;
// No point showing this at all if the user cant manually enrol users
@@ -614,9 +612,9 @@ public function get_cohort_enrolment_control(moodle_page $page) {
$arguments = array(
'courseid'=>$course->id,
'ajaxurl'=>'/enrol/ajax.php',
- 'url'=>$url->out(false),
+ 'url'=>$this->moodlepage->url->out(false),
'manualEnrolment'=>$hasmanualinstance);
- $page->requires->yui_module($modules, $function, array($arguments));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
return $control;
}
@@ -627,7 +625,7 @@ public function get_cohort_enrolment_control(moodle_page $page) {
*
* @return single_button|url_select
*/
- public function get_enrolment_selector(moodle_page $page) {
+ public function get_enrolment_selector() {
static $count = 0;
$instances = $this->manager->get_enrolment_instances();
@@ -662,7 +660,6 @@ public function get_enrolment_selector(moodle_page $page) {
$control->formid = 'manuallyenrol_select_'+$count;
}
$course = $this->manager->get_course();
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
$timeformat = get_string('strftimedatefullshort');
$today = time();
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
@@ -674,7 +671,7 @@ public function get_enrolment_selector(moodle_page $page) {
if ($count == 1) {
$instance = reset($manuals);
- $page->requires->strings_for_js(array(
+ $this->moodlepage->requires->strings_for_js(array(
'ajaxoneuserfound',
'ajaxxusersfound',
'ajaxnext25',
@@ -689,19 +686,19 @@ public function get_enrolment_selector(moodle_page $page) {
'startdatetoday',
'durationdays',
'enrolperiod'), 'enrol');
- $page->requires->string_for_js('assignroles', 'role');
- $page->requires->string_for_js('startingfrom', 'moodle');
+ $this->moodlepage->requires->string_for_js('assignroles', 'role');
+ $this->moodlepage->requires->string_for_js('startingfrom', 'moodle');
$modules = array('moodle-enrol-enrolmentmanager', 'moodle-enrol-enrolmentmanager-skin');
$function = 'M.enrol.enrolmentmanager.init';
$arguments = array(
'instances'=>$arguments,
'courseid'=>$course->id,
'ajaxurl'=>'/enrol/ajax.php',
- 'url'=>$url->out(false),
+ 'url'=>$this->moodlepage->url->out(false),
'optionsStartDate'=>$startdateoptions,
'defaultRole'=>$instance->roleid);
- $page->requires->yui_module($modules, $function, array($arguments));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
return $control;
}
@@ -713,8 +710,7 @@ public function get_enrolment_selector(moodle_page $page) {
* @return single_select
*/
public function get_enrolment_type_filter() {
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
- $selector = new single_select($url, 'ifilter', array(0=>get_string('all')) + (array)$this->manager->get_enrolment_instance_names(), $this->manager->get_enrolment_filter(), array());
+ $selector = new single_select($this->moodlepage->url, 'ifilter', array(0=>get_string('all')) + (array)$this->manager->get_enrolment_instance_names(), $this->manager->get_enrolment_filter(), array());
$selector->set_label( get_string('enrolmentinstances', 'enrol'));
return $selector;
}
@@ -736,10 +732,10 @@ class course_enrolment_other_users_table extends course_enrolment_table {
* Constructs the table
*
* @param course_enrolment_manager $manager
- * @param moodle_url $pageurl
+ * @param moodle_page $moodlepage
*/
- public function __construct(course_enrolment_manager $manager, moodle_url $pageurl) {
- parent::__construct($manager, $pageurl);
+ public function __construct(course_enrolment_manager $manager, moodle_page $moodlepage) {
+ parent::__construct($manager, $moodlepage);
$this->attributes = array('class'=>'userenrolment otheruserenrolment');
}
@@ -750,18 +746,17 @@ public function __construct(course_enrolment_manager $manager, moodle_url $pageu
* @param int $page
* @return single_button
*/
- public function get_user_search_button($page) {
- global $CFG;
+ public function get_user_search_button() {
static $count = 0;
if (!has_capability('moodle/role:assign', $this->manager->get_context())) {
return false;
}
$count++;
- $url = new moodle_url('/'.$CFG->admin.'/roles/assign.php', array('contextid'=>$this->manager->get_context()->id, 'sesskey'=>sesskey()));
+ $url = new moodle_url('/admin/roles/assign.php', array('contextid'=>$this->manager->get_context()->id, 'sesskey'=>sesskey()));
$control = new single_button($url, get_string('assignroles', 'role'), 'get');
$control->class = 'singlebutton assignuserrole instance'.$count;
if ($count == 1) {
- $page->requires->strings_for_js(array(
+ $this->moodlepage->requires->strings_for_js(array(
'ajaxoneuserfound',
'ajaxxusersfound',
'ajaxnext25',
@@ -776,16 +771,15 @@ public function get_user_search_button($page) {
'startdatetoday',
'durationdays',
'enrolperiod'), 'enrol');
- $page->requires->string_for_js('assignrole', 'role');
+ $this->moodlepage->requires->string_for_js('assignrole', 'role');
$modules = array('moodle-enrol-otherusersmanager', 'moodle-enrol-otherusersmanager-skin');
$function = 'M.enrol.otherusersmanager.init';
- $url = new moodle_url($this->pageurl, $this->manager->get_url_params()+$this->get_url_params());
$arguments = array(
'courseId'=> $this->manager->get_course()->id,
'ajaxUrl' => '/enrol/ajax.php',
- 'url' => $url->out(false));
- $page->requires->yui_module($modules, $function, array($arguments));
+ 'url' => $this->moodlepage->url->out(false));
+ $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
}
return $control;
}
View
44 enrol/users.php
@@ -33,8 +33,6 @@
$action = optional_param('action', '', PARAM_ACTION);
$filter = optional_param('ifilter', 0, PARAM_INT);
-$PAGE->set_url(new moodle_url('/enrol/users.php', array('id'=>$id)));
-
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
@@ -47,8 +45,8 @@
$PAGE->set_pagelayout('admin');
$manager = new course_enrolment_manager($course, $filter);
-$table = new course_enrolment_users_table($manager, $PAGE->url);
-$pageurl = new moodle_url($PAGE->url, $manager->get_url_params()+$table->get_url_params());
+$table = new course_enrolment_users_table($manager, $PAGE);
+$PAGE->set_url('/enrol/users.php', $manager->get_url_params()+$table->get_url_params());
// Check if there is an action to take
if ($action) {
@@ -71,13 +69,13 @@
list ($instance, $plugin) = $manager->get_user_enrolment_components($ue);
if ($instance && $plugin && $plugin->allow_unenrol($instance) && has_capability("enrol/$instance->enrol:unenrol", $manager->get_context())) {
if ($confirm && $manager->unenrol_user($ue)) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
- $yesurl = new moodle_url($pageurl, array('action'=>'unenrol', 'ue'=>$ue->id, 'confirm'=>1, 'sesskey'=>sesskey()));
+ $yesurl = new moodle_url($PAGE->url, array('action'=>'unenrol', 'ue'=>$ue->id, 'confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('unenrolconfirm', 'enrol', array('user'=>fullname($user, true), 'course'=>format_string($course->fullname)));
$pagetitle = get_string('unenrol', 'enrol');
- $pagecontent = $OUTPUT->confirm($message, $yesurl, $pageurl);
+ $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
@@ -90,15 +88,15 @@
$role = required_param('role', PARAM_INT);
$user = required_param('user', PARAM_INT);
if ($confirm && $manager->unassign_role_from_user($user, $role)) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$user = $DB->get_record('user', array('id'=>$user), '*', MUST_EXIST);
$allroles = $manager->get_all_roles();
$role = $allroles[$role];
- $yesurl = new moodle_url($pageurl, array('action'=>'unassign', 'role'=>$role->id, 'user'=>$user->id, 'confirm'=>1, 'sesskey'=>sesskey()));
+ $yesurl = new moodle_url($PAGE->url, array('action'=>'unassign', 'role'=>$role->id, 'user'=>$user->id, 'confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('unassignconfirm', 'role', array('user'=>fullname($user, true), 'role'=>$role->localname));
$pagetitle = get_string('unassignarole', 'role', $role->localname);
- $pagecontent = $OUTPUT->confirm($message, $yesurl, $pageurl);
+ $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
@@ -111,10 +109,10 @@
$user = $DB->get_record('user', array('id'=>required_param('user', PARAM_INT)), '*', MUST_EXIST);
if (is_enrolled($context, $user) && has_capability('moodle/role:assign', $manager->get_context())) {
$mform = new enrol_users_assign_form(NULL, array('user'=>$user, 'course'=>$course, 'assignable'=>$manager->get_assignable_roles()));
- $mform->set_data($pageurl->params());
+ $mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || ($data && array_key_exists($data->roleid, $manager->get_assignable_roles()) && $manager->assign_role_to_user($data->roleid, $user->id))) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$pagetitle = get_string('assignroles', 'role');
}
@@ -130,16 +128,16 @@
$userid = required_param('user', PARAM_INT);
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
if ($confirm && $manager->remove_user_from_group($user, $groupid)) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$group = $manager->get_group($groupid);
if (!$group) {
break;
}
- $yesurl = new moodle_url($pageurl, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey()));
+ $yesurl = new moodle_url($PAGE->url, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid, 'confirm'=>1, 'sesskey'=>sesskey()));
$message = get_string('removefromgroupconfirm', 'group', array('user'=>fullname($user, true), 'group'=>$group->name));
$pagetitle = get_string('removefromgroup', 'group', $group->name);
- $pagecontent = $OUTPUT->confirm($message, $yesurl, $pageurl);
+ $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
}
$actiontaken = true;
}
@@ -153,10 +151,10 @@
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
$mform = new enrol_users_addmember_form(NULL, array('user'=>$user, 'course'=>$course, 'allgroups'=>$manager->get_all_groups()));
- $mform->set_data($pageurl->params());
+ $mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || ($data && $manager->add_user_to_group($user, $data->groupid))) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$pagetitle = get_string('addgroup', 'group');
}
@@ -172,10 +170,10 @@
if ($instance && $plugin && $plugin->allow_manage($instance) && has_capability("enrol/$instance->enrol:manage", $manager->get_context())) {
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
$mform = new enrol_users_edit_form(NULL, array('user'=>$user, 'course'=>$course, 'ue'=>$ue));
- $mform->set_data($pageurl->params());
+ $mform->set_data($PAGE->url->params());
$data = $mform->get_data();
if ($mform->is_cancelled() || ($data && $manager->edit_enrolment($ue, $data))) {
- redirect($pageurl);
+ redirect($PAGE->url);
} else {
$pagetitle = fullname($user);
}
@@ -220,12 +218,12 @@
$table->set_fields($fields, $renderer);
$canassign = has_capability('moodle/role:assign', $manager->get_context());
-$users = $manager->get_users_for_display($renderer, $pageurl, $table->sort, $table->sortdirection, $table->page, $table->perpage);
+$users = $manager->get_users_for_display($renderer, $PAGE->url, $table->sort, $table->sortdirection, $table->page, $table->perpage);
foreach ($users as $userid=>&$user) {
$user['picture'] = $OUTPUT->render($user['picture']);
- $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $manager->get_assignable_roles(), $canassign, $pageurl);
- $user['group'] = $renderer->user_groups_and_actions($userid, $user['groups'], $manager->get_all_groups(), has_capability('moodle/course:managegroups', $manager->get_context()), $pageurl);
- $user['enrol'] = $renderer->user_enrolments_and_actions($userid, $user['enrolments'], $pageurl);
+ $user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $manager->get_assignable_roles(), $canassign, $PAGE->url);
+ $user['group'] = $renderer->user_groups_and_actions($userid, $user['groups'], $manager->get_all_groups(), has_capability('moodle/course:managegroups', $manager->get_context()), $PAGE->url);
+ $user['enrol'] = $renderer->user_enrolments_and_actions($userid, $user['enrolments'], $PAGE->url);
}
$table->set_total_users($manager->get_total_users());
$table->set_users($users);

0 comments on commit 161ba40

Please sign in to comment.
Something went wrong with that request. Please try again.