Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'm22_MDL-35123' of git://github.com/danmarsden/moodle in…

…to MOODLE_22_STABLE
  • Loading branch information...
commit 686723f4fa53c37b4c49b66e2a38eb1ff5bec080 2 parents 5f48905 + 88c5506
Eloy Lafuente (stronk7) stronk7 authored

Showing 1 changed file with 32 additions and 15 deletions. Show diff stats Hide diff stats

  1. +32 15 mod/scorm/locallib.php
47 mod/scorm/locallib.php
@@ -644,33 +644,50 @@ function scorm_count_launchable($scormid, $organization='') {
644 644 return $DB->count_records_select('scorm_scoes', "scorm = ? $sqlorganization AND ".$DB->sql_isnotempty('scorm_scoes', 'launch', false, true), $params);
645 645 }
646 646
  647 +/**
  648 + * Returns the last attempt used - if no attempts yet, returns 1 for first attempt
  649 + *
  650 + * @param int $scormid the id of the scorm.
  651 + * @param int $userid the id of the user.
  652 + *
  653 + * @return int The attempt number to use.
  654 + */
647 655 function scorm_get_last_attempt($scormid, $userid) {
648 656 global $DB;
649 657
650 658 /// Find the last attempt number for the given user id and scorm id
651   - if ($lastattempt = $DB->get_record('scorm_scoes_track', array('userid'=>$userid, 'scormid'=>$scormid), 'max(attempt) as a')) {
652   - if (empty($lastattempt->a)) {
653   - return '1';
654   - } else {
655   - return $lastattempt->a;
656   - }
  659 + $sql = "SELECT MAX(attempt)
  660 + FROM {scorm_scoes_track}
  661 + WHERE userid = ? AND scormid = ?";
  662 + $lastattempt = $DB->get_field_sql($sql, array($userid, $scormid));
  663 + if (empty($lastattempt)) {
  664 + return '1';
657 665 } else {
658   - return false;
  666 + return $lastattempt;
659 667 }
660 668 }
661 669
  670 +/**
  671 + * Returns the last completed attempt used - if no completed attempts yet, returns 1 for first attempt
  672 + *
  673 + * @param int $scormid the id of the scorm.
  674 + * @param int $userid the id of the user.
  675 + *
  676 + * @return int The attempt number to use.
  677 + */
662 678 function scorm_get_last_completed_attempt($scormid, $userid) {
663 679 global $DB;
664 680
665   - /// Find the last attempt number for the given user id and scorm id
666   - if ($lastattempt = $DB->get_record_select('scorm_scoes_track', "userid = ? AND scormid = ? AND (value='completed' OR value='passed')", array($userid, $scormid), 'max(attempt) as a')) {
667   - if (empty($lastattempt->a)) {
668   - return '1';
669   - } else {
670   - return $lastattempt->a;
671   - }
  681 + /// Find the last completed attempt number for the given user id and scorm id
  682 + $sql = "SELECT MAX(attempt)
  683 + FROM {scorm_scoes_track}
  684 + WHERE userid = ? AND scormid = ?
  685 + AND (value='completed' OR value='passed')";
  686 + $lastattempt = $DB->get_field_sql($sql, array($userid, $scormid));
  687 + if (empty($lastattempt)) {
  688 + return '1';
672 689 } else {
673   - return false;
  690 + return $lastattempt;
674 691 }
675 692 }
676 693

0 comments on commit 686723f

Please sign in to comment.
Something went wrong with that request. Please try again.