/**
 * @param object $skillsoft
 * @param int $userid
 * @param int $attempt
 * @return object
 */
function skillsoft_grade_user($skillsoft, $userid, $attempt = '')
{
    $result = new stdClass();
    $result->score = 0;
    $result->time = 0;
    //We need to get last attempt to grade
    if (empty($attempt)) {
        $attempt = skillsoft_get_last_attempt($skillsoft->id, $userid);
        if ($attempt == 0) {
            $attempt = 1;
        }
    }
    if ($userdata = skillsoft_get_tracks($skillsoft->id, $userid, $attempt)) {
        if (isset($userdata->{'[SUMMARY]bestscore'})) {
            $result->score = $userdata->{'[SUMMARY]bestscore'};
            $result->time = $userdata->{'[SUMMARY]lastaccess'};
        } else {
            $result = NULL;
        }
    }
    return $result;
}
 /**
  * Retrieve existing data
  *
  * This function retrieves existing data from database and populates
  * the CMI model
  */
 public function getdata()
 {
     global $CFG;
     //Get data from database
     $userdata = skillsoft_get_tracks($this->skillsoft->id, $this->user->id, $this->attempt);
     //Populate the cmi datamodel
     //Set the student ID based on
     //Need to include logic for "prefix" here
     $this->cmi->core->student_id = $CFG->skillsoft_accountprefix . $this->user->{$CFG->skillsoft_useridentifier};
     $this->cmi->core->student_name = $this->user->lastname . ', ' . $this->user->firstname;
     if ($this->cmi->core->lesson_mode == 'normal') {
         $this->cmi->core->credit = 'credit';
     } else {
         $this->cmi->core->credit = 'no-credit';
     }
     if (isset($userdata->{'[CORE]lesson_location'})) {
         $this->cmi->core->lesson_location = $userdata->{'[CORE]lesson_location'};
     } else {
         $this->cmi->core->lesson_location = '';
     }
     if (isset($userdata->status)) {
         if ($userdata->status == '') {
             $this->cmi->core->lesson_status_entry = 'ab initio';
         } else {
             if (isset($userdata->{'[CORE]lesson_status flag'}) && $userdata->{'[CORE]lesson_status flag'} == 'suspend') {
                 $this->cmi->core->lesson_status_entry = 'resume';
             } else {
                 $this->cmi->core->lesson_status_entry = NULL;
             }
         }
     }
     if (isset($userdata->{'[CORE]lesson_status'})) {
         $this->cmi->core->lesson_status = $userdata->{'[CORE]lesson_status'};
     } else {
         $this->cmi->core->lesson_status = 'not attempted';
     }
     if (isset($userdata->{'[CORE]score'})) {
         $this->cmi->core->score->raw = $userdata->{'[CORE]score'};
     } else {
         $this->cmi->core->score->raw = '';
     }
     $this->cmi->core->student_data->mastery_score = isset($this->skillsoft->mastery) ? $this->skillsoft->mastery : '';
     if (isset($userdata->{'[CORE]time'})) {
         $this->cmi->core->time = $userdata->{'[CORE]time'};
     } else {
         $this->cmi->core->time = '00:00:00';
     }
     if (isset($userdata->{'[CORE_LESSON]'})) {
         $this->cmi->core->core_lesson = stripslashes($userdata->{'[CORE_LESSON]'});
     } else {
         $this->cmi->core->core_lesson = '';
     }
     if (isset($userdata->{'[CORE]session_time'})) {
         $this->cmi->core->session_time = $userdata->{'[CORE]session_time'};
     } else {
         $this->cmi->core->session_time = '00:00:00';
     }
 }
/**
 * Print a detailed representation of what a user has done with
 * a given particular instance of this module, for user activity reports.
 * This needs to output the information
 *
 * @return boolean
 * @todo Finish documenting this function
 */
