From 6f8dda46d82d1e22e002984ed2394d3e78db4f20 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 22 Apr 2010 09:41:41 +0000 Subject: [PATCH] SCORM MDL-21555 improved Report interface - now allows export as text/excel/ods - probably could do with some more refactoring/improvement, but this is much better than it was. Thanks to Valerian for the initial patch. --- mod/scorm/report.php | 593 ++++++++++++++++++++++++------ mod/scorm/reportsettings_form.php | 30 ++ mod/scorm/tabs.php | 41 +++ mod/scorm/view.php | 11 +- 4 files changed, 560 insertions(+), 115 deletions(-) create mode 100644 mod/scorm/reportsettings_form.php create mode 100644 mod/scorm/tabs.php diff --git a/mod/scorm/report.php b/mod/scorm/report.php index 10d6c4bdd65..a78c39875f5 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -3,7 +3,14 @@ // This script uses installed report plugins to print quiz reports require_once("../../config.php"); - require_once('locallib.php'); + require_once($CFG->libdir.'/tablelib.php'); + require_once($CFG->dirroot.'/mod/scorm/locallib.php'); + require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php'); + require_once($CFG->libdir.'/formslib.php'); + define('SCORM_REPORT_DEFAULT_PAGE_SIZE', 20); + define('SCORM_REPORT_ATTEMPTS_ALL_STUDENTS', 0); + define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH', 1); + define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2); $id = optional_param('id', '', PARAM_INT); // Course Module ID, or $a = optional_param('a', '', PARAM_INT); // SCORM ID @@ -11,7 +18,8 @@ $user = optional_param('user', '', PARAM_INT); // User ID $attempt = optional_param('attempt', '1', PARAM_INT); // attempt number $action = optional_param('action', '', PARAM_ALPHA); - $attemptids = optional_param('attemptid', array(), PARAM_RAW); //get array of responses to delete. + $attemptids = optional_param('attemptid', array(), PARAM_RAW); + $download = optional_param('download', '', PARAM_RAW); $url = new moodle_url('/mod/scorm/report.php'); if ($user !== '') { @@ -71,7 +79,9 @@ } else { $userdata = null; } - + if (!empty($download)) { + $noheader = true; + } /// Print the page header if (empty($noheader)) { @@ -94,11 +104,14 @@ $PAGE->navbar->add($sco->title); } echo $OUTPUT->header(); + $currenttab = 'reports'; + require($CFG->dirroot . '/mod/scorm/tabs.php'); echo $OUTPUT->heading(format_string($scorm->name)); } - if ($action == 'delete' && has_capability('mod/scorm:deleteresponses',$contextmodule)) { + if ($action == 'delete' && has_capability('mod/scorm:deleteresponses',$contextmodule) && confirm_sesskey()) { if (scorm_delete_responses($attemptids, $scorm->id)) { //delete responses. + add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id); echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess'); } } @@ -106,113 +119,475 @@ if (empty($b)) { if (empty($a)) { // No options, show the global scorm report + $pageoptions = array(); + $pageoptions['id'] = $cm->id; + $reporturl = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $pageoptions); + + // find out current groups mode + $currentgroup = groups_get_activity_group($cm, true); + + // detailed report + $mform = new mod_scorm_report_settings( $reporturl, compact('currentgroup') ); + if ($fromform = $mform->get_data()) { + $detailedrep = $fromform->detailedrep; + $pagesize = $fromform->pagesize; + $attemptsmode = $fromform->attemptsmode; + set_user_preference('scorm_report_detailed', $detailedrep); + set_user_preference('scorm_report_pagesize', $pagesize); + } else { + $detailedrep = get_user_preferences('scorm_report_detailed', false); + $pagesize = get_user_preferences('scorm_report_pagesize', 0); + $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_STUDENTS_WITH, PARAM_INT); + } + if ($pagesize < 1) { + $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE; + } - if (!empty($cm->groupingid)) { - $sql = "SELECT st.userid, st.scormid - FROM {scorm_scoes_track} st - INNER JOIN {groups_members} gm ON st.userid = gm.userid - INNER JOIN {groupings_groups} gg ON gm.groupid = gg.groupid - WHERE st.scormid = ? AND gg.groupingid = ? - GROUP BY st.userid,st.scormid - "; - $params = array($scorm->id, $cm->groupingid); - } else { - $sql = "SELECT st.userid, st.scormid - FROM {scorm_scoes_track} st - WHERE st.scormid = ? - GROUP BY st.userid,st.scormid - "; - $params = array($scorm->id); - } + // select group menu + $displayoptions = array(); + $displayoptions['id'] = $cm->id; + $displayoptions['attemptsmode'] = $attemptsmode; + $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/scorm/report.php', $displayoptions); - if ($scousers=$DB->get_records_sql($sql, $params)) { - $table = new html_table(); - $table->head = array(); - $table->width = '100%'; - if (has_capability('mod/scorm:deleteresponses',$contextmodule)) { - $table->head[] = ' '; - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '10'; + if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used + if (!$download) { + groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out()); + } } - $table->head[] = ' '; - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '10'; - - $table->head[] = get_string('name'); - $table->align[] = 'left'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - - $table->head[]= get_string('attempt','scorm'); - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - - $table->head[]= get_string('started','scorm'); - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - - $table->head[]= get_string('last','scorm'); - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - - $table->head[]= get_string('score','scorm'); - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - - foreach($scousers as $scouser){ - $userdata = scorm_get_user_data($scouser->userid); - $attempt = scorm_get_last_attempt($scorm->id,$scouser->userid); - for ($a = 1; $a<=$attempt; $a++) { - $row = array(); - if (has_capability('mod/scorm:deleteresponses',$contextmodule)) { - $row[] = ''; + // We only want to show the checkbox to delete attempts + // if the user has permissions and if the report mode is showing attempts. + $candelete = has_capability('mod/scorm:deleteresponses',$contextmodule) + && ($attemptsmode!= SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO); + // select the students + $nostudents = false; + + if (empty($currentgroup)) { + // all users who can attempt scoes + if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack','','','','','','',false)){ + notify(get_string('nostudentsyet')); + $nostudents = true; + $allowedlist = ''; + } else { + $allowedlist = join(',',array_keys($students)); + } + } else { + // all users who can attempt scoes and who are in the currently selected group + if (!$groupstudents = get_users_by_capability($context, 'mod/scorm:savetrack','','','','',$currentgroup,'',false)){ + notify(get_string('nostudentsingroup')); + $nostudents = true; + $groupstudents = array(); + } + $allowedlist = join(',', array_keys($groupstudents)); + } + + if( !$nostudents ) { + + // Now check if asked download of data + if ($download) { + $filename = clean_filename("$course->shortname ".format_string($scorm->name,true)); + } + + // Define table columns + $columns = array(); + $headers = array(); + if (!$download && $candelete) { + $columns[]= 'checkbox'; + $headers[]= NULL; + } + if (!$download && $CFG->grade_report_showuserimage) { + $columns[]= 'picture'; + $headers[]= ''; + } + $columns[]= 'fullname'; + $headers[]= get_string('name'); + if ($CFG->grade_report_showuseridnumber) { + $columns[]= 'idnumber'; + $headers[]= get_string('idnumber'); + } + $columns[]= 'attempt'; + $headers[]= get_string('attempt', 'scorm'); + $columns[]= 'start'; + $headers[]= get_string('started','scorm'); + $columns[]= 'finish'; + $headers[]= get_string('last','scorm'); + $columns[]= 'score'; + $headers[]= get_string('score','scorm'); + if ($detailedrep && $scoes = $DB->get_records('scorm_scoes',array("scorm"=>$scorm->id),'id')) { + foreach ($scoes as $sco) { + if ($sco->launch!='') { + $columns[]= 'scograde'.$sco->id; + $headers[]= format_string($sco->title); + $table->head[]= format_string($sco->title); + } + } + } else { + $scoes = NULL; + } + + if (!$download) { + $table = new flexible_table('mod-scorm-report'); + + $table->define_columns($columns); + $table->define_headers($headers); + $table->define_baseurl($reporturlwithdisplayoptions->out()); + + $table->sortable(true); + $table->collapsible(true); + + $table->column_suppress('picture'); + $table->column_suppress('fullname'); + $table->column_suppress('idnumber'); + + $table->no_sorting('start'); + $table->no_sorting('finish'); + $table->no_sorting('score'); + if( $scoes ) { + foreach ($scoes as $sco) { + if ($sco->launch!='') { + $table->no_sorting('scograde'.$sco->id); + } + } + } + + $table->column_class('picture', 'picture'); + $table->column_class('fullname', 'bold'); + $table->column_class('score', 'bold'); + + $table->set_attribute('cellspacing', '0'); + $table->set_attribute('id', 'attempts'); + $table->set_attribute('class', 'generaltable generalbox'); + + // Start working -- this is necessary as soon as the niceties are over + $table->setup(); + } else if ($download =='ODS') { + require_once("$CFG->libdir/odslib.class.php"); + + $filename .= ".ods"; + // Creating a workbook + $workbook = new MoodleODSWorkbook("-"); + // Sending HTTP headers + $workbook->send($filename); + // Creating the first worksheet + $sheettitle = get_string('report','scorm'); + $myxls =& $workbook->add_worksheet($sheettitle); + // format types + $format =& $workbook->add_format(); + $format->set_bold(0); + $formatbc =& $workbook->add_format(); + $formatbc->set_bold(1); + $formatbc->set_align('center'); + $formatb =& $workbook->add_format(); + $formatb->set_bold(1); + $formaty =& $workbook->add_format(); + $formaty->set_bg_color('yellow'); + $formatc =& $workbook->add_format(); + $formatc->set_align('center'); + $formatr =& $workbook->add_format(); + $formatr->set_bold(1); + $formatr->set_color('red'); + $formatr->set_align('center'); + $formatg =& $workbook->add_format(); + $formatg->set_bold(1); + $formatg->set_color('green'); + $formatg->set_align('center'); + // Here starts workshhet headers + + $colnum = 0; + foreach ($headers as $item) { + $myxls->write(0,$colnum,$item,$formatbc); + $colnum++; } - //TODO: fetch the user details elsewhere - this is a performance problem!! - $user = (object)array('id'=>$scouser->userid); - $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id)); - $row[] = ''. - fullname($userdata).''; - $row[] = ''.$a.''; - $select = 'scormid = ? and userid = ? and attempt = ?'; - $params = array($scorm->id, $scouser->userid, $a); - $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $a); - // jump out here if this attempt doesnt exist - if (!$timetracks->start) { - continue; + $rownum=1; + } else if ($download =='Excel') { + require_once("$CFG->libdir/excellib.class.php"); + + $filename .= ".xls"; + // Creating a workbook + $workbook = new MoodleExcelWorkbook("-"); + // Sending HTTP headers + $workbook->send($filename); + // Creating the first worksheet + $sheettitle = get_string('report','scorm'); + $myxls =& $workbook->add_worksheet($sheettitle); + // format types + $format =& $workbook->add_format(); + $format->set_bold(0); + $formatbc =& $workbook->add_format(); + $formatbc->set_bold(1); + $formatbc->set_align('center'); + $formatb =& $workbook->add_format(); + $formatb->set_bold(1); + $formaty =& $workbook->add_format(); + $formaty->set_bg_color('yellow'); + $formatc =& $workbook->add_format(); + $formatc->set_align('center'); + $formatr =& $workbook->add_format(); + $formatr->set_bold(1); + $formatr->set_color('red'); + $formatr->set_align('center'); + $formatg =& $workbook->add_format(); + $formatg->set_bold(1); + $formatg->set_color('green'); + $formatg->set_align('center'); + + $colnum = 0; + foreach ($headers as $item) { + $myxls->write(0,$colnum,$item,$formatbc); + $colnum++; } - $row[] = userdate($timetracks->start, get_string('strftimedaydatetime')); - $row[] = userdate($timetracks->finish, get_string('strftimedaydatetime')); + $rownum=1; + } else if ($download=='CSV') { + $filename .= ".txt"; + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=\"$filename\""); + header("Expires: 0"); + header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); + header("Pragma: public"); + echo implode("\t", $headers)." \n"; + } - $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $a); - $table->data[] = $row; + // Construct the SQL + $select = 'SELECT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, '; + $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' . + 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt '; + + // This part is the same for all cases - join users and scorm_scoes_track tables + $from = 'FROM '.$CFG->prefix.'user u '; + $from .= 'LEFT JOIN '.$CFG->prefix.'scorm_scoes_track st ON st.userid = u.id AND st.scormid = '.$scorm->id; + switch ($attemptsmode){ + case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH: + // Show only students with attempts + $where = ' WHERE u.id IN (' .$allowedlist. ') AND st.userid IS NOT NULL'; + break; + case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO: + // Show only students without attempts + $where = ' WHERE u.id IN (' .$allowedlist. ') AND st.userid IS NULL'; + break; + case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS: + // Show all students with or without attempts + $where = ' WHERE u.id IN (' .$allowedlist. ') AND (st.userid IS NOT NULL OR st.userid IS NULL)'; + break; + } + $groupby = ' GROUP BY uniqueid'; + + $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, '; + $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'','st.attempt').')) AS nbattempts, '; + $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers '; + $countsql .= $from.$where; + + if (!$download) { + $sort = $table->get_sql_sort(); + } + else { + $sort = ''; + } + // Fix some wired sorting + if (empty($sort)) { + $sort = ' ORDER BY uniqueid'; + } else { + $sort = ' ORDER BY '.$sort; + } + + if (!$download) { + // Add extra limits due to initials bar + if($table->get_sql_where()) { + $where .= ' AND '.$table->get_sql_where(); + } + + if (!empty($countsql)) { + $count = $DB->get_record_sql($countsql); + $totalinitials = $count->nbresults; + if ($table->get_sql_where()) { + $countsql .= ' AND '.$table->get_sql_where(); + } + $count = $DB->get_record_sql($countsql); + $total = $count->nbresults; + } + + $table->pagesize($pagesize, $total); + + echo '
'; + if ( $count->nbresults == $count->nbattempts ) { + echo get_string('reportcountattempts','scorm', $count); + } else if( $count->nbattempts>0 ) { + echo get_string('reportcountallattempts','scorm', $count); + } else { + echo $count->nbusers.' '.get_string('users'); + } + echo '
'; + } + + // Fetch the attempts + if (!$download) { + $attempts = $DB->get_records_sql($select.$from.$where.$groupby.$sort, array(), + $table->get_page_start(), $table->get_page_size()); + echo '
'; + if ($candelete) { + // Start form + $strreallydel = addslashes(get_string('deleteattemptcheck','scorm')); + echo '
'; + echo ''; + echo ''; + echo '
'; + echo html_writer::input_hidden_params($reporturlwithdisplayoptions); + echo '
'; + echo '
'; + } + $table->initialbars($totalinitials>20); // Build table rows + } else { + $attempts = $DB->get_records_sql($select.$from.$where.$groupby.$sort); + } + + if ($attempts) { + foreach($attempts as $scouser){ + $row = array(); + if (!empty($scouser->attempt)) { + $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt); + } + if (in_array('checkbox', $columns)){ + if ($candelete && !empty($timetracks->start)) { + $row[] = ''; + } else if($candelete) { + $row[] = ''; + } + } + //TODO: fetch the user details elsewhere - this is a performance problem!! + if (in_array('picture', $columns)){ + $user = (object)array('id'=>$scouser->userid); + $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id)); + } + if (!$download){ + $row[] = ''.fullname($scouser).''; + } else { + $row[] = fullname($scouser); + } + if (in_array('idnumber', $columns)){ + $row[] = $scouser->idnumber; + } + if (empty($timetracks->start)) { + $row[] = '-'; + $row[] = '-'; + $row[] = '-'; + $row[] = '-'; + } else { + if (!$download) $row[] = ''.$scouser->attempt.''; + else $row[] = $scouser->attempt; + if ($download =='ODS' || $download =='Excel' ) $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig")); + else $row[] = userdate($timetracks->start); + if ($download =='ODS' || $download =='Excel' ) $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig')); + else $row[] = userdate($timetracks->finish); + + $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt); + } + // print out all scores of attempt + if ($scoes) { + foreach ($scoes as $sco) { + if ($sco->launch!='') { + if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid,$scouser->attempt)) { + if ($trackdata->status == '') { + $trackdata->status = 'notattempted'; + } + $strstatus = get_string($trackdata->status, 'scorm'); + // if raw score exists, print it + if ($trackdata->score_raw != '') { + $score = $trackdata->score_raw; + // add max score if it exists + if ($scorm->version == 'SCORM_1.3') { + $maxkey = 'cmi.score.max'; + } else { + $maxkey = 'cmi.core.score.max'; + } + if (isset($trackdata->$maxkey)) { + $score .= '/'.$trackdata->$maxkey; + } + // else print out status + } else { + $score = $strstatus; + } + if (!$download) { + $row[] = ''.$strstatus.'
+ '.$score.''; + } else { + $row[] = $score; + } + } else { + // if we don't have track data, we haven't attempted yet + $strstatus = get_string('notattempted', 'scorm'); + if (!$download) { + $row[] = ''.$strstatus.'
'.$strstatus; + } else { + $row[] = $strstatus; + } + } + } + } + } + + if (!$download) { + $table->add_data($row); + } else if ($download == 'Excel' or $download == 'ODS') { + $colnum = 0; + foreach($row as $item){ + $myxls->write($rownum,$colnum,$item,$format); + $colnum++; + } + $rownum++; + } else if ($download=='CSV') { + $text = implode("\t", $row); + echo $text." \n"; + } + } + if (!$download) { + if ($candelete) { + echo ''; + echo '
'; + echo ''. + get_string('selectall', 'scorm').' / '; + echo ''. + get_string('selectnone', 'scorm').' '; + echo '  '; + echo ''; + echo '
'; + // Close form + echo '
'; + echo '
'; + } + echo '
'; + if (!empty($attempts)) { + echo ''; + echo '\n"; + echo '\n"; + echo '\n"; + echo "\n"; + echo '
'; + echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'ODS')), get_string('downloadods')); + echo "'; + echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'Excel')), get_string('downloadexcel')); + echo "'; + echo $OUTPUT->single_button(new moodle_url('/mod/scorm/report.php', $pageoptions + $displayoptions + array('download' => 'CSV')), get_string('downloadtext')); + echo ""; + echo "
'; + } } - } - echo '
'; - if (has_capability('mod/scorm:deleteresponses',$contextmodule)) { - echo '
'; - echo ''; - echo html_writer::table($table); - echo ''.get_string('selectall', 'quiz').' / '; - echo ''.get_string('selectnone', 'quiz').' '; - echo '  '; - echo html_writer::tag('label', get_string('withselected', 'quiz'), array('for'=>'menuaction')); - echo html_writer::select(array('delete' => get_string('delete')), 'action', '', array(''=>'choosedots'), array('id'=>'menuaction')); - $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('attemptsform', 'menuaction', '')); - echo ''; - echo '
'; } else { - echo html_writer::table($table); + notify(get_string('noactivity', 'scorm')); + if (!$download) { + echo html_writer::table($table); + } + } + if ($download == 'Excel' or $download == 'ODS') { + $workbook->close(); + exit; + } else if ($download == 'CSV') { + exit; + } + if (!$download) { + $mform->set_data($displayoptions + compact('detailedrep', 'pagesize')); + $mform->display(); } - echo '
'; } else { echo $OUTPUT->notification(get_string('noactivity', 'scorm')); } @@ -303,7 +678,7 @@ $trackdata->total_time = ''; } $strstatus = get_string($trackdata->status,'scorm'); - echo ''.$strstatus.'pix_url('pix/'.$trackdata->status, 'scorm').'" alt="'.$strstatus.'" title="'. $strstatus.'" /> '.scorm_format_date_time($trackdata->total_time).'
'.$scoreview.'
'; echo ''."\n"; echo '

