mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 20:50:21 +01:00
MDL-23532 enrol - abstracted user enrolment action icons to the enrolment plugin class
This commit is contained in:
parent
410135aa10
commit
291215f441
@ -817,7 +817,8 @@ class course_enrolment_manager {
|
|||||||
* @param int $perpage
|
* @param int $perpage
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_users_for_display(core_enrol_renderer $renderer, moodle_url $pageurl, $sort, $direction, $page, $perpage) {
|
public function get_users_for_display(course_enrolment_manager $manager, $sort, $direction, $page, $perpage) {
|
||||||
|
$pageurl = $manager->get_moodlepage()->url;
|
||||||
$users = $this->get_users($sort, $direction, $page, $perpage);
|
$users = $this->get_users($sort, $direction, $page, $perpage);
|
||||||
|
|
||||||
$now = time();
|
$now = time();
|
||||||
@ -826,10 +827,6 @@ class course_enrolment_manager {
|
|||||||
$strunenrol = get_string('unenrol', 'enrol');
|
$strunenrol = get_string('unenrol', 'enrol');
|
||||||
$stredit = get_string('edit');
|
$stredit = get_string('edit');
|
||||||
|
|
||||||
$iconedit = $renderer->pix_url('t/edit');
|
|
||||||
$iconenroladd = $renderer->pix_url('t/enroladd');
|
|
||||||
$iconenrolremove = $renderer->pix_url('t/delete');
|
|
||||||
|
|
||||||
$allroles = $this->get_all_roles();
|
$allroles = $this->get_all_roles();
|
||||||
$assignable = $this->get_assignable_roles();
|
$assignable = $this->get_assignable_roles();
|
||||||
$allgroups = $this->get_all_groups();
|
$allgroups = $this->get_all_groups();
|
||||||
@ -887,8 +884,7 @@ class course_enrolment_manager {
|
|||||||
'text' => $ue->enrolmentinstancename,
|
'text' => $ue->enrolmentinstancename,
|
||||||
'period' => $period,
|
'period' => $period,
|
||||||
'dimmed' => ($periodoutside || $ue->status != ENROL_USER_ACTIVE),
|
'dimmed' => ($periodoutside || $ue->status != ENROL_USER_ACTIVE),
|
||||||
'canunenrol' => ($ue->enrolmentplugin->allow_unenrol($ue->enrolmentinstance) && has_capability("enrol/".$ue->enrolmentinstance->enrol.":unenrol", $context)),
|
'actions' => $ue->enrolmentplugin->get_user_enrolment_actions($manager, $ue)
|
||||||
'canmanage' => ($ue->enrolmentplugin->allow_manage($ue->enrolmentinstance) && has_capability("enrol/".$ue->enrolmentinstance->enrol.":manage", $context))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$userdetails[$user->id] = $details;
|
$userdetails[$user->id] = $details;
|
||||||
@ -1032,6 +1028,91 @@ class enrol_user_button extends single_button {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User enrolment action
|
||||||
|
*
|
||||||
|
* This class is used to manage a renderable ue action such as editing an user enrolment or deleting
|
||||||
|
* a user enrolment.
|
||||||
|
*
|
||||||
|
* @copyright 2011 Sam Hemelryk
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
class user_enrolment_action implements renderable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The icon to display for the action
|
||||||
|
* @var pix_icon
|
||||||
|
*/
|
||||||
|
protected $icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The title for the action
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL to the action
|
||||||
|
* @var moodle_url
|
||||||
|
*/
|
||||||
|
protected $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of HTML attributes
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $attributes = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param pix_icon $icon
|
||||||
|
* @param string $title
|
||||||
|
* @param moodle_url $url
|
||||||
|
* @param array $attributes
|
||||||
|
*/
|
||||||
|
public function __construct(pix_icon $icon, $title, $url, array $attributes = null) {
|
||||||
|
$this->icon = $icon;
|
||||||
|
$this->title = $title;
|
||||||
|
$this->url = new moodle_url($url);
|
||||||
|
if (!empty($attributes)) {
|
||||||
|
$this->attributes = $attributes;
|
||||||
|
}
|
||||||
|
$this->attributes['title'] = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the icon for this action
|
||||||
|
* @return pix_icon
|
||||||
|
*/
|
||||||
|
public function get_icon() {
|
||||||
|
return $this->icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the title for this action
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_title() {
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the URL for this action
|
||||||
|
* @return moodle_url
|
||||||
|
*/
|
||||||
|
public function get_url() {
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the attributes to use for this action
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_attributes() {
|
||||||
|
return $this->attributes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class enrol_ajax_exception extends moodle_exception {
|
class enrol_ajax_exception extends moodle_exception {
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -233,33 +233,31 @@ class core_enrol_renderer extends plugin_renderer_base {
|
|||||||
* @param moodle_url $pageurl
|
* @param moodle_url $pageurl
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function user_enrolments_and_actions($userid, $enrolments, $pageurl) {
|
public function user_enrolments_and_actions($enrolments) {
|
||||||
$iconedit = $this->output->pix_url('t/edit');
|
|
||||||
$iconenrolremove = $this->output->pix_url('t/delete');
|
|
||||||
$strunenrol = get_string('unenrol', 'enrol');
|
|
||||||
$stredit = get_string('edit');
|
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
foreach ($enrolments as $ueid=>$enrolment) {
|
foreach ($enrolments as $ue) {
|
||||||
$enrolmentoutput = $enrolment['text'].' '.$enrolment['period'];
|
$enrolmentoutput = $ue['text'].' '.$ue['period'];
|
||||||
if ($enrolment['dimmed']) {
|
if ($ue['dimmed']) {
|
||||||
$enrolmentoutput = html_writer::tag('span', $enrolmentoutput, array('class'=>'dimmed_text'));
|
$enrolmentoutput = html_writer::tag('span', $enrolmentoutput, array('class'=>'dimmed_text'));
|
||||||
|
} else {
|
||||||
|
$enrolmentoutput = html_writer::tag('span', $enrolmentoutput);
|
||||||
}
|
}
|
||||||
if ($enrolment['canunenrol']) {
|
foreach ($ue['actions'] as $action) {
|
||||||
$icon = html_writer::empty_tag('img', array('alt'=>$strunenrol, 'src'=>$iconenrolremove));
|
$enrolmentoutput .= $this->render($action);
|
||||||
$url = new moodle_url($pageurl, array('action'=>'unenrol', 'ue'=>$ueid));
|
|
||||||
$enrolmentoutput .= html_writer::link($url, $icon, array('class'=>'unenrollink', 'rel'=>$ueid));
|
|
||||||
}
|
|
||||||
if ($enrolment['canmanage']) {
|
|
||||||
$icon = html_writer::empty_tag('img', array('alt'=>$stredit, 'src'=>$iconedit));
|
|
||||||
$url = new moodle_url($url, array('action'=>'edit', 'ue'=>$ueid));
|
|
||||||
$enrolmentoutput .= html_writer::link($url, $icon, array('class'=>'editenrollink', 'rel'=>$ueid));
|
|
||||||
}
|
}
|
||||||
$output .= html_writer::tag('div', $enrolmentoutput, array('class'=>'enrolment'));
|
$output .= html_writer::tag('div', $enrolmentoutput, array('class'=>'enrolment'));
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a user enrolment action
|
||||||
|
* @param user_enrolment_action $icon
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function render_user_enrolment_action(user_enrolment_action $icon) {
|
||||||
|
return html_writer::link($icon->get_url(), $this->output->render($icon->get_icon()), $icon->get_attributes());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -221,12 +221,12 @@ $fields = array(
|
|||||||
$table->set_fields($fields, $renderer);
|
$table->set_fields($fields, $renderer);
|
||||||
|
|
||||||
$canassign = has_capability('moodle/role:assign', $manager->get_context());
|
$canassign = has_capability('moodle/role:assign', $manager->get_context());
|
||||||
$users = $manager->get_users_for_display($renderer, $PAGE->url, $table->sort, $table->sortdirection, $table->page, $table->perpage);
|
$users = $manager->get_users_for_display($manager, $table->sort, $table->sortdirection, $table->page, $table->perpage);
|
||||||
foreach ($users as $userid=>&$user) {
|
foreach ($users as $userid=>&$user) {
|
||||||
$user['picture'] = $OUTPUT->render($user['picture']);
|
$user['picture'] = $OUTPUT->render($user['picture']);
|
||||||
$user['role'] = $renderer->user_roles_and_actions($userid, $user['roles'], $manager->get_assignable_roles(), $canassign, $PAGE->url);
|
$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['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);
|
$user['enrol'] = $renderer->user_enrolments_and_actions($user['enrolments']);;
|
||||||
}
|
}
|
||||||
$table->set_total_users($manager->get_total_users());
|
$table->set_total_users($manager->get_total_users());
|
||||||
$table->set_users($users);
|
$table->set_users($users);
|
||||||
|
@ -1531,4 +1531,26 @@ abstract class enrol_plugin {
|
|||||||
public function get_manual_enrol_button(course_enrolment_manager $manager) {
|
public function get_manual_enrol_button(course_enrolment_manager $manager) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Gets an array of the user enrolment actions
|
||||||
|
*
|
||||||
|
* @param course_enrolment_manager $manager
|
||||||
|
* @param stdClass $ue
|
||||||
|
* @return array An array of user_enrolment_actions
|
||||||
|
*/
|
||||||
|
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) {
|
||||||
|
$actions = array();
|
||||||
|
$context = $manager->get_context();
|
||||||
|
$instance = $ue->enrolmentinstance;
|
||||||
|
if ($this->allow_unenrol($instance) && has_capability("enrol/".$instance->enrol.":unenrol", $context)) {
|
||||||
|
$url = new moodle_url($manager->get_moodlepage()->url, array('action' => 'unenrol', 'ue' => $ue->id));
|
||||||
|
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
|
||||||
|
}
|
||||||
|
if ($this->allow_manage($instance) && has_capability("enrol/".$instance->enrol.":manage", $context)) {
|
||||||
|
$url = new moodle_url($manager->get_moodlepage()->url, array('action' => 'edit', 'ue' => $ue->id));
|
||||||
|
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id));
|
||||||
|
}
|
||||||
|
return $actions;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user