function skillsoft_user_complete($course, $user, $mod, $skillsoft)
{
    global $OUTPUT;
    require_once 'locallib.php';
    $table = new html_table();
    $table->head = array(get_string('skillsoft_attempt', 'skillsoft'), get_string('skillsoft_firstaccess', 'skillsoft'), get_string('skillsoft_lastaccess', 'skillsoft'), get_string('skillsoft_completed', 'skillsoft'), get_string('skillsoft_lessonstatus', 'skillsoft'), get_string('skillsoft_totaltime', 'skillsoft'), get_string('skillsoft_firstscore', 'skillsoft'), get_string('skillsoft_currentscore', 'skillsoft'), get_string('skillsoft_bestscore', 'skillsoft'), get_string('skillsoft_accesscount', 'skillsoft'));
    $table->align = array('left', 'left', 'left', 'left', 'center', 'center', 'right', 'right', 'right', 'right');
    $table->wrap = array('', '', '', '', 'nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
    $table->width = '80%';
    $table->size = array('*', '*', '*', '*', '*', '*', '*', '*', '*', '*');
    $row = array();
    $score = ' ';
    $maxattempts = skillsoft_get_last_attempt($skillsoft->id, $user->id);
    if ($maxattempts == 0) {
        $maxattempts = 1;
    }
    for ($a = $maxattempts; $a > 0; $a--) {
        $row = array();
        $score = ' ';
        if ($trackdata = skillsoft_get_tracks($skillsoft->id, $user->id, $a)) {
            $row[] = '<a href="' . new moodle_url('/mod/skillsoft/report.php', array('id' => $skillsoft->id, 'user' => 'true', 'attempt' => $trackdata->attempt)) . '">' . $trackdata->attempt . '</a>';
            $row[] = isset($trackdata->{'[SUMMARY]firstaccess'}) ? userdate($trackdata->{'[SUMMARY]firstaccess'}) : '';
            $row[] = isset($trackdata->{'[SUMMARY]lastaccess'}) ? userdate($trackdata->{'[SUMMARY]lastaccess'}) : '';
            if ($skillsoft->completable == true) {
                $row[] = isset($trackdata->{'[SUMMARY]completed'}) ? userdate($trackdata->{'[SUMMARY]completed'}) : '';
                $row[] = isset($trackdata->{'[CORE]lesson_status'}) ? $trackdata->{'[CORE]lesson_status'} : '';
                $row[] = isset($trackdata->{'[CORE]time'}) ? $trackdata->{'[CORE]time'} : '';
                $row[] = isset($trackdata->{'[SUMMARY]firstscore'}) ? $trackdata->{'[SUMMARY]firstscore'} : '';
                $row[] = isset($trackdata->{'[SUMMARY]currentscore'}) ? $trackdata->{'[SUMMARY]currentscore'} : '';
                $row[] = isset($trackdata->{'[SUMMARY]bestscore'}) ? $trackdata->{'[SUMMARY]bestscore'} : '';
            } else {
                $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
            }
            $row[] = isset($trackdata->{'[SUMMARY]accesscount'}) ? $trackdata->{'[SUMMARY]accesscount'} : '';
            $table->data[] = $row;
        }
    }
    echo html_writer::table($table);
    return true;
}
 $table->align = array('left', 'left', 'left', 'left', 'left', 'center', 'center', 'right', 'right', 'right', 'right');
 $table->wrap = array('', '', '', '', '', 'nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
 $table->width = '80%';
 $table->size = array('*', '*', '*', '*', '*', '*', '*', '*', '*', '*', '*');
 if ($skillsoftusers = $DB->get_records_sql($sql, $params)) {
     foreach ($skillsoftusers as $skillsoftuser) {
         $maxattempts = skillsoft_get_last_attempt($skillsoft->id, $skillsoftuser->userid);
         if ($maxattempts == 0) {
             $maxattempts = 1;
         }
         for ($a = $maxattempts; $a > 0; $a--) {
             $row = array();
             $userdata = $DB->get_record('user', array('id' => $skillsoftuser->userid), 'id, firstname, lastname, picture, imagealt, email');
             $row[] = $OUTPUT->user_picture($userdata, array('courseid' => $course->id)) . ' ' . '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $skillsoftuser->userid . '&amp;course=' . $course->id . '">' . fullname($userdata) . '</a>';
             $score = '&nbsp;';
             if ($trackdata = skillsoft_get_tracks($skillsoftuser->skillsoftid, $skillsoftuser->userid, $a)) {
                 $row[] = $trackdata->attempt;
                 $row[] = isset($trackdata->{'[SUMMARY]firstaccess'}) ? userdate($trackdata->{'[SUMMARY]firstaccess'}) : '';
                 $row[] = isset($trackdata->{'[SUMMARY]lastaccess'}) ? userdate($trackdata->{'[SUMMARY]lastaccess'}) : '';
                 if ($skillsoft->completable == true) {
                     $row[] = isset($trackdata->{'[SUMMARY]completed'}) ? userdate($trackdata->{'[SUMMARY]completed'}) : '';
                     $row[] = isset($trackdata->{'[CORE]lesson_status'}) ? $trackdata->{'[CORE]lesson_status'} : '';
                     $row[] = isset($trackdata->{'[CORE]time'}) ? $trackdata->{'[CORE]time'} : '';
                     $row[] = isset($trackdata->{'[SUMMARY]firstscore'}) ? $trackdata->{'[SUMMARY]firstscore'} : '';
                     $row[] = isset($trackdata->{'[SUMMARY]currentscore'}) ? $trackdata->{'[SUMMARY]currentscore'} : '';
                     $row[] = isset($trackdata->{'[SUMMARY]bestscore'}) ? $trackdata->{'[SUMMARY]bestscore'} : '';
                 } else {
                     $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                     $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                     $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));
                     $row[] = $OUTPUT->help_icon('skillsoft_noncompletable', 'skillsoft', get_string('skillsoft_na', 'skillsoft'));