Skip to content

Commit

Permalink
Cleaned up unused code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctam committed Feb 2, 2017
1 parent e945ac6 commit 80b22b3
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 835 deletions.
56 changes: 2 additions & 54 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -93,6 +77,7 @@
}
$outcome->response = $schoolarray;
break;

case 'getselectprogramoptions':
require_capability('moodle/course:enrolconfig', $context);
$sid = required_param('filterid', PARAM_INT); // school id
Expand All @@ -105,6 +90,7 @@
}
$outcome->response = $programarray;
break;

case 'getselectcohortoptions':
require_capability('moodle/course:enrolconfig', $context);
$pid = required_param('filterid', PARAM_INT);
Expand Down Expand Up @@ -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');
}
Expand Down
3 changes: 1 addition & 2 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
6 changes: 2 additions & 4 deletions lang/en/enrol_ilios.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand All @@ -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';
Expand Down
6 changes: 2 additions & 4 deletions lang/en_us/enrol_ilios.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand All @@ -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';
Expand Down
36 changes: 0 additions & 36 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
Expand Down
147 changes: 0 additions & 147 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
46 changes: 0 additions & 46 deletions yui/quickenrolment/assets/skins/sam/quickenrolment.css

This file was deleted.

Binary file removed yui/quickenrolment/assets/skins/sam/sprite.png
Binary file not shown.
Loading

0 comments on commit 80b22b3

Please sign in to comment.