• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP grade_user_unenrol函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中grade_user_unenrol函数的典型用法代码示例。如果您正苦于以下问题:PHP grade_user_unenrol函数的具体用法?PHP grade_user_unenrol怎么用?PHP grade_user_unenrol使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了grade_user_unenrol函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
         events_trigger('user_unenrolled', $ue);
         // user still has some enrolments, no big cleanup yet
     } 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
         events_trigger('user_unenrolled', $ue);
     }
     // reset all enrol caches
     $context->mark_dirty();
     // 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:vinoth4891,项目名称:clinique,代码行数:64,代码来源:enrollib.php


示例2: 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;

        $name = $this->get_name();
        $courseid = $instance->courseid;

        if ($instance->enrol !== $name) {
            throw new coding_exception('invalid enrol instance!');
        }
        $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);

        if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
            // weird, user not enrolled
            return;
        }

        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'
                  FROM {user_enrolments} ue
                  JOIN {enrol} e ON (e.id = ue.enrolid)
                  WHERE ue.userid = :userid AND e.courseid = :courseid";
        if ($DB->record_exists_sql($sql, array('userid'=>$userid, 'courseid'=>$courseid))) {
            $ue->lastenrol = false;
            events_trigger('user_unenrolled', $ue);
            // user still has some enrolments, no big cleanup yet
        } else {
            // the big cleanup IS necessary!

            require_once("$CFG->dirroot/group/lib.php");
            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
            events_trigger('user_unenrolled', $ue);
        }
        // reset primitive require_login() 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]);
                $USER->access = remove_temp_roles($context, $USER->access);
            }
        }
    }
开发者ID:nikita777,项目名称:moodle,代码行数:69,代码来源:enrollib.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP grade_verify_idnumber函数代码示例发布时间:2022-05-15
下一篇:
PHP grade_user_delete函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap