Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-23532 enrol - moved UI enrolment components from core enrol to th…

…eir respective enrolment plugins
  • Loading branch information...
commit b69ca6bee44fb7a746ae61de1018a7a127daee55 1 parent 4452ed6
Sam Hemelryk samhemelryk authored
70 enrol/cohort/lib.php
@@ -64,32 +64,40 @@ public function get_instance_name($instance) {
64 64 * @return moodle_url page url
65 65 */
66 66 public function get_newinstance_link($courseid) {
  67 + if (!$this->can_add_new_instances($courseid)) {
  68 + return NULL;
  69 + }
  70 + // multiple instances supported - multiple parent courses linked
  71 + return new moodle_url('/enrol/cohort/addinstance.php', array('id'=>$courseid));
  72 + }
  73 +
  74 + /**
  75 + * Given a courseid this function returns true if the user is able to enrol or configure cohorts
  76 + * AND there are cohorts that the user can view.
  77 + *
  78 + * @param int $courseid
  79 + * @return bool
  80 + */
  81 + protected function can_add_new_instances($courseid) {
67 82 global $DB;
68 83
69 84 $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
70 85 if (!has_capability('moodle/course:enrolconfig', $coursecontext) or !has_capability('enrol/cohort:config', $coursecontext)) {
71   - return NULL;
  86 + return false;
72 87 }
73   -
74 88 list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
75 89 $sql = "SELECT id, contextid
76 90 FROM {cohort}
77 91 WHERE contextid $sqlparents
78 92 ORDER BY name ASC";
79 93 $cohorts = $DB->get_records_sql($sql, $params);
80   - $found = false;
81 94 foreach ($cohorts as $c) {
82 95 $context = get_context_instance_by_id($c->contextid);
83 96 if (has_capability('moodle/cohort:view', $context)) {
84   - $found = true;
85   - break;
  97 + return true;
86 98 }
87 99 }
88   - if (!$found) {
89   - return NULL;
90   - }
91   - // multiple instances supported - multiple parent courses linked
92   - return new moodle_url('/enrol/cohort/addinstance.php', array('id'=>$courseid));
  100 + return false;
93 101 }
94 102
95 103 /**
@@ -129,6 +137,48 @@ public function course_updated($inserted, $course, $data) {
129 137 }
130 138
131 139 }
  140 +
  141 + /**
  142 + * Returns a button to enrol a cohort or its users through the manual enrolment plugin.
  143 + *
  144 + * This function also adds a quickenrolment JS ui to the page so that users can be enrolled
  145 + * via AJAX.
  146 + *
  147 + * @global moodle_page $PAGE
  148 + * @param course_enrolment_manager $manager
  149 + * @return enrol_user_button
  150 + */
  151 + public function get_manual_enrol_button(course_enrolment_manager $manager) {
  152 + global $PAGE;
  153 +
  154 + $course = $manager->get_course();
  155 + if (!$this->can_add_new_instances($course->id)) {
  156 + return false;
  157 + }
  158 +
  159 + $cohorturl = new moodle_url('/enrol/cohort/addinstance.php', array('id' => $course->id));
  160 + $button = new enrol_user_button($cohorturl, get_string('enrolcohort', 'enrol'), 'get');
  161 + $button->class .= ' enrol_cohort_plugin';
  162 +
  163 + $button->strings_for_js(array('enrol','synced','enrolcohort','enrolcohortusers'), 'enrol');
  164 + $button->strings_for_js('assignroles', 'role');
  165 + $button->strings_for_js('cohort', 'cohort');
  166 + $button->strings_for_js('users', 'moodle');
  167 +
  168 + // No point showing this at all if the user cant manually enrol users
  169 + $hasmanualinstance = has_capability('enrol/manual:manage', $manager->get_context()) && $manager->has_instance('manual');
  170 +
  171 + $modules = array('moodle-enrol_cohort-quickenrolment', 'moodle-enrol_cohort-quickenrolment-skin');
  172 + $function = 'M.enrol_cohort.quickenrolment.init';
  173 + $arguments = array(
  174 + 'courseid' => $course->id,
  175 + 'ajaxurl' => '/enrol/ajax.php',
  176 + 'url' => $PAGE->url->out(false),
  177 + 'manualEnrolment' => $hasmanualinstance);
  178 + $button->require_yui_module($modules, $function, array($arguments));
  179 +
  180 + return $button;
  181 + }
132 182 }
133 183
134 184
0  ...rolment/assets/skins/sam/quickcohortenrolment.css → ...uickenrolment/assets/skins/sam/quickenrolment.css
File renamed without changes
0  .../quickcohortenrolment/assets/skins/sam/sprite.png → ...rt/yui/quickenrolment/assets/skins/sam/sprite.png
File renamed without changes
8 .../yui/quickcohortenrolment/quickcohortenrolment.js → enrol/cohort/yui/quickenrolment/quickenrolment.js
... ... @@ -1,4 +1,4 @@
1   -YUI.add('moodle-enrol-quickcohortenrolment', function(Y) {
  1 +YUI.add('moodle-enrol_cohort-quickenrolment', function(Y) {
2 2
3 3 var CONTROLLERNAME = 'Quick cohort enrolment controller',
4 4 COHORTNAME = 'Cohort',
@@ -71,7 +71,7 @@ YUI.add('moodle-enrol-quickcohortenrolment', function(Y) {
71 71 this.on('defaultcohortroleloaded', this.updateContent, this, panel);
72 72 close.on('click', this.hide, this);
73 73
74   - Y.all('.enrolcohortbutton input').each(function(node){
  74 + Y.all('.enrol_cohort_plugin input').each(function(node){
75 75 if (node.getAttribute('type', 'submit')) {
76 76 node.on('click', this.show, this);
77 77 }
@@ -332,8 +332,8 @@ YUI.add('moodle-enrol-quickcohortenrolment', function(Y) {
332 332 });
333 333 Y.augment(COHORT, Y.EventTarget);
334 334
335   - M.enrol = M.enrol || {};
336   - M.enrol.quickcohortenrolment = {
  335 + M.enrol_cohort = M.enrol || {};
  336 + M.enrol_cohort.quickenrolment = {
337 337 init : function(cfg) {
338 338 new CONTROLLER(cfg);
339 339 }
135 enrol/locallib.php
@@ -986,6 +986,141 @@ public function get_users_for_display(core_enrol_renderer $renderer, moodle_url
986 986 }
987 987 return $userdetails;
988 988 }
  989 +
  990 + public function get_manual_enrol_buttons() {
  991 + $plugins = $this->get_enrolment_plugins();
  992 + $buttons = array();
  993 + foreach ($plugins as $plugin) {
  994 + $newbutton = $plugin->get_manual_enrol_button($this);
  995 + if (is_array($newbutton)) {
  996 + $buttons += $newbutton;
  997 + } else if ($newbutton instanceof enrol_user_button) {
  998 + $buttons[] = $newbutton;
  999 + }
  1000 + }
  1001 + return $buttons;
  1002 + }
  1003 +
  1004 + public function has_instance($enrolpluginname) {
  1005 + // Make sure manual enrolments instance exists
  1006 + foreach ($this->get_enrolment_instances() as $instance) {
  1007 + if ($instance->enrol == $enrolpluginname) {
  1008 + return true;
  1009 + }
  1010 + }
  1011 + return false;
  1012 + }
  1013 +}
  1014 +
  1015 +/**
  1016 + * A button that is used to enrol users in a course
  1017 + *
  1018 + * @copyright 2010 Sam Hemelryk
  1019 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  1020 + */
  1021 +class enrol_user_button extends single_button {
  1022 +
  1023 + /**
  1024 + * An array containing JS YUI modules required by this button
  1025 + * @var array
  1026 + */
  1027 + protected $jsyuimodules = array();
  1028 +
  1029 + /**
  1030 + * An array containing JS initialisation calls required by this button
  1031 + * @var array
  1032 + */
  1033 + protected $jsinitcalls = array();
  1034 +
  1035 + /**
  1036 + * An array strings required by JS for this button
  1037 + * @var array
  1038 + */
  1039 + protected $jsstrings = array();
  1040 +
  1041 + /**
  1042 + * Initialises the new enrol_user_button
  1043 + *
  1044 + * @staticvar int $count The number of enrol user buttons already created
  1045 + * @param moodle_url $url
  1046 + * @param string $label The text to display in the button
  1047 + * @param string $method Either post or get
  1048 + */
  1049 + public function __construct(moodle_url $url, $label, $method = 'post') {
  1050 + static $count = 0;
  1051 + $count ++;
  1052 + parent::__construct($url, $label, $method);
  1053 + $this->class = 'singlebutton enrolusersbutton';
  1054 + $this->formid = 'enrolusersbutton-'.$count;
  1055 + }
  1056 +
  1057 + /**
  1058 + * Adds a YUI module call that will be added to the page when the button is used.
  1059 + *
  1060 + * @param string|array $modules One or more modules to require
  1061 + * @param string $function The JS function to call
  1062 + * @param array $arguments An array of arguments to pass to the function
  1063 + * @param string $galleryversion The YUI gallery version of any modules required
  1064 + * @param bool $ondomready If true the call is postponed until the DOM is finished loading
  1065 + */
  1066 + public function require_yui_module($modules, $function, array $arguments = null, $galleryversion = '2010.04.08-12-35', $ondomready = false) {
  1067 + $js = new stdClass;
  1068 + $js->modules = (array)$modules;
  1069 + $js->function = $function;
  1070 + $js->arguments = $arguments;
  1071 + $js->galleryversion = $galleryversion;
  1072 + $js->ondomready = $ondomready;
  1073 + $this->jsyuimodules[] = $js;
  1074 + }
  1075 +
  1076 + /**
  1077 + * Adds a JS initialisation call to the page when the button is used.
  1078 + *
  1079 + * @param string $function The function to call
  1080 + * @param array $extraarguments An array of arguments to pass to the function
  1081 + * @param bool $ondomready If true the call is postponed until the DOM is finished loading
  1082 + * @param array $module A module definition
  1083 + */
  1084 + public function require_js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) {
  1085 + $js = new stdClass;
  1086 + $js->function = $function;
  1087 + $js->extraarguments = $extraarguments;
  1088 + $js->ondomready = $ondomready;
  1089 + $js->module = $module;
  1090 + $this->jsinitcalls[] = $js;
  1091 + }
  1092 +
  1093 + /**
  1094 + * Requires strings for JS that will be loaded when the button is used.
  1095 + *
  1096 + * @param type $identifiers
  1097 + * @param string $component
  1098 + * @param mixed $a
  1099 + */
  1100 + public function strings_for_js($identifiers, $component = 'moodle', $a = null) {
  1101 + $string = new stdClass;
  1102 + $string->identifiers = (array)$identifiers;
  1103 + $string->component = $component;
  1104 + $string->a = $a;
  1105 + $this->jsstrings[] = $string;
  1106 + }
  1107 +
  1108 + /**
  1109 + * Initialises the JS that is required by this button
  1110 + *
  1111 + * @param moodle_page $page
  1112 + */
  1113 + public function initialise_js(moodle_page $page) {
  1114 + foreach ($this->jsyuimodules as $js) {
  1115 + $page->requires->yui_module($js->modules, $js->function, $js->arguments, $js->galleryversion, $js->ondomready);
  1116 + }
  1117 + foreach ($this->jsinitcalls as $js) {
  1118 + $page->requires->js_init_call($js->function, $js->extraarguments, $js->ondomready, $js->module);
  1119 + }
  1120 + foreach ($this->jsstrings as $string) {
  1121 + $page->requires->strings_for_js($string->identifiers, $string->component, $string->a);
  1122 + }
  1123 + }
989 1124 }
990 1125
991 1126 class enrol_ajax_exception extends moodle_exception {
75 enrol/manual/lib.php
@@ -168,6 +168,81 @@ public function add_instance($course, array $fields = NULL) {
168 168
169 169 return parent::add_instance($course, $fields);
170 170 }
  171 +
  172 + /**
  173 + * Returns a button to manually enrol users through the manual enrolment plugin.
  174 + *
  175 + * By default the first manual enrolment plugin instance available in the course is used.
  176 + * If no manual enrolment instances exist within the course then false is returned.
  177 + *
  178 + * This function also adds a quickenrolment JS ui to the page so that users can be enrolled
  179 + * via AJAX.
  180 + *
  181 + * @global moodle_page $PAGE
  182 + * @param course_enrolment_manager $manager
  183 + * @return enrol_user_button
  184 + */
  185 + public function get_manual_enrol_button(course_enrolment_manager $manager) {
  186 + global $PAGE;
  187 +
  188 + $instance = null;
  189 + $instances = array();
  190 + foreach ($manager->get_enrolment_instances() as $tempinstance) {
  191 + if ($tempinstance->enrol == 'manual') {
  192 + if ($instance === null) {
  193 + $instance = $tempinstance;
  194 + }
  195 + $instances[] = array('id' => $tempinstance->id, 'name' => $this->get_instance_name($tempinstance));
  196 + }
  197 + }
  198 + if (empty($instance)) {
  199 + return false;
  200 + }
  201 +
  202 + $button = new enrol_user_button($this->get_manual_enrol_link($instance), get_string('enrolusers', 'enrol_manual'), 'get');
  203 + $button->class .= ' enrol_manual_plugin';
  204 +
  205 + $startdate = $manager->get_course()->startdate;
  206 + $startdateoptions = array();
  207 + $timeformat = get_string('strftimedatefullshort');
  208 + if ($startdate > 0) {
  209 + $today = time();
  210 + $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
  211 + $startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $timeformat) . ')';
  212 + }
  213 + $startdateoptions[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
  214 +
  215 + $modules = array('moodle-enrol_manual-quickenrolment', 'moodle-enrol_manual-quickenrolment-skin');
  216 + $arguments = array(
  217 + 'instances' => $instances,
  218 + 'courseid' => $instance->courseid,
  219 + 'ajaxurl' => '/enrol/ajax.php',
  220 + 'url' => $PAGE->url->out(false),
  221 + 'optionsStartDate' => $startdateoptions,
  222 + 'defaultRole' => $instance->roleid
  223 + );
  224 + $function = 'M.enrol_manual.quickenrolment.init';
  225 + $button->require_yui_module($modules, $function, array($arguments));
  226 + $button->strings_for_js(array(
  227 + 'ajaxoneuserfound',
  228 + 'ajaxxusersfound',
  229 + 'ajaxnext25',
  230 + 'enrol',
  231 + 'enrolmentoptions',
  232 + 'enrolusers',
  233 + 'errajaxfailedenrol',
  234 + 'errajaxsearch',
  235 + 'none',
  236 + 'usersearch',
  237 + 'unlimitedduration',
  238 + 'startdatetoday',
  239 + 'durationdays',
  240 + 'enrolperiod'), 'enrol');
  241 + $button->strings_for_js('assignroles', 'role');
  242 + $button->strings_for_js('startingfrom', 'moodle');
  243 +
  244 + return $button;
  245 + }
171 246 }
172 247
173 248 /**
0  ...mentmanager/assets/skins/sam/enrolmentmanager.css → ...uickenrolment/assets/skins/sam/quickenrolment.css
File renamed without changes
0  .../yui/enrolmentmanager/assets/skins/sam/sprite.png → ...al/yui/quickenrolment/assets/skins/sam/sprite.png
File renamed without changes
9 enrol/yui/enrolmentmanager/enrolmentmanager.js → enrol/manual/yui/quickenrolment/quickenrolment.js
... ... @@ -1,4 +1,4 @@
1   -YUI.add('moodle-enrol-enrolmentmanager', function(Y) {
  1 +YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
2 2
3 3 var UEP = {
4 4 NAME : 'Enrolment Manager',
@@ -116,7 +116,7 @@ YUI.add('moodle-enrol-enrolmentmanager', function(Y) {
116 116 );
117 117
118 118 this.set(UEP.SEARCH, this.get(UEP.BASE).one('#enrolusersearch'));
119   - Y.all('.enrolusersbutton input').each(function(node){
  119 + Y.all('.enrol_manual_plugin input').each(function(node){
120 120 if (node.getAttribute('type', 'submit')) {
121 121 node.on('click', this.show, this);
122 122 }
@@ -506,9 +506,8 @@ YUI.add('moodle-enrol-enrolmentmanager', function(Y) {
506 506 });
507 507 Y.augment(USERENROLLER, Y.EventTarget);
508 508
509   -
510   - M.enrol = M.enrol || {};
511   - M.enrol.enrolmentmanager = {
  509 + M.enrol_manual = M.enrol_manual || {};
  510 + M.enrol_manual.quickenrolment = {
512 511 init : function(cfg) {
513 512 new USERENROLLER(cfg);
514 513 }
241 enrol/renderer.php
@@ -42,31 +42,85 @@ protected function render_course_enrolment_users_table(course_enrolment_users_ta
42 42
43 43 $table->initialise_javascript();
44 44
45   - $content = '';
46   - $enrolmentselector = $table->get_enrolment_selector();
47   - if ($enrolmentselector) {
48   - $content .= $this->output->render($enrolmentselector);
  45 + $buttons = $table->get_manual_enrol_buttons();
  46 + $buttonhtml = '';
  47 + if (count($buttons) > 0) {
  48 + $buttonhtml .= html_writer::start_tag('div', array('class' => 'enrol_user_buttons'));
  49 + foreach ($buttons as $button) {
  50 + $buttonhtml .= $this->render($button);
  51 + }
  52 + $buttonhtml .= html_writer::end_tag('div');
49 53 }
50   - $cohortenroller = $table->get_cohort_enrolment_control();
51   - if ($cohortenroller) {
52   - $content .= $this->output->render($cohortenroller);
  54 +
  55 + $content = '';
  56 + if (!empty($buttonhtml)) {
  57 + $content .= $buttonhtml;
53 58 }
54   - $content .= $this->output->render($table->get_enrolment_type_filter());
  59 + $content .= $this->output->render($table->get_enrolment_type_filter());
55 60 $content .= $this->output->render($table->get_paging_bar());
56 61 $content .= html_writer::table($table);
57 62 $content .= $this->output->render($table->get_paging_bar());
58   - $enrolmentselector = $table->get_enrolment_selector();
59   - if ($enrolmentselector) {
60   - $content .= $this->output->render($enrolmentselector);
61   - }
62   - $cohortenroller = $table->get_cohort_enrolment_control();
63   - if ($cohortenroller) {
64   - $content .= $this->output->render($cohortenroller);
  63 + if (!empty($buttonhtml)) {
  64 + $content .= $buttonhtml;
65 65 }
66 66 return $content;
67 67 }
68 68
69 69 /**
  70 + * Renderers the enrol_user_button.
  71 + *
  72 + * @param enrol_user_button $button
  73 + * @return string XHTML
  74 + */
  75 + protected function render_enrol_user_button(enrol_user_button $button) {
  76 + $attributes = array('type' => 'submit',
  77 + 'value' => $button->label,
  78 + 'disabled' => $button->disabled ? 'disabled' : null,
  79 + 'title' => $button->tooltip);
  80 +
  81 + if ($button->actions) {
  82 + $id = html_writer::random_id('single_button');
  83 + $attributes['id'] = $id;
  84 + foreach ($button->actions as $action) {
  85 + $this->add_action_handler($action, $id);
  86 + }
  87 + }
  88 + $button->initialise_js($this->page);
  89 +
  90 + // first the input element
  91 + $output = html_writer::empty_tag('input', $attributes);
  92 +
  93 + // then hidden fields
  94 + $params = $button->url->params();
  95 + if ($button->method === 'post') {
  96 + $params['sesskey'] = sesskey();
  97 + }
  98 + foreach ($params as $var => $val) {
  99 + $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $var, 'value' => $val));
  100 + }
  101 +
  102 + // then div wrapper for xhtml strictness
  103 + $output = html_writer::tag('div', $output);
  104 +
  105 + // now the form itself around it
  106 + if ($button->method === 'get') {
  107 + $url = $button->url->out_omit_querystring(true); // url without params, the anchor part allowed
  108 + } else {
  109 + $url = $button->url->out_omit_querystring(); // url without params, the anchor part not allowed
  110 + }
  111 + if ($url === '') {
  112 + $url = '#'; // there has to be always some action
  113 + }
  114 + $attributes = array('method' => $button->method,
  115 + 'action' => $url,
  116 + 'id' => $button->formid);
  117 + $output = html_writer::tag('form', $output, $attributes);
  118 +
  119 + // and finally one more wrapper with class
  120 + return html_writer::tag('div', $output, array('class' => $button->class));
  121 + }
  122 +
  123 + /**
70 124 * Renders a course enrolment table
71 125 *
72 126 * @param course_enrolment_table $table
@@ -370,6 +424,16 @@ public function __construct(course_enrolment_manager $manager, moodle_page $mood
370 424 }
371 425
372 426 /**
  427 + * Returns an array of enrol_user_buttons that are created by the different
  428 + * enrolment plugins available.
  429 + *
  430 + * @return array
  431 + */
  432 + public function get_manual_enrol_buttons() {
  433 + return $this->manager->get_manual_enrol_buttons();
  434 + }
  435 +
  436 + /**
373 437 * Gets the sort direction for a given field
374 438 *
375 439 * @param string $field
@@ -444,9 +508,6 @@ public function set_total_users($totalusers) {
444 508 }
445 509 }
446 510 /**
447   -
448   - */
449   - /**
450 511 * Sets the users for this table
451 512 *
452 513 * @param array $users
@@ -565,150 +626,6 @@ class course_enrolment_users_table extends course_enrolment_table {
565 626 protected static $sortablefields = array('firstname', 'lastname', 'email', 'lastaccess');
566 627
567 628 /**
568   - * Returns a button to enrol cohorts or thier users
569   - *
570   - * @staticvar int $count
571   - * @return single_button|false
572   - */
573   - public function get_cohort_enrolment_control() {
574   - static $count = 0;
575   -
576   - // First make sure that cohorts is enabled
577   - $plugins = $this->manager->get_enrolment_plugins();
578   - if (!array_key_exists('cohort', $plugins)) {
579   - return false;
580   - }
581   - $course = $this->manager->get_course();
582   - if (!$plugins['cohort']->get_newinstance_link($course->id)) {
583   - // user can not see any cohort === can not use this
584   - return false;
585   - }
586   - $count ++;
587   - $cohorturl = new moodle_url('/enrol/cohort/addinstance.php', array('id'=>$course->id));
588   - $control = new single_button($cohorturl, get_string('enrolcohort', 'enrol'), 'get');
589   - $control->class = 'singlebutton enrolcohortbutton instance'.$count;
590   - $control->formid = 'manuallyenrol_single_'+$count;
591   - if ($count == 1) {
592   - $this->moodlepage->requires->strings_for_js(array('enrol','synced','enrolcohort','enrolcohortusers'), 'enrol');
593   - $this->moodlepage->requires->string_for_js('assignroles', 'role');
594   - $this->moodlepage->requires->string_for_js('cohort', 'cohort');
595   - $this->moodlepage->requires->string_for_js('users', 'moodle');
596   -
597   - $hasmanualinstance = false;
598   - // No point showing this at all if the user cant manually enrol users
599   - if (has_capability('enrol/manual:manage', $this->manager->get_context())) {
600   - // Make sure manual enrolments instance exists
601   - $instances = $this->manager->get_enrolment_instances();
602   - foreach ($instances as $instance) {
603   - if ($instance->enrol == 'manual') {
604   - $hasmanualinstance = true;
605   - break;
606   - }
607   - }
608   - }
609   -
610   - $modules = array('moodle-enrol-quickcohortenrolment', 'moodle-enrol-quickcohortenrolment-skin');
611   - $function = 'M.enrol.quickcohortenrolment.init';
612   - $arguments = array(
613   - 'courseid'=>$course->id,
614   - 'ajaxurl'=>'/enrol/ajax.php',
615   - 'url'=>$this->moodlepage->url->out(false),
616   - 'manualEnrolment'=>$hasmanualinstance);
617   - $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
618   - }
619   - return $control;
620   - }
621   -
622   - /**
623   - * Gets the enrolment selector control for this table and initialises its
624   - * JavaScript
625   - *
626   - * @return single_button|url_select
627   - */
628   - public function get_enrolment_selector() {
629   - global $CFG;
630   - static $count = 0;
631   -
632   - $instances = $this->manager->get_enrolment_instances();
633   - $plugins = $this->manager->get_enrolment_plugins();
634   - $manuals = array();
635   - // print enrol link or selection
636   - $links = array();
637   - foreach($instances as $instance) {
638   - $plugin = $plugins[$instance->enrol];
639   - if ($link = $plugin->get_manual_enrol_link($instance)) {
640   - $links[$instance->id] = $link;
641   - $manuals[$instance->id] = $instance;
642   - }
643   - }
644   - if (!empty($links)) {
645   - $arguments = array();
646   - $count ++;
647   - if (count($links) == 1) {
648   - $control = new single_button(reset($links), get_string('enrolusers', 'enrol_manual'), 'get');
649   - $control->class = 'singlebutton enrolusersbutton instance'.$count;
650   - $control->formid = 'manuallyenrol_single_'+$count;
651   - $arguments[] = array('id'=>key($links), 'name'=>$plugins[$instances[key($links)]->enrol]->get_instance_name($instances[key($links)]));
652   - } else if (count($links) > 1) {
653   - $inames = $this->manager->get_enrolment_instance_names();
654   - $options = array();
655   - foreach ($links as $i=>$link) {
656   - $options[$link->out(false)] = $inames[$i];
657   - $arguments[] = array('id'=>$i, 'name'=>$plugins[$instances[$i]->enrol]->get_instance_name($instances[$i]));
658   - }
659   - $control = new url_select($options, '', array(''=>get_string('enrolusers', 'enrol_manual').'...'));
660   - $control->class = 'singlebutton enrolusersbutton instance'.$count;
661   - $control->formid = 'manuallyenrol_select_'+$count;
662   - }
663   - $course = $this->manager->get_course();
664   - $timeformat = get_string('strftimedatefullshort');
665   - $today = time();
666   - $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
667   - $startdateoptions = array();
668   - if ($course->startdate > 0) {
669   - $startdateoptions[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')';
670   - }
671   - $startdateoptions[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
672   -
673   - if ($count == 1) {
674   - $instance = reset($manuals);
675   - $this->moodlepage->requires->strings_for_js(array(
676   - 'ajaxoneuserfound',
677   - 'ajaxxusersfound',
678   - 'ajaxnext25',
679   - 'enrol',
680   - 'enrolmentoptions',
681   - 'enrolusers',
682   - 'errajaxfailedenrol',
683   - 'errajaxsearch',
684   - 'none',
685   - 'usersearch',
686   - 'unlimitedduration',
687   - 'startdatetoday',
688   - 'durationdays',
689   - 'enrolperiod',
690   - 'finishenrollingusers',
691   - 'recovergrades'), 'enrol');
692   - $this->moodlepage->requires->string_for_js('assignroles', 'role');
693   - $this->moodlepage->requires->string_for_js('startingfrom', 'moodle');
694   -
695   - $modules = array('moodle-enrol-enrolmentmanager', 'moodle-enrol-enrolmentmanager-skin');
696   - $function = 'M.enrol.enrolmentmanager.init';
697   - $arguments = array(
698   - 'instances'=>$arguments,
699   - 'courseid'=>$course->id,
700   - 'ajaxurl'=>'/enrol/ajax.php',
701   - 'url'=>$this->moodlepage->url->out(false),
702   - 'optionsStartDate'=>$startdateoptions,
703   - 'defaultRole'=>$instance->roleid,
704   - 'disableGradeHistory'=>$CFG->disablegradehistory);
705   - $this->moodlepage->requires->yui_module($modules, $function, array($arguments));
706   - }
707   - return $control;
708   - }
709   - return null;
710   - }
711   - /**
712 629 * Gets the enrolment type filter control for this table
713 630 *
714 631 * @return single_select
15 lib/enrollib.php
@@ -1517,5 +1517,18 @@ public function user_delete($user) {
1517 1517 }
1518 1518 $rs->close();
1519 1519 }
1520   -}
1521 1520
  1521 + /**
  1522 + * Returns an enrol_user_button that takes the user to a page where they are able to
  1523 + * enrol users into the managers course through this plugin.
  1524 + *
  1525 + * Optional: If the plugin supports manual enrolments it can choose to override this
  1526 + * otherwise it shouldn't
  1527 + *
  1528 + * @param course_enrolment_manager $manager
  1529 + * @return enrol_user_button|false
  1530 + */
  1531 + public function get_manual_enrol_button(course_enrolment_manager $manager) {
  1532 + return false;
  1533 + }
  1534 +}

0 comments on commit b69ca6b

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