/**
 * setBestScore
 *
 * @param $userid
 * @param $skillsoftid
 * @param $attempt
 * @param $score
 * @return bool true if succesful
 */
function skillsoft_setBestScore($userid, $skillsoftid, $attempt, $score)
{
    global $DB;
    $id = null;
    //Work to support multiple attempts
    //$attempt = 1;
    $element = '[SUMMARY]bestscore';
    if ($score != 0) {
        $params = array($userid, $skillsoftid, $attempt, $element);
        if ($track = $DB->get_record_select('skillsoft_au_track', "userid=? AND skillsoftid=? AND attempt=? AND element=?", $params)) {
            //We this score is higher
            $currentscore = $track->value;
            if ($score > $currentscore) {
                $id = skillsoft_insert_track($userid, $skillsoftid, $attempt, $element, $score);
            }
        } else {
            $id = skillsoft_insert_track($userid, $skillsoftid, $attempt, $element, $score);
        }
    }
    return $id;
}
 /**
  * Process the ReportResults
  *
  * @param object $reportresults The ReportResults
  * @return null
  */
 public function processreportresults($reportresults, $attempt = 1)
 {
     //Lets parse the response
     $this->cleardata();
     $this->attempt = $attempt;
     $this->getdata();
     $this->cmi->core->lesson_status = strtolower($reportresults->lessonstatus);
     if ($reportresults->currentscore != 0) {
         $this->cmi->core->score->raw = $reportresults->currentscore;
     }
     //Now we do the EXITAU part
     //Duration
     $value = $this->Sec2Time($reportresults->duration);
     $id = skillsoft_insert_track($this->user->id, $this->skillsoft->id, $this->attempt, '[CORE]time', $value);
     $id = skillsoft_setFirstAccessDate($this->user->id, $this->skillsoft->id, $this->attempt, $reportresults->firstaccessdate);
     $id = skillsoft_setLastAccessDate($this->user->id, $this->skillsoft->id, $this->attempt, $reportresults->lastaccessdate);
     if (substr($this->cmi->core->lesson_status, 0, 1) == 'c' || substr($this->cmi->core->lesson_status, 0, 1) == 'p') {
         $id = skillsoft_setCompletedDate($this->user->id, $this->skillsoft->id, $this->attempt, $reportresults->completeddate);
     }
     $id = skillsoft_setAccessCount($this->user->id, $this->skillsoft->id, $this->attempt, $reportresults->accesscount);
     $id = skillsoft_setFirstScore($this->user->id, $this->skillsoft->id, $this->attempt, $reportresults->firstscore);
     $id = skillsoft_setCurrentScore($this->user->id, $this->skillsoft->id, $this->attempt, $reportresults->currentscore);
     $id = skillsoft_setBestScore($this->user->id, $this->skillsoft->id, $this->attempt, $reportresults->bestscore);
     //Need to do these last to ensure grades correctly entered
     //Persist the data
     $id = skillsoft_insert_track($this->user->id, $this->skillsoft->id, $this->attempt, '[CORE]lesson_status', $this->cmi->core->lesson_status);
     $id = skillsoft_insert_track($this->user->id, $this->skillsoft->id, $this->attempt, '[CORE]score', $this->cmi->core->score->raw);
 }