Esempio n. 1
0
/**
 * Obtains the automatic completion state for this face to face activity based on any conditions
 * in face to face settings.
 *
 * @param object $course Course
 * @param object $cm Course-module
 * @param int $userid User ID
 * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
 * @return bool True if completed, false if not. (If no conditions, then return
 *   value depends on comparison type)
 */
function facetoface_get_completion_state($course, $cm, $userid, $type) {
    global $DB;

    $result = $type;

    // Get face to face.
    if (!$facetoface = $DB->get_record('facetoface', array('id' => $cm->instance))) {
        print_error('cannotfindfacetoface');
    }

    // Only check for existence of tracks and return false if completionstatusrequired.
    // This means that if only view is required we don't end up with a false state.
    if ($facetoface->completionstatusrequired) {
        $completionstatusrequired = json_decode($facetoface->completionstatusrequired, true);
        if (empty($completionstatusrequired)) {
            return $result;
        }
        list($insql, $inparams) = $DB->get_in_or_equal(array_keys($completionstatusrequired));

        // Get user's face to face status.
        $sql = "SELECT f2fss.id AS signupstatusid, f2fss.statuscode, f2fsd.timefinish
                FROM {facetoface_sessions} f2fses
                LEFT JOIN {facetoface_signups} f2fs ON (f2fs.sessionid = f2fses.id)
                LEFT JOIN {facetoface_signups_status} f2fss ON (f2fss.signupid = f2fs.id)
                LEFT JOIN {facetoface_sessions_dates} f2fsd ON (f2fsd.sessionid = f2fses.id)
                WHERE f2fses.facetoface = ? AND f2fs.userid = ?
                  AND f2fss.statuscode $insql
                ORDER BY f2fsd.timefinish";
        $params = array_merge(array($facetoface->id, $userid), $inparams);
        $status = $DB->get_record_sql($sql, $params, IGNORE_MULTIPLE);
        if ($status) {
            // Tell completion_criteria_activity::review exact time of completion, otherwise it will use time of review run.
            $cm->timecompleted = $status->timefinish;
            return completion_info::aggregate_completion_states($type, $result, true);
        }
        return completion_info::aggregate_completion_states($type, $result, false);
    }
    return $result;
}
Esempio n. 2
0
File: lib.php Progetto: dg711/moodle
/**
 * Obtains the automatic completion state for this scorm based on any conditions
 * in scorm settings.
 *
 * @param object $course Course
 * @param object $cm Course-module
 * @param int $userid User ID
 * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
 * @return bool True if completed, false if not. (If no conditions, then return
 *   value depends on comparison type)
 */
function scorm_get_completion_state($course, $cm, $userid, $type)
{
    global $DB;
    $result = $type;
    // Get scorm.
    if (!($scorm = $DB->get_record('scorm', array('id' => $cm->instance)))) {
        print_error('cannotfindscorm');
    }
    // Only check for existence of tracks and return false if completionstatusrequired or completionscorerequired
    // this means that if only view is required we don't end up with a false state.
    if ($scorm->completionstatusrequired !== null || $scorm->completionscorerequired !== null) {
        // Get user's tracks data.
        $tracks = $DB->get_records_sql("\n            SELECT\n                id,\n                scoid,\n                element,\n                value\n            FROM\n                {scorm_scoes_track}\n            WHERE\n                scormid = ?\n            AND userid = ?\n            AND element IN\n            (\n                'cmi.core.lesson_status',\n                'cmi.completion_status',\n                'cmi.success_status',\n                'cmi.core.score.raw',\n                'cmi.score.raw'\n            )\n            ", array($scorm->id, $userid));
        if (!$tracks) {
            return completion_info::aggregate_completion_states($type, $result, false);
        }
    }
    // Check for status.
    if ($scorm->completionstatusrequired !== null) {
        // Get status.
        $statuses = array_flip(scorm_status_options());
        $nstatus = 0;
        // Check any track for these values.
        $scostatus = array();
        foreach ($tracks as $track) {
            if (!in_array($track->element, array('cmi.core.lesson_status', 'cmi.completion_status', 'cmi.success_status'))) {
                continue;
            }
            if (array_key_exists($track->value, $statuses)) {
                $scostatus[$track->scoid] = true;
                $nstatus |= $statuses[$track->value];
            }
        }
        if (!empty($scorm->completionstatusallscos)) {
            // Iterate over all scos and make sure each has a lesson_status.
            $scos = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id, 'scormtype' => 'sco'));
            foreach ($scos as $sco) {
                if (empty($scostatus[$sco->id])) {
                    return completion_info::aggregate_completion_states($type, $result, false);
                }
            }
            return completion_info::aggregate_completion_states($type, $result, true);
        } else {
            if ($scorm->completionstatusrequired & $nstatus) {
                return completion_info::aggregate_completion_states($type, $result, true);
            } else {
                return completion_info::aggregate_completion_states($type, $result, false);
            }
        }
    }
    // Check for score.
    if ($scorm->completionscorerequired !== null) {
        $maxscore = -1;
        foreach ($tracks as $track) {
            if (!in_array($track->element, array('cmi.core.score.raw', 'cmi.score.raw'))) {
                continue;
            }
            if (strlen($track->value) && floatval($track->value) >= $maxscore) {
                $maxscore = floatval($track->value);
            }
        }
        if ($scorm->completionscorerequired <= $maxscore) {
            return completion_info::aggregate_completion_states($type, $result, true);
        } else {
            return completion_info::aggregate_completion_states($type, $result, false);
        }
    }
    return $result;
}
Esempio n. 3
0
File: lib.php Progetto: ruddj/moodle
/**
 * Obtains the automatic completion state for this scorm based on any conditions
 * in scorm settings.
 *
 * @param object $course Course
 * @param object $cm Course-module
 * @param int $userid User ID
 * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
 * @return bool True if completed, false if not. (If no conditions, then return
 *   value depends on comparison type)
 */
