Línea 89... |
Línea 89... |
89 |
self::validate_context($context);
|
89 |
self::validate_context($context);
|
Línea 90... |
Línea 90... |
90 |
|
90 |
|
91 |
// Check that the user has the permission to manual enrol.
|
91 |
// Check that the user has the permission to manual enrol.
|
Línea -... |
Línea 92... |
- |
|
92 |
require_capability('enrol/manual:enrol', $context);
|
- |
|
93 |
|
- |
|
94 |
$user = core_user::get_user($enrolment['userid'], strictness: MUST_EXIST);
|
92 |
require_capability('enrol/manual:enrol', $context);
|
95 |
core_user::require_active_user($user);
|
93 |
|
96 |
|
94 |
// Throw an exception if user is not able to assign the role.
|
97 |
// Throw an exception if user is not able to assign the role.
|
95 |
$roles = get_assignable_roles($context);
|
98 |
$roles = get_assignable_roles($context);
|
96 |
if (!array_key_exists($enrolment['roleid'], $roles)) {
|
99 |
if (!array_key_exists($enrolment['roleid'], $roles)) {
|
97 |
$errorparams = new stdClass();
|
100 |
$errorparams = new stdClass();
|
98 |
$errorparams->roleid = $enrolment['roleid'];
|
101 |
$errorparams->roleid = $enrolment['roleid'];
|
99 |
$errorparams->courseid = $enrolment['courseid'];
|
102 |
$errorparams->courseid = $enrolment['courseid'];
|
100 |
$errorparams->userid = $enrolment['userid'];
|
103 |
$errorparams->userid = $user->id;
|
Línea 101... |
Línea 104... |
101 |
throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams);
|
104 |
throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams);
|
102 |
}
|
105 |
}
|
Línea 119... |
Línea 122... |
119 |
// Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin).
|
122 |
// Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin).
|
120 |
if (!$enrol->allow_enrol($instance)) {
|
123 |
if (!$enrol->allow_enrol($instance)) {
|
121 |
$errorparams = new stdClass();
|
124 |
$errorparams = new stdClass();
|
122 |
$errorparams->roleid = $enrolment['roleid'];
|
125 |
$errorparams->roleid = $enrolment['roleid'];
|
123 |
$errorparams->courseid = $enrolment['courseid'];
|
126 |
$errorparams->courseid = $enrolment['courseid'];
|
124 |
$errorparams->userid = $enrolment['userid'];
|
127 |
$errorparams->userid = $user->id;
|
125 |
throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams);
|
128 |
throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams);
|
126 |
}
|
129 |
}
|
Línea 127... |
Línea 130... |
127 |
|
130 |
|
128 |
// Finally proceed the enrolment.
|
131 |
// Finally proceed the enrolment.
|
129 |
$enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0;
|
132 |
$enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0;
|
130 |
$enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0;
|
133 |
$enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0;
|
131 |
$enrolment['status'] = (isset($enrolment['suspend']) && !empty($enrolment['suspend'])) ?
|
134 |
$enrolment['status'] = (isset($enrolment['suspend']) && !empty($enrolment['suspend'])) ?
|
Línea 132... |
Línea 135... |
132 |
ENROL_USER_SUSPENDED : ENROL_USER_ACTIVE;
|
135 |
ENROL_USER_SUSPENDED : ENROL_USER_ACTIVE;
|
133 |
|
136 |
|
Línea 134... |
Línea 137... |
134 |
$enrol->enrol_user($instance, $enrolment['userid'], $enrolment['roleid'],
|
137 |
$enrol->enrol_user($instance, $user->id, $enrolment['roleid'],
|
Línea 135... |
Línea 138... |
135 |
$enrolment['timestart'], $enrolment['timeend'], $enrolment['status']);
|
138 |
$enrolment['timestart'], $enrolment['timeend'], $enrolment['status']);
|
Línea 195... |
Línea 198... |
195 |
require_capability('enrol/manual:unenrol', $context);
|
198 |
require_capability('enrol/manual:unenrol', $context);
|
196 |
$instance = $DB->get_record('enrol', array('courseid' => $enrolment['courseid'], 'enrol' => 'manual'));
|
199 |
$instance = $DB->get_record('enrol', array('courseid' => $enrolment['courseid'], 'enrol' => 'manual'));
|
197 |
if (!$instance) {
|
200 |
if (!$instance) {
|
198 |
throw new moodle_exception('wsnoinstance', 'enrol_manual', '', $enrolment);
|
201 |
throw new moodle_exception('wsnoinstance', 'enrol_manual', '', $enrolment);
|
199 |
}
|
202 |
}
|
200 |
$user = $DB->get_record('user', array('id' => $enrolment['userid']));
|
203 |
$user = core_user::get_user($enrolment['userid'], strictness: MUST_EXIST);
|
201 |
if (!$user) {
|
204 |
core_user::require_active_user($user);
|
202 |
throw new invalid_parameter_exception('User id not exist: '.$enrolment['userid']);
|
- |
|
203 |
}
|
- |
|
204 |
if (!$enrol->allow_unenrol($instance)) {
|
205 |
if (!$enrol->allow_unenrol($instance)) {
|
205 |
throw new moodle_exception('wscannotunenrol', 'enrol_manual', '', $enrolment);
|
206 |
throw new moodle_exception('wscannotunenrol', 'enrol_manual', '', $enrolment);
|
206 |
}
|
207 |
}
|
207 |
$enrol->unenrol_user($instance, $enrolment['userid']);
|
208 |
$enrol->unenrol_user($instance, $user->id);
|
208 |
}
|
209 |
}
|
209 |
$transaction->allow_commit();
|
210 |
$transaction->allow_commit();
|
210 |
}
|
211 |
}
|
Línea 211... |
Línea 212... |
211 |
|
212 |
|