/**
  * Deal with users that are not supposed to be enrolled via this instance
  * @static
  * @param stdClass $instance
  * @param stdClass $ue
  * @param context_course $context
  * @param enrol_meta $plugin
  * @return void
  */
 protected static function user_not_supposed_to_be_here($instance, $ue, context_course $context, $plugin)
 {
     if (!$ue) {
         // not enrolled yet - simple!
         return;
     }
     $userid = $ue->userid;
     $unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
     if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
         // purges grades, group membership, preferences, etc. - admins were warned!
         $plugin->unenrol_user($instance, $userid);
         return;
     } else {
         // ENROL_EXT_REMOVED_SUSPENDNOROLES
         // just suspend users and remove all roles (we can reassign the roles any time later)
         if ($ue->status != ENROL_USER_SUSPENDED) {
             $plugin->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
             role_unassign_all(array('userid' => $userid, 'contextid' => $context->id, 'component' => 'enrol_meta', 'itemid' => $instance->id));
         }
         return;
     }
 }
Exemple #2
0
 /**
  * Deal with users that are not supposed to be enrolled via this instance
  * @static
  * @param stdClass $instance
  * @param stdClass $ue
  * @param context_course $context
  * @param enrol_meta $plugin
  * @return void
  */
 protected static function user_not_supposed_to_be_here($instance, $ue, context_course $context, $plugin)
 {
     if (!$ue) {
         // Not enrolled yet - simple!
         return;
     }
     $userid = $ue->userid;
     $unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
     if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
         // Purges grades, group membership, preferences, etc. - admins were warned!
         $plugin->unenrol_user($instance, $userid);
     } else {
         if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND) {
             if ($ue->status != ENROL_USER_SUSPENDED) {
                 $plugin->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
             }
         } else {
             if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
                 if ($ue->status != ENROL_USER_SUSPENDED) {
                     $plugin->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
                 }
                 role_unassign_all(array('userid' => $userid, 'contextid' => $context->id, 'component' => 'enrol_meta', 'itemid' => $instance->id));
             } else {
                 debugging('Unknown unenrol action ' . $unenrolaction);
             }
         }
     }
 }