当前位置: 首页>>代码示例>>PHP>>正文


PHP coursecat::user_enrolment_changed方法代码示例

本文整理汇总了PHP中coursecat::user_enrolment_changed方法的典型用法代码示例。如果您正苦于以下问题:PHP coursecat::user_enrolment_changed方法的具体用法?PHP coursecat::user_enrolment_changed怎么用?PHP coursecat::user_enrolment_changed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coursecat的用法示例。


在下文中一共展示了coursecat::user_enrolment_changed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: unenrol_user

 /**
  * Unenrol user from course,
  * the last unenrolment removes all remaining roles.
  *
  * @param stdClass $instance
  * @param int $userid
  * @return void
  */
 public function unenrol_user(stdClass $instance, $userid)
 {
     global $CFG, $USER, $DB;
     require_once "{$CFG->dirroot}/group/lib.php";
     $name = $this->get_name();
     $courseid = $instance->courseid;
     if ($instance->enrol !== $name) {
         throw new coding_exception('invalid enrol instance!');
     }
     $context = context_course::instance($instance->courseid, MUST_EXIST);
     if (!($ue = $DB->get_record('user_enrolments', array('enrolid' => $instance->id, 'userid' => $userid)))) {
         // weird, user not enrolled
         return;
     }
     // Remove all users groups linked to this enrolment instance.
     if ($gms = $DB->get_records('groups_members', array('userid' => $userid, 'component' => 'enrol_' . $name, 'itemid' => $instance->id))) {
         foreach ($gms as $gm) {
             groups_remove_member($gm->groupid, $gm->userid);
         }
     }
     role_unassign_all(array('userid' => $userid, 'contextid' => $context->id, 'component' => 'enrol_' . $name, 'itemid' => $instance->id));
     $DB->delete_records('user_enrolments', array('id' => $ue->id));
     // add extra info and trigger event
     $ue->courseid = $courseid;
     $ue->enrol = $name;
     $sql = "SELECT 'x'\n                  FROM {user_enrolments} ue\n                  JOIN {enrol} e ON (e.id = ue.enrolid)\n                 WHERE ue.userid = :userid AND e.courseid = :courseid";
     if ($DB->record_exists_sql($sql, array('userid' => $userid, 'courseid' => $courseid))) {
         $ue->lastenrol = false;
     } else {
         // the big cleanup IS necessary!
         require_once "{$CFG->libdir}/gradelib.php";
         // remove all remaining roles
         role_unassign_all(array('userid' => $userid, 'contextid' => $context->id), true, false);
         //clean up ALL invisible user data from course if this is the last enrolment - groups, grades, etc.
         groups_delete_group_members($courseid, $userid);
         grade_user_unenrol($courseid, $userid);
         $DB->delete_records('user_lastaccess', array('userid' => $userid, 'courseid' => $courseid));
         $ue->lastenrol = true;
         // means user not enrolled any more
     }
     // Trigger event.
     $event = \core\event\user_enrolment_deleted::create(array('courseid' => $courseid, 'context' => $context, 'relateduserid' => $ue->userid, 'objectid' => $ue->id, 'other' => array('userenrolment' => (array) $ue, 'enrol' => $name)));
     $event->trigger();
     // reset all enrol caches
     $context->mark_dirty();
     // Check if courrse contacts cache needs to be cleared.
     require_once $CFG->libdir . '/coursecatlib.php';
     coursecat::user_enrolment_changed($courseid, $ue->userid, ENROL_USER_SUSPENDED);
     // reset current user enrolment caching
     if ($userid == $USER->id) {
         if (isset($USER->enrol['enrolled'][$courseid])) {
             unset($USER->enrol['enrolled'][$courseid]);
         }
         if (isset($USER->enrol['tempguest'][$courseid])) {
             unset($USER->enrol['tempguest'][$courseid]);
             remove_temp_course_roles($context);
         }
     }
 }
开发者ID:dg711,项目名称:moodle,代码行数:67,代码来源:enrollib.php


注:本文中的coursecat::user_enrolment_changed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。