Permalink
Browse files

MDL-33755 SCORM: new quick function to check if a user has scorm data…

…/tracks - better/quicker way to check as full track info isn't needed.
  • Loading branch information...
1 parent 234415c commit 410b7c9bcc7c3b0aaf4731ac1ab304d26302c2cd @danmarsden danmarsden committed Sep 12, 2012
Showing with 14 additions and 2 deletions.
  1. +13 −1 mod/scorm/locallib.php
  2. +1 −1 mod/scorm/view.php
View
@@ -436,6 +436,18 @@ function scorm_insert_track($userid, $scormid, $scoid, $attempt, $element, $valu
return $id;
}
+/**
+ * simple quick function to return true/false if this user has tracks in this scorm
+ *
+ * @param integer $scormid The scorm ID
+ * @param integer $userid the users id
+ * @return boolean (false if there are no tracks)
+ */
+function scorm_has_tracks($scormid, $userid) {
+ global $DB;
+ return $DB->record_exists('scorm_scoes_track', array('userid'=>$userid, 'scormid'=>$scormid));
+}
+
function scorm_get_tracks($scoid, $userid, $attempt='') {
/// Gets all tracks of specified sco and user
global $CFG, $DB;
@@ -870,7 +882,7 @@ function scorm_simple_play($scorm, $user, $context, $cmid) {
$url = new moodle_url('/mod/scorm/player.php', array('a' => $scorm->id,
'currentorg'=>$orgidentifier,
'scoid'=>$sco->id));
- if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || scorm_get_tracks($sco->id, $user->id) === false) {
+ if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || !scorm_has_tracks($scorm->id, $user->id)) {
if (!empty($scorm->forcenewattempt)) {
$result = scorm_get_toc($user, $scorm, $cmid, TOCFULLURL, $orgidentifier);
if ($result->incomplete === false) {
View
@@ -70,7 +70,7 @@
!has_capability('mod/scorm:viewreport', $contextmodule)) { // Don't skip users with the capability to view reports.
// do we launch immediately and redirect the parent back ?
- if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || (scorm_get_tracks($scoes[0]->id, $USER->id) === false)) {
+ if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || !scorm_has_tracks($scorm->id, $USER->id)) {
$orgidentifier = '';
if ($sco = scorm_get_sco($scorm->launch, SCO_ONLY)) {
if (($sco->organization == '') && ($sco->launch == '')) {

0 comments on commit 410b7c9

Please sign in to comment.