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


PHP completion_completion::mark_enrolled方法代码示例

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


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

示例1: completion_cron_mark_started

/**
 * Mark users as started if the config option is set
 *
 * @return  void
 */
function completion_cron_mark_started()
{
    global $CFG, $DB;
    if (debugging()) {
        mtrace('Marking users as started');
    }
    if (!empty($CFG->progresstrackedroles)) {
        $roles = ' AND ra.roleid IN (' . $CFG->progresstrackedroles . ')';
    } else {
        // This causes it to default to everyone (if there is no student role)
        $roles = '';
    }
    /**
     * A quick explaination of this horrible looking query
     *
     * It's purpose is to locate all the active participants
     * of a course with course completion enabled.
     *
     * We also only want the users with no course_completions
     * record as this functions job is to create the missing
     * ones :)
     *
     * We want to record the user's enrolment start time for the
     * course. This gets tricky because there can be multiple
     * enrolment plugins active in a course, hence the possibility
     * of multiple records for each couse/user in the results
     */
    $sql = "\n        SELECT\n            c.id AS course,\n            u.id AS userid,\n            crc.id AS completionid,\n            ue.timestart AS timeenrolled,\n            ue.timecreated\n        FROM\n            {user} u\n        INNER JOIN\n            {user_enrolments} ue\n         ON ue.userid = u.id\n        INNER JOIN\n            {enrol} e\n         ON e.id = ue.enrolid\n        INNER JOIN\n            {course} c\n         ON c.id = e.courseid\n        INNER JOIN\n            {role_assignments} ra\n         ON ra.userid = u.id\n        LEFT JOIN\n            {course_completions} crc\n         ON crc.course = c.id\n        AND crc.userid = u.id\n        WHERE\n            c.enablecompletion = 1\n        AND crc.timeenrolled IS NULL\n        AND ue.status = 0\n        AND e.status = 0\n        AND u.deleted = 0\n        AND ue.timestart < ?\n        AND (ue.timeend > ? OR ue.timeend = 0)\n            {$roles}\n        ORDER BY\n            course,\n            userid\n    ";
    // Check if result is empty
    $now = time();
    if (!($rs = $DB->get_recordset_sql($sql, array($now, $now, $now, $now)))) {
        return;
    }
    /**
     * An explaination of the following loop
     *
     * We are essentially doing a group by in the code here (as I can't find
     * a decent way of doing it in the sql).
     *
     * Since there can be multiple enrolment plugins for each course, we can have
     * multiple rows for each particpant in the query result. This isn't really
     * a problem until you combine it with the fact that the enrolment plugins
     * can save the enrol start time in either timestart or timeenrolled.
     *
     * The purpose of this loop is to find the earliest enrolment start time for
     * each participant in each course.
     */
    $prev = null;
    while ($rs->valid() || $prev) {
        $current = $rs->current();
        if (!isset($current->course)) {
            $current = false;
        } else {
            // Not all enrol plugins fill out timestart correctly, so use whichever
            // is non-zero
            $current->timeenrolled = max($current->timecreated, $current->timeenrolled);
        }
        // If we are at the last record,
        // or we aren't at the first and the record is for a diff user/course
        if ($prev && (!$rs->valid() || ($current->course != $prev->course || $current->userid != $prev->userid))) {
            $completion = new completion_completion();
            $completion->userid = $prev->userid;
            $completion->course = $prev->course;
            $completion->timeenrolled = (string) $prev->timeenrolled;
            $completion->timestarted = 0;
            $completion->reaggregate = time();
            if ($prev->completionid) {
                $completion->id = $prev->completionid;
            }
            $completion->mark_enrolled();
            if (debugging()) {
                mtrace('Marked started user ' . $prev->userid . ' in course ' . $prev->course);
            }
        } elseif ($prev && $current) {
            // Use oldest timeenrolled
            $current->timeenrolled = min($current->timeenrolled, $prev->timeenrolled);
        }
        // Move current record to previous
        $prev = $current;
        // Move to next record
        $rs->next();
    }
    $rs->close();
}
开发者ID:vuchannguyen,项目名称:web,代码行数:89,代码来源:cron.php

示例2: sync_enrolments


//.........这里部分代码省略.........
                     }
                     $trace->output('Old grade for courseid ' . $cinfo['courseid'] . " and userid " . $userid . " is " . $currentgrade . ".");
                 } else {
                     $trace->output('Error: Unable to get final exam record for courseid ' . $cinfo['courseid'] . " and userid " . $userid . ". Course completion will be ignored.");
                     continue;
                 }
                 if (isset($cinfo['grade'])) {
                     if ($cinfo['grade'] > $currentgrade || empty($currentgrade)) {
                         // If imported grade is larger update the final exam grade
                         $grade = array();
                         $grade['userid'] = $userid;
                         $grade['rawgrade'] = $cinfo['grade'] / 10;
                         //learn.saylor.org is currently using rawmaxgrade of 10.0000
                         grade_update('mod/quiz', $cinfo['courseid'], $gi->itemtype, $gi->itemmodule, $gi->iteminstance, $gi->itemnumber, $grade);
                         $trace->output('Updating grade for courseid ' . $cinfo['courseid'] . " and userid " . $userid . " to " . $grade['rawgrade'] . ".");
                     } else {
                         if (!empty($currentgrade) && $currentgrade >= $cinfo['grade']) {
                             $trace->output("Current grade for final exam for courseid " . $cinfo['courseid'] . " and userid " . $userid . " is larger or equal to the imported grade. Not updating grade.");
                             continue;
                         } else {
                             debugging("Unable to determine if there is a current final exam grade for courseid " . $cinfo['courseid'] . " and userid " . $userid . " or whether it is less than the imported grade.");
                             continue;
                         }
                     }
                     //Mark course as complete. Create completion_completion object to handle completion info for that user and course.
                     $cparams = array('userid' => $userid, 'course' => $cinfo['courseid']);
                     $cc = new completion_completion($cparams);
                     if ($cc->is_complete()) {
                         continue;
                         //Skip adding completion info for this course if the user has already completed this course. Possibility that his grade gets bumped up.
                     }
                     if (isset($cinfo['completiondate'])) {
                         $completeddatestamp = strtotime($cinfo['completiondate']);
                         //Convert the date string to a unix time stamp.
                     } else {
                         $completeddatestamp = time();
                         //If not set, just use the current date.
                     }
                     if (isset($cinfo['enroldate'])) {
                         $enroldatestamp = strtotime($cinfo['enroldate']);
                         //Convert the date string to a unix time stamp.
                     } else {
                         $enroldatestamp = $completeddatestamp;
                     }
                     $cc->mark_enrolled($enroldatestamp);
                     $cc->mark_inprogress($enroldatestamp);
                     $cc->mark_complete($completeddatestamp);
                     $trace->output('Setting completion data for userid ' . $userid . ' and courseid ' . $cinfo['courseid'] . ".");
                 } else {
                     if (!isset($cinfo['grade'])) {
                         $trace->output("Error: No grade info in external db for completed course " . $cinfo['courseid'] . " for user " . $userid . ".");
                     }
                 }
             }
         }
         // Deal with enrolments removed from external table.
         if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
             if (!$preventfullunenrol) {
                 // Unenrol.
                 foreach ($currentstatus as $userid => $status) {
                     if (isset($requestedenrols[$userid])) {
                         continue;
                     }
                     $this->unenrol_user($instance, $userid);
                     $trace->output("unenrolling: {$userid} ==> {$course->shortname}", 1);
                 }
             }
         } else {
             if ($unenrolaction == ENROL_EXT_REMOVED_KEEP) {
                 // Keep - only adding enrolments.
             } else {
                 if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
                     // Suspend enrolments.
                     foreach ($currentstatus as $userid => $status) {
                         if (isset($requestedenrols[$userid])) {
                             continue;
                         }
                         if ($status != ENROL_USER_SUSPENDED) {
                             $this->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
                             $trace->output("suspending: {$userid} ==> {$course->shortname}", 1);
                         }
                         if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
                             if (isset($requestedroles[$userid])) {
                                 // We want this "other user" to keep their roles.
                                 continue;
                             }
                             role_unassign_all(array('contextid' => $context->id, 'userid' => $userid, 'component' => '', 'itemid' => $instance->id));
                             $trace->output("unsassigning all roles: {$userid} ==> {$course->shortname}", 1);
                         }
                     }
                 }
             }
         }
     }
     // Close db connection.
     $extdb->Close();
     $trace->output('...user enrolment synchronisation finished.');
     $trace->finished();
     return 0;
 }
开发者ID:saylordotorg,项目名称:moodle-enrol_dbself,代码行数:101,代码来源:lib.php


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