|
@ -9,8 +9,11 @@ |
|
|
* ************************************************************************* |
|
|
* ************************************************************************* |
|
|
* ************************************************************************ |
|
|
* ************************************************************************ |
|
|
*/ |
|
|
*/ |
|
|
class enrol_apply_plugin extends enrol_plugin { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** User participation in course is suspended (used in user_enrolments->status) */ |
|
|
|
|
|
define('ENROL_APPLY_USER_WAIT', 2); |
|
|
|
|
|
|
|
|
|
|
|
class enrol_apply_plugin extends enrol_plugin { |
|
|
/** |
|
|
/** |
|
|
* Add new instance of enrol plugin with default settings. |
|
|
* Add new instance of enrol plugin with default settings. |
|
|
* @param object $course |
|
|
* @param object $course |
|
@ -196,50 +199,82 @@ class enrol_apply_plugin extends enrol_plugin { |
|
|
|
|
|
|
|
|
return $fields; |
|
|
return $fields; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function confirmEnrolment($enrols){ |
|
|
function confirmEnrolment($enrols){ |
|
|
global $DB; |
|
|
global $DB; |
|
|
global $CFG; |
|
|
|
|
|
foreach ($enrols as $enrol){ |
|
|
foreach ($enrols as $enrol){ |
|
|
@$enroluser->id = $enrol; |
|
|
// $userenrolment = $DB->get_record('user_enrolments', array('id' => $enrol), '*', MUST_EXIST); |
|
|
@$enroluser->status = 0; |
|
|
$userenrolment = $DB->get_record_select( |
|
|
|
|
|
'user_enrolments', |
|
|
if($DB->update_record('user_enrolments',$enroluser)){ |
|
|
'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)', |
|
|
$userenrolments = $DB->get_record_sql('select * from '.$CFG->prefix.'user_enrolments where id='.$enrol); |
|
|
array( |
|
|
$role = $DB->get_record_sql("select * from ".$CFG->prefix."role where archetype='student' limit 1"); |
|
|
'id' => $enrol, |
|
|
@$roleAssignments->userid = $userenrolments->userid; |
|
|
'enrolusersuspended' => ENROL_USER_SUSPENDED, |
|
|
@$roleAssignments->roleid = $role->id; |
|
|
'enrolapplyuserwait' => ENROL_APPLY_USER_WAIT), |
|
|
@$roleAssignments->contextid = 3; |
|
|
'*', |
|
|
@$roleAssignments->timemodified = time(); |
|
|
MUST_EXIST); |
|
|
@$roleAssignments->modifierid = 2; |
|
|
|
|
|
$DB->insert_record('role_assignments',$roleAssignments); |
|
|
$instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); |
|
|
|
|
|
|
|
|
|
|
|
// Check privileges. |
|
|
|
|
|
$context = context_course::instance($instance->courseid, MUST_EXIST); |
|
|
|
|
|
if (!has_capability('enrol/apply:manageapplications', $context)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE); |
|
|
|
|
|
|
|
|
$info = getRelatedInfo($enrol); |
|
|
$info = getRelatedInfo($enrol); |
|
|
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); |
|
|
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); |
|
|
sendConfirmMail($info); |
|
|
sendConfirmMail($info); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function waitEnrolment($enrols){ |
|
|
function waitEnrolment($enrols){ |
|
|
global $DB; |
|
|
global $DB; |
|
|
global $CFG; |
|
|
|
|
|
foreach ($enrols as $enrol){ |
|
|
foreach ($enrols as $enrol){ |
|
|
@$enroluser->id = $enrol; |
|
|
$userenrolment = $DB->get_record('user_enrolments', array('id' => $enrol, 'status' => ENROL_USER_SUSPENDED), '*', IGNORE_MISSING); |
|
|
@$enroluser->status = 2; |
|
|
|
|
|
|
|
|
if ($userenrolment != null) { |
|
|
|
|
|
$instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); |
|
|
|
|
|
|
|
|
|
|
|
// Check privileges. |
|
|
|
|
|
$context = context_course::instance($instance->courseid, MUST_EXIST); |
|
|
|
|
|
if (!has_capability('enrol/apply:manageapplications', $context)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT); |
|
|
|
|
|
|
|
|
if($DB->update_record('user_enrolments',$enroluser)){ |
|
|
|
|
|
$info = getRelatedInfo($enrol); |
|
|
$info = getRelatedInfo($enrol); |
|
|
sendWaitMail($info); |
|
|
sendWaitMail($info); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function cancelEnrolment($enrols){ |
|
|
function cancelEnrolment($enrols){ |
|
|
global $DB; |
|
|
global $DB; |
|
|
foreach ($enrols as $enrol){ |
|
|
foreach ($enrols as $enrol){ |
|
|
|
|
|
$userenrolment = $DB->get_record_select( |
|
|
|
|
|
'user_enrolments', |
|
|
|
|
|
'id = :id AND (status = :enrolusersuspended OR status = :enrolapplyuserwait)', |
|
|
|
|
|
array( |
|
|
|
|
|
'id' => $enrol, |
|
|
|
|
|
'enrolusersuspended' => ENROL_USER_SUSPENDED, |
|
|
|
|
|
'enrolapplyuserwait' => ENROL_APPLY_USER_WAIT), |
|
|
|
|
|
'*', |
|
|
|
|
|
MUST_EXIST); |
|
|
|
|
|
|
|
|
|
|
|
$instance = $DB->get_record('enrol', array('id' => $userenrolment->enrolid, 'enrol' => 'apply'), '*', MUST_EXIST); |
|
|
|
|
|
|
|
|
|
|
|
// Check privileges. |
|
|
|
|
|
$context = context_course::instance($instance->courseid, MUST_EXIST); |
|
|
|
|
|
if (!has_capability('enrol/apply:manageapplications', $context)) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$info = getRelatedInfo($enrol); |
|
|
$info = getRelatedInfo($enrol); |
|
|
if($DB->delete_records('user_enrolments',array('id'=>$enrol))){ |
|
|
$this->unenrol_user($instance, $userenrolment->userid); |
|
|
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); |
|
|
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); |
|
|
sendCancelMail($info); |
|
|
sendCancelMail($info); |
|
|
} |
|
|
} |
|
|