Browse Source

Merge pull request #44 from danielneis/filter-enrols

@danielneis 	adding composer.json 	a1450c1
	@danielneis 	filter by enrolid/enrol plugin on getAllEnrolment 	bd03f50
	@danielneis 	add missing string
SABERES_37_STABLE v3.0-b
Flotter Totte 9 years ago
parent
commit
1d3afe086f
  1. 8
      apply.php
  2. 12
      composer.json
  3. 9
      db/access.php
  4. 1
      lang/en/enrol_apply.php
  5. 25
      lib.php

8
apply.php

@ -22,6 +22,8 @@ $id = required_param ( 'id', PARAM_INT ); // course id
$course = $DB->get_record ( 'course', array ('id' => $id ), '*', MUST_EXIST );
$context = context_course::instance($course->id, MUST_EXIST);
$enrolid = optional_param('enrolid', 0, PARAM_INT);
require_login ( $course );
require_capability ( 'moodle/course:enrolreview', $context );
@ -40,15 +42,15 @@ if (isset ( $_POST ['enrolid'] )) {
} elseif ($_POST ['type'] == 'cancel') {
cancelEnrolment ( $_POST ['enrolid'] );
}
redirect ( "$CFG->wwwroot/enrol/apply/apply.php?id=" . $id . "&enrolid=" . $_GET ['enrolid'] );
redirect ( "$CFG->wwwroot/enrol/apply/apply.php?id=" . $id . "&enrolid=" . $enrolid );
}
}
$enrols = getAllEnrolment ($id);
$enrols = getAllEnrolment ($enrolid);
echo $OUTPUT->header ();
echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) );
echo '<form id="frmenrol" method="post" action="apply.php?id=' . $id . '&enrolid=' . $_GET ['enrolid'] . '">';
echo '<form id="frmenrol" method="post" action="apply.php?id=' . $id . '&enrolid=' . $enrolid . '">';
echo '<input type="hidden" id="type" name="type" value="confirm">';
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">';
echo '<th class="header" scope="col">&nbsp;</th>';

12
composer.json

@ -0,0 +1,12 @@
{
"name": "emeneo/moodle-enrol_apply",
"description": "An enrol plugin for Moodle that adds an approval step into the course enrolment process.",
"type": "moodle-enrol",
"license": "GPLv3",
"require": {
"composer/installers": "*"
},
"extra": {
"installer-name": "apply"
}
}

9
db/access.php

@ -53,6 +53,15 @@ $capabilities = array(
)
),
'enrol/apply:enrol' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
)
),
'enrol/apply:unenrol' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,

1
lang/en/enrol_apply.php

@ -35,6 +35,7 @@ $string['status'] = 'Allow Course enrol confirmation';
$string['confirmenrol'] = 'Manage application';
$string['apply:config'] = 'Configure apply enrol instances';
$string['apply:enrol'] = 'Enrol users';
$string['apply:manage'] = 'Manage apply enrolment';
$string['apply:unenrol'] = 'Cancel users from the course';
$string['apply:unenrolapply'] = 'Cancel self from the course'; // is this necessary now?

25
lib.php

@ -239,11 +239,30 @@ class enrol_apply_plugin extends enrol_plugin {
function getAllEnrolment($id = null) {
global $DB;
global $CFG;
if ($id) {
$userenrolments = $DB->get_records_sql('select ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.status=1 and e.courseid='.$id);
$sql = 'SELECT ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated
FROM {course} c
JOIN {enrol} e
ON e.courseid = c.id
JOIN {user_enrolments} ue
ON ue.enrolid = e.id
JOIN {user} u
ON ue.userid = u.id
WHERE ue.status = 1
AND e.id = ?';
$userenrolments = $DB->get_records_sql($sql, array($id));
} else {
$userenrolments = $DB->get_records_sql('select ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.status=1');
$sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated
FROM {user_enrolments} ue
LEFT JOIN {user} u
ON ue.userid = u.id
LEFT JOIN {enrol} e
ON ue.enrolid = e.id
LEFT JOIN {course} c
ON e.courseid = c.id
WHERE ue.status = 1
AND e.enrol = ?';
$userenrolments = $DB->get_records_sql($sql, array('apply'));
}
return $userenrolments;
}

Loading…
Cancel
Save