diff --git a/ajax.php b/ajax.php index e89b563..352fc90 100644 --- a/ajax.php +++ b/ajax.php @@ -67,22 +67,6 @@ $enrol = enrol_get_plugin('ilios'); switch ($action) { - case 'getassignable': - $otheruserroles = optional_param('otherusers', false, PARAM_BOOL); - $outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true); - break; - case 'getdefaultiliosrole': //TODO: use in ajax UI MDL-24280 - $iliosenrol = enrol_get_plugin('ilios'); - $outcome->response = $iliosenrol->get_config('roleid'); - break; - case 'getcohorts': - require_capability('moodle/course:enrolconfig', $context); - $offset = optional_param('offset', 0, PARAM_INT); - $search = optional_param('search', '', PARAM_RAW); - $outcome->response = enrol_ilios_search_cohorts($manager, $offset, 25, $search); - // Some browsers reorder collections by key. - $outcome->response['cohorts'] = array_values($outcome->response['cohorts']); - break; case 'getselectschooloptions': require_capability('moodle/course:enrolconfig', $context); $http = $enrol->get_http_client(); @@ -93,6 +77,7 @@ } $outcome->response = $schoolarray; break; + case 'getselectprogramoptions': require_capability('moodle/course:enrolconfig', $context); $sid = required_param('filterid', PARAM_INT); // school id @@ -105,6 +90,7 @@ } $outcome->response = $programarray; break; + case 'getselectcohortoptions': require_capability('moodle/course:enrolconfig', $context); $pid = required_param('filterid', PARAM_INT); @@ -203,44 +189,6 @@ $outcome->response = $instructorgroupoptions; break; - case 'enrolilios': - require_capability('moodle/course:enrolconfig', $context); - require_capability('enrol/ilios:config', $context); - $roleid = required_param('roleid', PARAM_INT); - $cohortid = required_param('cohortid', PARAM_INT); - - $roles = $manager->get_assignable_roles(); - if (!enrol_ilios_can_view_cohort($cohortid) || !array_key_exists($roleid, $roles)) { - throw new enrol_ajax_exception('errorenrolilios'); - } - $enrol = enrol_get_plugin('ilios'); - $enrol->add_instance($manager->get_course(), array('customint1' => $cohortid, 'roleid' => $roleid)); - $trace = new null_progress_trace(); - enrol_ilios_sync($trace, $manager->get_course()->id); - $trace->finished(); - break; - case 'enroliliosusers': - //TODO: this should be moved to enrol_manual, see MDL-35618. - require_capability('enrol/manual:enrol', $context); - $roleid = required_param('roleid', PARAM_INT); - $cohortid = required_param('cohortid', PARAM_INT); - - $roles = $manager->get_assignable_roles(); - if (!enrol_ilios_can_view_cohort($cohortid) || !array_key_exists($roleid, $roles)) { - throw new enrol_ajax_exception('errorenrolilios'); - } - - $result = enrol_ilios_enrol_all_users($manager, $cohortid, $roleid); - if ($result === false) { - throw new enrol_ajax_exception('errorenroliliosusers'); - } - - $outcome->success = true; - $outcome->response->users = $result; - $outcome->response->title = get_string('success'); - $outcome->response->message = get_string('enrollednewusers', 'enrol', $result); - $outcome->response->yesLabel = get_string('ok'); - break; default: throw new enrol_ajax_exception('unknowajaxaction'); } diff --git a/edit_form.php b/edit_form.php index 5aedcff..6559c4b 100644 --- a/edit_form.php +++ b/edit_form.php @@ -53,8 +53,7 @@ function definition() { $mform->addElement('select', 'status', get_string('status', 'enrol_ilios'), $options); - // TODO: Move this into 'if ($instance->id)'. - $usertypes = array('Learner', 'Instructor'); + $usertypes = array(get_string('learner', 'enrol_ilios'), get_string('instructor', 'enrol_ilios')); $schooloptions = array('' => get_string('choosedots')); $programoptions = array('' => get_string('choosedots')); $cohortoptions = array('' => get_string('choosedots')); diff --git a/lang/en/enrol_ilios.php b/lang/en/enrol_ilios.php index 0e0f637..27ec374 100644 --- a/lang/en/enrol_ilios.php +++ b/lang/en/enrol_ilios.php @@ -34,10 +34,6 @@ $string['defaultlearnerrole'] = 'Default learner role'; $string['defaultinstructorrole'] = 'Default instructor role'; $string['enrol'] = 'Enrol Ilios users'; -$string['enrolilios'] = 'Enrol Ilios cohort/learner group/users'; -$string['enrolilioscohort'] = 'Enrol cohort'; -$string['enroliliosgroup'] = 'Enrol group'; -$string['enroliliosusers'] = 'Enrol users'; $string['enrolusers'] = 'Enrol users'; $string['host_url'] = 'Host URL'; $string['host_url_desc'] = 'Type Ilios server IP address or host URL.'; @@ -48,6 +44,8 @@ $string['ilios:config'] = 'Configure ilios instances'; $string['ilios:unenrol'] = 'Unenrol suspended users'; $string['instanceexists'] = 'Ilios sync is already synchronised with selected role'; +$string['instructor'] = 'Instructor'; +$string['learner'] = 'Learner'; $string['learnergroup'] = 'Learner group (sub-groups) (learners)'; $string['learnergroup_help'] = 'This corresponds to the Learner groups in Ilios'; $string['learnergroupoptionsupdate'] = 'Update learner group options'; diff --git a/lang/en_us/enrol_ilios.php b/lang/en_us/enrol_ilios.php index 55e5f48..014bdd8 100644 --- a/lang/en_us/enrol_ilios.php +++ b/lang/en_us/enrol_ilios.php @@ -34,10 +34,6 @@ $string['defaultlearnerrole'] = 'Default learner role'; $string['defaultinstructorrole'] = 'Default instructor role'; $string['enrol'] = 'Enroll Ilios users'; -$string['enrolilios'] = 'Enroll Ilios cohort/learner group/users'; -$string['enrolilioscohort'] = 'Enroll cohort'; -$string['enroliliosgroup'] = 'Enroll group'; -$string['enroliliosusers'] = 'Enroll users'; $string['enrolusers'] = 'Enroll users'; $string['host_url'] = 'Host URL'; $string['host_url_desc'] = 'Type Ilios server IP address or host URL.'; @@ -48,6 +44,8 @@ $string['ilios:config'] = 'Configure ilios instances'; $string['ilios:unenrol'] = 'Unenroll suspended users'; $string['instanceexists'] = 'Ilios sync is already synchronized with selected role'; +$string['instructor'] = 'Instructor'; +$string['learner'] = 'Learner'; $string['learnergroup'] = 'Learner group (sub-groups) (learners)'; $string['learnergroup_help'] = 'This corresponds to the Learner groups in Ilios'; $string['learnergroupoptionsupdate'] = 'Update learner group options'; diff --git a/lib.php b/lib.php index 589a92a..8aee322 100644 --- a/lib.php +++ b/lib.php @@ -289,9 +289,6 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u /** * Returns a button to enrol a ilios or its users through the manual enrolment plugin. * - * This function also adds a quickenrolment JS ui to the page so that users can be enrolled - * via AJAX. - * * @param course_enrolment_manager $manager * @return enrol_user_button */ @@ -303,39 +300,6 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) { $iliosurl = new moodle_url('/enrol/ilios/edit.php', array('courseid' => $course->id)); $button = new enrol_user_button($iliosurl, get_string('enrol', 'enrol_ilios'), 'get'); - $button->class .= ' enrol_ilios_plugin'; - - $button->strings_for_js(array( - 'enrol', - 'synced', - ), 'enrol'); - $button->strings_for_js(array( - 'ajaxmore', - 'enrolilios', - 'enrolilioscohort', - 'enroliliosgroup', - 'enroliliosusers', - 'iliosgroups', - 'iliosgroupsearch', - 'school', - 'program', - 'cohort' - ), 'enrol_ilios'); - $button->strings_for_js('assignroles', 'role'); - $button->strings_for_js('ilios', 'enrol_ilios'); - $button->strings_for_js('users', 'moodle'); - - // No point showing this at all if the user cant manually enrol users. - $hasmanualinstance = has_capability('enrol/manual:enrol', $manager->get_context()) && $manager->has_instance('manual'); - - $modules = array('moodle-enrol_ilios-quickenrolment', 'moodle-enrol_ilios-quickenrolment-skin'); - $function = 'M.enrol_ilios.quickenrolment.init'; - $arguments = array( - 'courseid' => $course->id, - 'ajaxurl' => '/enrol/ilios/ajax.php', - 'url' => $manager->get_moodlepage()->url->out(false), - 'manualEnrolment' => $hasmanualinstance); - $button->require_yui_module($modules, $function, array($arguments)); return $button; } diff --git a/locallib.php b/locallib.php index 23a1ba4..da6a640 100644 --- a/locallib.php +++ b/locallib.php @@ -232,150 +232,3 @@ function enrol_ilios_sync(progress_trace $trace, $courseid = NULL) { return 0; } - -/** - * Enrols all of the users in a cohort through a manual plugin instance. - * - * In order for this to succeed the course must contain a valid manual - * enrolment plugin instance that the user has permission to enrol users through. - * - * @global moodle_database $DB - * @param course_enrolment_manager $manager - * @param int $cohortid - * @param int $roleid - * @return int - */ - -// DISABLED: This is being called by ajax.php. // TODO: Update this to take learner group id -function enrol_ilios_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) { - global $DB; - $context = $manager->get_context(); - require_capability('moodle/course:enrolconfig', $context); - - $instance = false; - $instances = $manager->get_enrolment_instances(); - foreach ($instances as $i) { - if ($i->enrol == 'manual') { - $instance = $i; - break; - } - } - $plugin = enrol_get_plugin('manual'); - if (!$instance || !$plugin || !$plugin->allow_enrol($instance) || !has_capability('enrol/'.$plugin->get_name().':enrol', $context)) { - return false; - } - $sql = "SELECT com.userid - FROM {cohort_members} com - LEFT JOIN ( - SELECT * - FROM {user_enrolments} ue - WHERE ue.enrolid = :enrolid - ) ue ON ue.userid=com.userid - WHERE com.cohortid = :cohortid AND ue.id IS NULL"; - $params = array('cohortid' => $cohortid, 'enrolid' => $instance->id); - $rs = $DB->get_recordset_sql($sql, $params); - $count = 0; - foreach ($rs as $user) { - $count++; - $plugin->enrol_user($instance, $user->userid, $roleid); - } - $rs->close(); - return $count; -} - -/** - * Check if cohort exists and user is allowed to enrol it. - * - * @global moodle_database $DB - * @param int $cohortid Ilios enrolment ID - * @return boolean - */ -// TODO: Being called by ajax.php. Not really needed. -function enrol_ilios_can_view_cohort($cohortid) { - global $DB; - $ilios = $DB->get_record('ilios', array('id' => $cohortid), 'id, contextid'); - if ($ilios) { - $context = context::instance_by_id($ilios->contextid); - if (has_capability('moodle/cohort:view', $context)) { - return true; - } - } - return false; -} - -/** - * Gets cohorts the user is able to view. - * - * @global moodle_database $DB - * @param course_enrolment_manager $manager - * @param int $offset limit output from - * @param int $limit items to output per load - * @param string $search search string - * @return array Array(more => bool, offset => int, cohorts => array) - */ -// TODO: Update to search learner groups -function enrol_ilios_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') { - global $DB; - $context = $manager->get_context(); - $cohorts = array(); - $instances = $manager->get_enrolment_instances(); - $enrolled = array(); - foreach ($instances as $instance) { - if ($instance->enrol == 'ilios') { - $enrolled[] = $instance->customint1; - } - } - - list($sqlparents, $params) = $DB->get_in_or_equal($context->get_parent_context_ids()); - - // Add some additional sensible conditions. - $tests = array('contextid ' . $sqlparents); - - // Modify the query to perform the search if required. - if (!empty($search)) { - $conditions = array( - 'name', - 'idnumber', - 'description' - ); - $searchparam = '%' . $DB->sql_like_escape($search) . '%'; - foreach ($conditions as $key=>$condition) { - $conditions[$key] = $DB->sql_like($condition, "?", false); - $params[] = $searchparam; - } - $tests[] = '(' . implode(' OR ', $conditions) . ')'; - } - $wherecondition = implode(' AND ', $tests); - - $sql = "SELECT id, name, idnumber, contextid, description - FROM {cohort} - WHERE $wherecondition - ORDER BY name ASC, idnumber ASC"; - $rs = $DB->get_recordset_sql($sql, $params, $offset); - - // Produce the output respecting parameters. - foreach ($rs as $c) { - // Track offset. - $offset++; - // Check capabilities. - $context = context::instance_by_id($c->contextid); - if (!has_capability('moodle/cohort:view', $context)) { - continue; - } - if ($limit === 0) { - // We have reached the required number of items and know that there are more, exit now. - $offset--; - break; - } - $cohorts[$c->id] = array( - 'cohortid' => $c->id, - 'name' => shorten_text(format_string($c->name, true, array('context'=>context::instance_by_id($c->contextid))), 35), - 'users' => $DB->count_records('cohort_members', array('cohortid'=>$c->id)), - 'enrolled' => in_array($c->id, $enrolled) - ); - // Count items. - $limit--; - } - $rs->close(); - return array('more' => !(bool)$limit, 'offset' => $offset, 'cohorts' => $cohorts); -} diff --git a/yui/quickenrolment/assets/skins/sam/quickenrolment.css b/yui/quickenrolment/assets/skins/sam/quickenrolment.css deleted file mode 100644 index faa5791..0000000 --- a/yui/quickenrolment/assets/skins/sam/quickenrolment.css +++ /dev/null @@ -1,46 +0,0 @@ -.qce-panel {background-color:#666;border:2px solid #666;border-width:0 2px 2px 0;min-width:420px;} -.qce-panel .yui3-widget-hd {background:url("sprite.png");background-repeat:repeat-x;background-color:#DDD;background-position: 0 -15px;border-bottom:1px solid #555;border-top:1px solid #fff;} -.qce-panel .yui3-widget-hd h2 {margin:3px 5px 2px;padding:0;font-size:110%;} -.qce-panel .yui3-widget-hd .close {width:25px;height:15px;position:absolute;top:3px;right:1em;cursor:pointer;background:url("sprite.png") no-repeat scroll 0 0 transparent;} -.dir-rtl .qce-panel .yui3-widget-hd .close {right:auto;left:1em;} -.qce-panel .yui3-overlay-content {background-color:#F6F6F6;border:1px solid #555;margin-top:-2px;margin-left:-2px;} -.qce-panel .qce-enrollable-ilios-groups {margin:5px;} -.qce-panel .qce-cohorts {border:1px solid #666;min-width:408px;background-color:#FFF;height:375px;overflow:auto;} -.qce-panel .qce-cohorts .qce-more-results {background-color:#eee;padding:5px;border-top:1px solid #BBB;text-align:center;} - -.qce-panel .qce-panel-content {min-height:405px;} -.qce-panel .qce-panel-content .qce-loading-lightbox {position:absolute;width:100%;height:100%;top:0;left:0;background-color:#FFF;min-height:264px;text-align:center;} -.qce-panel .qce-panel-content .qce-loading-lightbox.hidden {display:none;} -.qce-panel .qce-panel-content .qce-loading-lightbox .loading-icon {margin:auto;vertical-align:middle;margin-top:198px;} - -.qce-panel .qce-cohort {width:100%;position:relative;clear:both;height:24px;white-space:nowrap;} -.qce-panel .qce-cohort div {display:inline-block;overflow:hidden;} -.qce-panel .qce-cohort.odd {background-color:#f4f4f4;} -.qce-panel .qce-cohort .qce-cohort-button {text-align:center;display:inline-block;font-size:80%;height:22px;line-height:22px;overflow:hidden;padding:0 4px;} -.qce-panel .qce-cohort .qce-cohort-button.notenrolled {background-color:#ddd;border:1px outset #CCC;background:url("sprite.png");background-repeat:repeat-x;background-color:#DDD;background-position: 0 -25px;color:inherit;} -.qce-panel .qce-cohort .qce-cohort-button.notenrolled:hover {background-position:0 -15px;cursor:pointer;} -.qce-panel .qce-cohort .qce-cohort-button.notenrolled.enrolusers {margin-right: 4px;} -.qce-panel .qce-cohort .qce-cohort-button.alreadyenrolled {font-weight:bold;} -.qce-panel .qce-cohort .qce-cohort-name {line-height:24px;width:220px;} -.qce-panel .canenrolusers .qce-cohort .qce-cohort-button.alreadyenrolled {width:125px;} -.qce-panel .canenrolusers .qce-cohort .qce-cohort-name {line-height:24px;} -.qce-panel .qce-cohort .qce-cohort-users {width:30px;text-align:right;height:24px;line-height:24px;margin-right:4px} - -.qce-panel .qce-ilios-schools {margin:5px 6px 0 6px;} -.qce-panel .qce-ilios-schools label {padding-right:8px;} -.qce-panel .qce-ilios-programs {margin:5px 6px 0 6px;} -.qce-panel .qce-ilios-programs label {padding-right:8px;} -.qce-panel .qce-ilios-cohorts {margin:5px 6px 0 6px;} -.qce-panel .qce-ilios-cohorts label {padding-right:8px;} -.qce-panel .qce-assignable-roles {margin:5px 6px 0 6px;} -.qce-panel .qce-assignable-roles label {padding-right:8px;} - -.qce-panel .qce-footer {margin:0 6px 5px 6px;} -.qce-panel .qce-search label {padding-right:8px;} -.qce-panel .qce-search input {width:70%;} - -.qce-panel .qce-cohort.headings {font-weight:bold;border-width:0;} -.qe-panel .qce-cohort.headings .qce-cohort-button {display:none;} - -.ie7 .qce-panel .qce-cohort div, -.ie7 .qce-panel .canenrolusers .qce-cohort .qce-cohort-name {float:left;} diff --git a/yui/quickenrolment/assets/skins/sam/sprite.png b/yui/quickenrolment/assets/skins/sam/sprite.png deleted file mode 100644 index 067c225..0000000 Binary files a/yui/quickenrolment/assets/skins/sam/sprite.png and /dev/null differ diff --git a/yui/quickenrolment/quickenrolment.js b/yui/quickenrolment/quickenrolment.js deleted file mode 100644 index 4e03926..0000000 --- a/yui/quickenrolment/quickenrolment.js +++ /dev/null @@ -1,542 +0,0 @@ -YUI.add('moodle-enrol_ilios-quickenrolment-disbled', function(Y) { - - var CONTROLLERNAME = 'Quick ilios enrolment controller', - COHORTNAME = 'Cohort', - COHORTID = 'cohortid', - ENROLLED = 'enrolled', - NAME = 'name', - USERS = 'users', - COURSEID = 'courseid', - ASSIGNABLEROLES = 'assignableRoles', - DEFAULTILIOSROLE = 'defaultIliosRole', - ILIOSSCHOOLS = 'iliosschools', - ILIOSPROGRAMS = 'iliosprograms', - // Moodle COHORTS - remove - COHORTS = 'cohorts', - ILIOSCOHORTS = 'ilioscohorts', - ILIOSGROUPS = 'iliosgroups', - MORERESULTS = 'moreresults', - FIRSTPAGE = 'firstpage', - OFFSET = 'offset', - PANELID = 'qce-panel-', - REQUIREREFRESH = 'requiresRefresh', - SEARCH = 'search', - URL = 'url', - AJAXURL = 'ajaxurl', - MANUALENROLMENT = 'manualEnrolment', - CSS = { - CLOSEBTN : 'close-button', - COHORT : 'qce-cohort', - COHORTS : 'qce-cohorts', - COHORTBUTTON : 'qce-cohort-button', - COHORTENROLLED : 'qce-cohort-enrolled', - COHORTNAME : 'qce-cohort-name', - COHORTUSERS : 'qce-cohort-users', - ENROLUSERS : 'canenrolusers', - FOOTER : 'qce-footer', - HIDDEN : 'hidden', - LIGHTBOX : 'qce-loading-lightbox', - LOADINGICON : 'loading-icon', - MORERESULTS : 'qce-more-results', - PANEL : 'qce-panel', - PANELCONTENT : 'qce-panel-content', - PANELILIOSGROUPS : 'qce-enrollable-ilios-groups', - PANELCOHORTS : 'qce-ilios-cohorts', - PANELPROGRAMS : 'qce-ilios-programs', - PANELROLES : 'qce-assignable-roles', - PANELSCHOOLS : 'qce-ilios-schools', - PANELCONTROLS : 'qce-panel-controls', - SEARCH : 'qce-search' - }, - COUNT = 0; - - - var CONTROLLER = function(config) { - CONTROLLER.superclass.constructor.apply(this, arguments); - }; - CONTROLLER.prototype = { - initializer : function(config) { - COUNT ++; - this.publish('assignablerolesloaded', {fireOnce:true}); - this.publish('iliosgroupsloaded'); - this.publish('defaultiliosroleloaded', {fireOnce:true}); - - var finishbutton = Y.Node.create('
') - .append(Y.Node.create('')); - var base = Y.Node.create('') - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('')) - .append(Y.Node.create('') - .append(Y.Node.create('') - .append(Y.Node.create('')) - ) - .append(finishbutton) - ) - .append(Y.Node.create('') - .append(Y.Node.create('