MDL-71144 mod_scorm: Deprecate scorm_get_completion_state()
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* List of deprecated mod_scorm functions.
|
||||
*
|
||||
* @package mod_scorm
|
||||
* @copyright 2021 Shamim Rezaie <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtains the automatic completion state for this scorm based on any conditions
|
||||
* in scorm settings.
|
||||
*
|
||||
* @deprecated since Moodle 3.11
|
||||
* @todo MDL-71196 Final deprecation in Moodle 4.3
|
||||
* @see \mod_scorm\completion\custom_completion
|
||||
* @param stdClass $course Course
|
||||
* @param cm_info|stdClass $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;
|
||||
|
||||
// No need to call debugging here. Deprecation debugging notice already being called in \completion_info::internal_get_state().
|
||||
|
||||
$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,
|
||||
scoid,
|
||||
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;
|
||||
// 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;
|
||||
}
|
||||
+3
-112
@@ -19,6 +19,7 @@
|
||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/** SCORM_TYPE_LOCAL = local */
|
||||
define('SCORM_TYPE_LOCAL', 'local');
|
||||
@@ -53,6 +54,8 @@ define('SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY', 3);
|
||||
define('SCORM_EVENT_TYPE_OPEN', 'open');
|
||||
define('SCORM_EVENT_TYPE_CLOSE', 'close');
|
||||
|
||||
require_once(__DIR__ . '/deprecatedlib.php');
|
||||
|
||||
/**
|
||||
* Return an array of status options
|
||||
*
|
||||
@@ -1146,118 +1149,6 @@ function scorm_version_check($scormversion, $version='') {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
scoid,
|
||||
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;
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the ability to handle drag and drop file uploads
|
||||
* @return array containing details of the files / types the mod can handle
|
||||
|
||||
Reference in New Issue
Block a user