function scorm_get_completion_state($course, $cm, $userid, $type) {
    global $DB;

    $result = $type;

    // Get scorm.
    if (!$scorm = $DB->get_record('scorm', array('id' => $cm->instance))) {
        print_error('cannotfindscorm');
    }
    // Only check for existence of tracks and return false if completionstatusrequired or completionscorerequired
    // this means that if only view is required we don't end up with a false state.
    if ($scorm->completionstatusrequired !== null ||
        $scorm->completionscorerequired !== null) {
        // Get user's tracks data.
        $tracks = $DB->get_records_sql(
            "
            SELECT
                id,
                element,
                value
            FROM
                {scorm_scoes_track}
            WHERE
                scormid = ?
            AND userid = ?
            AND element IN
            (
                'cmi.core.lesson_status',
                'cmi.completion_status',
                'cmi.success_status',
                'cmi.core.score.raw',
                'cmi.score.raw'
            )
            ",
            array($scorm->id, $userid)
        );

        if (!$tracks) {
            return completion_info::aggregate_completion_states($type, $result, false);
        }
    }

    // Check for status.
    if ($scorm->completionstatusrequired !== null) {

        // Get status.
        $statuses = array_flip(scorm_status_options());
        $nstatus = 0;

        foreach ($tracks as $track) {
            if (!in_array($track->element, array('cmi.core.lesson_status', 'cmi.completion_status', 'cmi.success_status'))) {
                continue;
            }

            if (array_key_exists($track->value, $statuses)) {
                $nstatus |= $statuses[$track->value];
            }
        }

        if ($scorm->completionstatusrequired & $nstatus) {
            return completion_info::aggregate_completion_states($type, $result, true);
        } else {
            return completion_info::aggregate_completion_states($type, $result, false);
        }

    }

    // Check for score.
    if ($scorm->completionscorerequired !== null) {
        $maxscore = -1;

        foreach ($tracks as $track) {
            if (!in_array($track->element, array('cmi.core.score.raw', 'cmi.score.raw'))) {
                continue;
            }

            if (strlen($track->value) && floatval($track->value) >= $maxscore) {
                $maxscore = floatval($track->value);
            }
        }

        if ($scorm->completionscorerequired <= $maxscore) {
            return completion_info::aggregate_completion_states($type, $result, true);
        } else {
            return completion_info::aggregate_completion_states($type, $result, false);
        }
    }

    return $result;
}
Esempio n. 4
0
/**
 * Obtains the automatic completion state for this scorm based on any conditions
 * in scorm settings.
 *
 * @param object $course Course
 * @param object $cm Course-module
 * @param int $userid User ID
 * @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
 * @return bool True if completed, false if not. (If no conditions, then return
 *   value depends on comparison type)
 */
function scorm_get_completion_state($course, $cm, $userid, $type)
{
    global $DB;
    $result = $type;
    // Get scorm
    if (!($scorm = $DB->get_record('scorm', array('id' => $cm->instance)))) {
        print_error('cannotfindscorm');
    }
    // Get user's tracks data
    $tracks = $DB->get_records_sql("\n        SELECT\n            id,\n            element,\n            value\n        FROM\n            {scorm_scoes_track}\n        WHERE\n            scormid = ?\n        AND userid = ?\n        AND element IN\n        (\n            'cmi.core.lesson_status',\n            'cmi.completion_status',\n            'cmi.success_status',\n            'cmi.core.score.raw',\n            'cmi.score.raw'\n        )\n        ", array($scorm->id, $userid));
    if (!$tracks) {
        return completion_info::aggregate_completion_states($type, $result, false);
    }
    // Check for status
    if ($scorm->completionstatusrequired !== null) {
        // Get status
        $statuses = array_flip(scorm_status_options());
        $nstatus = 0;
        foreach ($tracks as $track) {
            if (!in_array($track->element, array('cmi.core.lesson_status', 'cmi.completion_status', 'cmi.success_status'))) {
                continue;
            }
            if (array_key_exists($track->value, $statuses)) {
                $nstatus |= $statuses[$track->value];
            }
        }
        if ($scorm->completionstatusrequired & $nstatus) {
            return completion_info::aggregate_completion_states($type, $result, true);
        } else {
            return completion_info::aggregate_completion_states($type, $result, false);
        }
    }
    // Check for score
    if ($scorm->completionscorerequired !== null) {
        $maxscore = -1;
        foreach ($tracks as $track) {
            if (!in_array($track->element, array('cmi.core.score.raw', 'cmi.score.raw'))) {
                continue;
            }
            if (strlen($track->value) && floatval($track->value) >= $maxscore) {
                $maxscore = floatval($track->value);
            }
        }
        if ($scorm->completionscorerequired <= $maxscore) {
            return completion_info::aggregate_completion_states($type, $result, true);
        } else {
            return completion_info::aggregate_completion_states($type, $result, false);
        }
    }
    return $result;
}