'.get_string('details','scorm').'

'; @@ -337,10 +712,16 @@ $printedelements[]=$element; $row = array(); $row[] = get_string($key,'scorm'); - if ($key == 'time') { - $row[] = s(scorm_format_date_time($trackdata->$element)); - } else { - $row[] = s($trackdata->$element); + switch($key) { + case 'status': + $row[] = $strstatus; + break; + case 'time': + $row[] = s(scorm_format_date_time($trackdata->$element)); + break; + default: + s($trackdata->$element); + break; } $table->data[] = $row; } diff --git a/mod/scorm/reportsettings_form.php b/mod/scorm/reportsettings_form.php new file mode 100644 index 00000000000..ec3387cc791 --- /dev/null +++ b/mod/scorm/reportsettings_form.php @@ -0,0 +1,30 @@ +libdir/formslib.php"; +class mod_scorm_report_settings extends moodleform { + + function definition() { + global $COURSE; + $mform =& $this->_form; + //------------------------------------------------------------------------------- + $mform->addElement('header', 'preferencespage', get_string('preferencespage', 'scorm')); + + $options = array(); + if ($this->_customdata['currentgroup'] || $COURSE->id != SITEID) { + $options[SCORM_REPORT_ATTEMPTS_ALL_STUDENTS] = get_string('optallstudents','scorm'); + $options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH] = get_string('optattemptsonly','scorm'); + $options[SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO] = get_string('optnoattemptsonly', 'scorm'); + } + $mform->addElement('select', 'attemptsmode', get_string('show', 'scorm'), $options); + + //------------------------------------------------------------------------------- + $mform->addElement('header', 'preferencesuser', get_string('preferencesuser', 'scorm')); + + $mform->addElement('text', 'pagesize', get_string('pagesize', 'scorm')); + $mform->setType('pagesize', PARAM_INT); + + $mform->addElement('selectyesno', 'detailedrep', get_string('details', 'scorm')); + + $this->add_action_buttons(false, get_string('savepreferences')); + } + +} diff --git a/mod/scorm/tabs.php b/mod/scorm/tabs.php new file mode 100644 index 00000000000..6615bcf9dfd --- /dev/null +++ b/mod/scorm/tabs.php @@ -0,0 +1,41 @@ +id); +} + + +$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id); + +$tabs = array(); +$row = array(); +$inactive = array(); +$activated = array(); + +if (has_capability('mod/scorm:savetrack', $contextmodule)) { + $row[] = new tabobject('info', "$CFG->wwwroot/mod/scorm/view.php?id=$cm->id", get_string('info', 'scorm')); +} +if (has_capability('mod/scorm:viewreport', $contextmodule)) { + $row[] = new tabobject('reports', "$CFG->wwwroot/mod/scorm/report.php?id=$cm->id", get_string('results', 'scorm')); +} + +if ($currenttab == 'info' && count($row) == 1) { + // Don't show only an info tab (e.g. to students). +} else { + $tabs[] = $row; +} + +print_tabs($tabs, $currenttab, $inactive, $activated); diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 578a3294adf..c956afcd8f6 100755 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -63,15 +63,8 @@ $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); - if (has_capability('mod/scorm:viewreport', $context)) { - - $trackedusers = scorm_get_count_users($scorm->id, $cm->groupingid); - if ($trackedusers > 0) { - echo "
id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'
'; - } else { - echo ''; - } - } + $currenttab = 'info'; + require($CFG->dirroot . '/mod/scorm/tabs.php'); // Print the main part of the page echo $OUTPUT->heading(format_string($scorm->name)); -- 2.43.0