MDL-39926 SCORM: new Objectives report type
[moodle.git] / mod / scorm / report / objectives / report.php
CommitLineData
1554cfcd
DM
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16/**
17 * Core Report class of objectives SCORM report plugin
18 * @package scormreport_objectives
19 * @author Dan Marsden <dan@danmarsden.com>
20 * @copyright 2013 Dan Marsden
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24defined('MOODLE_INTERNAL') || die();
25
26require_once($CFG->dirroot.'/mod/scorm/report/objectives/responsessettings_form.php');
27
28/**
29 * Objectives report class
30 *
31 * @copyright 2013 Dan Marsden
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 */
34class scorm_objectives_report extends scorm_default_report {
35 /**
36 * displays the full report
37 * @param stdClass $scorm full SCORM object
38 * @param stdClass $cm - full course_module object
39 * @param stdClass $course - full course object
40 * @param string $download - type of download being requested
41 */
42 public function display($scorm, $cm, $course, $download) {
43 global $CFG, $DB, $OUTPUT, $PAGE;
44
45 $contextmodule = context_module::instance($cm->id);
46 $action = optional_param('action', '', PARAM_ALPHA);
47 $attemptids = optional_param_array('attemptid', array(), PARAM_RAW);
48 $attemptsmode = optional_param('attemptsmode', SCORM_REPORT_ATTEMPTS_ALL_STUDENTS, PARAM_INT);
49 $PAGE->set_url(new moodle_url($PAGE->url, array('attemptsmode' => $attemptsmode)));
50
51 if ($action == 'delete' && has_capability('mod/scorm:deleteresponses', $contextmodule) && confirm_sesskey()) {
52 if (scorm_delete_responses($attemptids, $scorm)) { // Delete responses.
53 add_to_log($course->id, 'scorm', 'delete attempts', 'report.php?id=' . $cm->id, implode(",", $attemptids), $cm->id);
54 echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
55 }
56 }
57 // Find out current groups mode.
58 $currentgroup = groups_get_activity_group($cm, true);
59
60 // Detailed report.
61 $mform = new mod_scorm_report_objectives_settings($PAGE->url, compact('currentgroup'));
62 if ($fromform = $mform->get_data()) {
63 $pagesize = $fromform->pagesize;
64 $showobjectivescore = $fromform->objectivescore;
65 set_user_preference('scorm_report_pagesize', $pagesize);
66 set_user_preference('scorm_report_objectives_score', $showobjectivescore);
67 } else {
68 $pagesize = get_user_preferences('scorm_report_pagesize', 0);
69 $showobjectivescore = get_user_preferences('scorm_report_objectives_score', 0);
70 }
71 if ($pagesize < 1) {
72 $pagesize = SCORM_REPORT_DEFAULT_PAGE_SIZE;
73 }
74
75 // Select group menu.
76 $displayoptions = array();
77 $displayoptions['attemptsmode'] = $attemptsmode;
78 $displayoptions['objectivescore'] = $showobjectivescore;
79
80 $mform->set_data($displayoptions + array('pagesize' => $pagesize));
81 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used.
82 if (!$download) {
83 groups_print_activity_menu($cm, new moodle_url($PAGE->url, $displayoptions));
84 }
85 }
86 $formattextoptions = array('context' => context_course::instance($course->id));
87
88 // We only want to show the checkbox to delete attempts
89 // if the user has permissions and if the report mode is showing attempts.
90 $candelete = has_capability('mod/scorm:deleteresponses', $contextmodule)
91 && ($attemptsmode != SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
92 // Select the students.
93 $nostudents = false;
94
95 if (empty($currentgroup)) {
96 // All users who can attempt scoes.
97 if (!$students = get_users_by_capability($contextmodule, 'mod/scorm:savetrack', 'u.id', '', '', '', '', '', false)) {
98 echo $OUTPUT->notification(get_string('nostudentsyet'));
99 $nostudents = true;
100 $allowedlist = '';
101 } else {
102 $allowedlist = array_keys($students);
103 }
104 unset($students);
105 } else {
106 // All users who can attempt scoes and who are in the currently selected group.
107 $groupstudents = get_users_by_capability($contextmodule, 'mod/scorm:savetrack',
108 'u.id', '', '', '', $currentgroup, '', false);
109 if (!$groupstudents) {
110 echo $OUTPUT->notification(get_string('nostudentsingroup'));
111 $nostudents = true;
112 $groupstudents = array();
113 }
114 $allowedlist = array_keys($groupstudents);
115 unset($groupstudents);
116 }
117 if ( !$nostudents ) {
118 // Now check if asked download of data.
119 $coursecontext = context_course::instance($course->id);
120 if ($download) {
121 $filename = clean_filename("$course->shortname ".format_string($scorm->name, true, $formattextoptions));
122 }
123
124 // Define table columns.
125 $columns = array();
126 $headers = array();
127 if (!$download && $candelete) {
128 $columns[] = 'checkbox';
129 $headers[] = null;
130 }
131 if (!$download && $CFG->grade_report_showuserimage) {
132 $columns[] = 'picture';
133 $headers[] = '';
134 }
135 $columns[] = 'fullname';
136 $headers[] = get_string('name');
137
138 $extrafields = get_extra_user_fields($coursecontext);
139 foreach ($extrafields as $field) {
140 $columns[] = $field;
141 $headers[] = get_user_field_name($field);
142 }
143 $columns[] = 'attempt';
144 $headers[] = get_string('attempt', 'scorm');
145 $columns[] = 'start';
146 $headers[] = get_string('started', 'scorm');
147 $columns[] = 'finish';
148 $headers[] = get_string('last', 'scorm');
149 $columns[] = 'score';
150 $headers[] = get_string('score', 'scorm');
151 $scoes = $DB->get_records('scorm_scoes', array("scorm"=>$scorm->id), 'id');
152 foreach ($scoes as $sco) {
153 if ($sco->launch != '') {
154 $columns[] = 'scograde'.$sco->id;
155 $headers[] = format_string($sco->title, '', $formattextoptions);
156 }
157 }
158
159 $params = array();
160 list($usql, $params) = $DB->get_in_or_equal($allowedlist, SQL_PARAMS_NAMED);
161 // Construct the SQL.
162 $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, ';
163 $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' .
164 'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email'.
165 get_extra_user_fields_sql($coursecontext, 'u', '', array('email', 'idnumber')) . ' ';
166
167 // This part is the same for all cases - join users and scorm_scoes_track tables.
168 $from = 'FROM {user} u ';
169 $from .= 'LEFT JOIN {scorm_scoes_track} st ON st.userid = u.id AND st.scormid = '.$scorm->id;
170 switch ($attemptsmode) {
171 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH:
172 // Show only students with attempts.
173 $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NOT NULL';
174 break;
175 case SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
176 // Show only students without attempts.
177 $where = ' WHERE u.id ' .$usql. ' AND st.userid IS NULL';
178 break;
179 case SCORM_REPORT_ATTEMPTS_ALL_STUDENTS:
180 // Show all students with or without attempts.
181 $where = ' WHERE u.id ' .$usql. ' AND (st.userid IS NOT NULL OR st.userid IS NULL)';
182 break;
183 }
184
185 $countsql = 'SELECT COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').')) AS nbresults, ';
186 $countsql .= 'COUNT(DISTINCT('.$DB->sql_concat('u.id', '\'#\'', 'st.attempt').')) AS nbattempts, ';
187 $countsql .= 'COUNT(DISTINCT(u.id)) AS nbusers ';
188 $countsql .= $from.$where;
189
190 $nbmaincolumns = count($columns); // Get number of main columns used.
191
192 $objectives = get_scorm_objectives($scorm->id);
193 $nosort = array();
194 foreach ($objectives as $scoid => $sco) {
195 foreach ($sco as $id => $objectivename) {
196 $colid = $scoid.'objectivestatus' . $id;
197 $columns[] = $colid;
198 $nosort[] = $colid;
199
200 if (!$displayoptions['objectivescore']) {
201 // Display the objective name only.
202 $headers[] = $objectivename;
203 } else {
204 // Display the objective status header with a "status" suffix to avoid confusion.
205 $headers[] = $objectivename. ' '. get_string('status', 'scormreport_objectives');
206
207 // Now print objective score headers.
208 $colid = $scoid.'objectivescore' . $id;
209 $columns[] = $colid;
210 $nosort[] = $colid;
211 $headers[] = $objectivename. ' '. get_string('score', 'scormreport_objectives');
212 }
213 }
214 }
215
216 $emptycell = ''; // Used when an empty cell is being printed - in html we add a space.
217 if (!$download) {
218 $emptycell = '&nbsp;';
219 $table = new flexible_table('mod-scorm-report');
220
221 $table->define_columns($columns);
222 $table->define_headers($headers);
223 $table->define_baseurl($PAGE->url);
224
225 $table->sortable(true);
226 $table->collapsible(true);
227
228 // This is done to prevent redundant data, when a user has multiple attempts.
229 $table->column_suppress('picture');
230 $table->column_suppress('fullname');
231 foreach ($extrafields as $field) {
232 $table->column_suppress($field);
233 }
234 foreach ($nosort as $field) {
235 $table->no_sorting($field);
236 }
237
238 $table->no_sorting('start');
239 $table->no_sorting('finish');
240 $table->no_sorting('score');
241
242 foreach ($scoes as $sco) {
243 if ($sco->launch != '') {
244 $table->no_sorting('scograde'.$sco->id);
245 }
246 }
247
248 $table->column_class('picture', 'picture');
249 $table->column_class('fullname', 'bold');
250 $table->column_class('score', 'bold');
251
252 $table->set_attribute('cellspacing', '0');
253 $table->set_attribute('id', 'attempts');
254 $table->set_attribute('class', 'generaltable generalbox');
255
256 // Start working -- this is necessary as soon as the niceties are over.
257 $table->setup();
258 } else if ($download == 'ODS') {
259 require_once("$CFG->libdir/odslib.class.php");
260
261 $filename .= ".ods";
262 // Creating a workbook.
263 $workbook = new MoodleODSWorkbook("-");
264 // Sending HTTP headers.
265 $workbook->send($filename);
266 // Creating the first worksheet.
267 $sheettitle = get_string('report', 'scorm');
268 $myxls = $workbook->add_worksheet($sheettitle);
269 // Format types.
270 $format = $workbook->add_format();
271 $format->set_bold(0);
272 $formatbc = $workbook->add_format();
273 $formatbc->set_bold(1);
274 $formatbc->set_align('center');
275 $formatb = $workbook->add_format();
276 $formatb->set_bold(1);
277 $formaty = $workbook->add_format();
278 $formaty->set_bg_color('yellow');
279 $formatc = $workbook->add_format();
280 $formatc->set_align('center');
281 $formatr = $workbook->add_format();
282 $formatr->set_bold(1);
283 $formatr->set_color('red');
284 $formatr->set_align('center');
285 $formatg = $workbook->add_format();
286 $formatg->set_bold(1);
287 $formatg->set_color('green');
288 $formatg->set_align('center');
289 // Here starts workshhet headers.
290
291 $colnum = 0;
292 foreach ($headers as $item) {
293 $myxls->write(0, $colnum, $item, $formatbc);
294 $colnum++;
295 }
296 $rownum = 1;
297 } else if ($download =='Excel') {
298 require_once("$CFG->libdir/excellib.class.php");
299
300 $filename .= ".xls";
301 // Creating a workbook.
302 $workbook = new MoodleExcelWorkbook("-");
303 // Sending HTTP headers.
304 $workbook->send($filename);
305 // Creating the first worksheet.
306 $sheettitle = get_string('report', 'scorm');
307 $myxls = $workbook->add_worksheet($sheettitle);
308 // Format types.
309 $format = $workbook->add_format();
310 $format->set_bold(0);
311 $formatbc = $workbook->add_format();
312 $formatbc->set_bold(1);
313 $formatbc->set_align('center');
314 $formatb = $workbook->add_format();
315 $formatb->set_bold(1);
316 $formaty = $workbook->add_format();
317 $formaty->set_bg_color('yellow');
318 $formatc = $workbook->add_format();
319 $formatc->set_align('center');
320 $formatr = $workbook->add_format();
321 $formatr->set_bold(1);
322 $formatr->set_color('red');
323 $formatr->set_align('center');
324 $formatg = $workbook->add_format();
325 $formatg->set_bold(1);
326 $formatg->set_color('green');
327 $formatg->set_align('center');
328
329 $colnum = 0;
330 foreach ($headers as $item) {
331 $myxls->write(0, $colnum, $item, $formatbc);
332 $colnum++;
333 }
334 $rownum = 1;
335 } else if ($download == 'CSV') {
336 $csvexport = new csv_export_writer("tab");
337 $csvexport->set_filename($filename, ".txt");
338 $csvexport->add_data($headers);
339 }
340
341 if (!$download) {
342 $sort = $table->get_sql_sort();
343 } else {
344 $sort = '';
345 }
346 // Fix some wired sorting.
347 if (empty($sort)) {
348 $sort = ' ORDER BY uniqueid';
349 } else {
350 $sort = ' ORDER BY '.$sort;
351 }
352
353 if (!$download) {
354 // Add extra limits due to initials bar.
355 list($twhere, $tparams) = $table->get_sql_where();
356 if ($twhere) {
357 $where .= ' AND '.$twhere; // Initial bar.
358 $params = array_merge($params, $tparams);
359 }
360
361 if (!empty($countsql)) {
362 $count = $DB->get_record_sql($countsql, $params);
363 $totalinitials = $count->nbresults;
364 if ($twhere) {
365 $countsql .= ' AND '.$twhere;
366 }
367 $count = $DB->get_record_sql($countsql, $params);
368 $total = $count->nbresults;
369 }
370
371 $table->pagesize($pagesize, $total);
372
373 echo '<div class="quizattemptcounts">';
374 if ( $count->nbresults == $count->nbattempts ) {
375 echo get_string('reportcountattempts', 'scorm', $count);
376 } else if ( $count->nbattempts>0 ) {
377 echo get_string('reportcountallattempts', 'scorm', $count);
378 } else {
379 echo $count->nbusers.' '.get_string('users');
380 }
381 echo '</div>';
382 }
383
384 // Fetch the attempts.
385 if (!$download) {
386 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params,
387 $table->get_page_start(), $table->get_page_size());
388 echo '<div id="scormtablecontainer">';
389 if ($candelete) {
390 // Start form.
391 $strreallydel = addslashes_js(get_string('deleteattemptcheck', 'scorm'));
392 echo '<form id="attemptsform" method="post" action="' . $PAGE->url->out(false) .
393 '" onsubmit="return confirm(\''.$strreallydel.'\');">';
394 echo '<input type="hidden" name="action" value="delete"/>';
395 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
396 echo '<div style="display: none;">';
397 echo html_writer::input_hidden_params($PAGE->url);
398 echo '</div>';
399 echo '<div>';
400 }
401 $table->initialbars($totalinitials>20); // Build table rows.
402 } else {
403 $attempts = $DB->get_records_sql($select.$from.$where.$sort, $params);
404 }
405 if ($attempts) {
406 foreach ($attempts as $scouser) {
407 $row = array();
408 if (!empty($scouser->attempt)) {
409 $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $scouser->attempt);
410 } else {
411 $timetracks = '';
412 }
413 if (in_array('checkbox', $columns)) {
414 if ($candelete && !empty($timetracks->start)) {
415 $row[] = '<input type="checkbox" name="attemptid[]" value="'.
416 $scouser->userid . ':' . $scouser->attempt . '" />';
417 } else if ($candelete) {
418 $row[] = '';
419 }
420 }
421 if (in_array('picture', $columns)) {
422 $user = (object)array(
423 'id'=>$scouser->userid,
424 'picture'=>$scouser->picture,
425 'imagealt'=>$scouser->imagealt,
426 'email'=>$scouser->email,
427 'firstname'=>$scouser->firstname,
428 'lastname'=>$scouser->lastname);
429 $row[] = $OUTPUT->user_picture($user, array('courseid'=>$course->id));
430 }
431 if (!$download) {
432 $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.
433 '&amp;course='.$course->id.'">'.fullname($scouser).'</a>';
434 } else {
435 $row[] = fullname($scouser);
436 }
437 foreach ($extrafields as $field) {
438 $row[] = s($scouser->{$field});
439 }
440 if (empty($timetracks->start)) {
441 $row[] = '-';
442 $row[] = '-';
443 $row[] = '-';
444 $row[] = '-';
445 } else {
446 if (!$download) {
447 $row[] = '<a href="userreport.php?a='.$scorm->id.'&amp;user='.$scouser->userid.
448 '&amp;attempt='.$scouser->attempt.'">'.$scouser->attempt.'</a>';
449 } else {
450 $row[] = $scouser->attempt;
451 }
452 if ($download =='ODS' || $download =='Excel' ) {
453 $row[] = userdate($timetracks->start, get_string("strftimedatetime", "langconfig"));
454 } else {
455 $row[] = userdate($timetracks->start);
456 }
457 if ($download =='ODS' || $download =='Excel' ) {
458 $row[] = userdate($timetracks->finish, get_string('strftimedatetime', 'langconfig'));
459 } else {
460 $row[] = userdate($timetracks->finish);
461 }
462 $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $scouser->attempt);
463 }
464 // Print out all scores of attempt.
465 foreach ($scoes as $sco) {
466 if ($sco->launch != '') {
467 if ($trackdata = scorm_get_tracks($sco->id, $scouser->userid, $scouser->attempt)) {
468 if ($trackdata->status == '') {
469 $trackdata->status = 'notattempted';
470 }
471 $strstatus = get_string($trackdata->status, 'scorm');
472
473 if ($trackdata->score_raw != '') { // If raw score exists, print it.
474 $score = $trackdata->score_raw;
475 // Add max score if it exists.
476 if (isset($trackdata->score_max)) {
477 $score .= '/'.$trackdata->score_max;
478 }
479
480 } else { // ...else print out status.
481 $score = $strstatus;
482 }
483 if (!$download) {
484 $row[] = '<img src="'.$OUTPUT->pix_url($trackdata->status, 'scorm').'" alt="'.
485 $strstatus.'" title="'.$strstatus.'" /><br/><a href="userreport.php?b='.
486 $sco->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$scouser->attempt.
487 '" title="'.get_string('details', 'scorm').'">'.$score.'</a>';
488 } else {
489 $row[] = $score;
490 }
491 // Iterate over tracks and match objective id against values.
492 $keywords = array("cmi.objectives_", ".id");
493 $objectivestatus = array();
494 $objectivescore = array();
495 foreach ($trackdata as $name => $value) {
496 if (strpos($name, 'cmi.objectives_') === 0 && strrpos($name, '.id') !== false) {
497 $num = trim(str_ireplace($keywords, '', $name));
498 if (is_numeric($num)) {
499 if (scorm_version_check($scorm->version, SCORM_13)) {
500 $element='cmi.objectives_'.$num.'.completion_status';
501 } else {
502 $element='cmi.objectives_'.$num.'.status';
503 }
504 if (isset($trackdata->$element)) {
505 $objectivestatus[$value] = $trackdata->$element;
506 } else {
507 $objectivestatus[$value] = '';
508 }
509 if ($displayoptions['objectivescore']) {
510 $element='cmi.objectives_'.$num.'.score.raw';
511 if (isset($trackdata->$element)) {
512 $objectivescore[$value] = $trackdata->$element;
513 } else {
514 $objectivescore[$value] = '';
515 }
516 }
517 }
518 }
519 }
520
521 // Interaction data.
522 if (!empty($objectives[$trackdata->scoid])) {
523 foreach ($objectives[$trackdata->scoid] as $name) {
524 if (isset($objectivestatus[$name])) {
525 $row[] = s($objectivestatus[$name]);
526 } else {
527 $row[] = $emptycell;
528 }
529 if ($displayoptions['objectivescore']) {
530 if (isset($objectivescore[$name])) {
531 $row[] = s($objectivescore[$name]);
532 } else {
533 $row[] = $emptycell;
534 }
535
536 }
537 }
538 }
539 // End of interaction data.
540 } else {
541 // If we don't have track data, we haven't attempted yet.
542 $strstatus = get_string('notattempted', 'scorm');
543 if (!$download) {
544 $row[] = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.
545 $strstatus.'" title="'.$strstatus.'" /><br/>'.$strstatus;
546 } else {
547 $row[] = $strstatus;
548 }
549 // Complete the empty cells.
550 for ($i=0; $i < count($columns) - $nbmaincolumns; $i++) {
551 $row[] = $emptycell;
552 }
553 }
554 }
555 }
556
557 if (!$download) {
558 $table->add_data($row);
559 } else if ($download == 'Excel' or $download == 'ODS') {
560 $colnum = 0;
561 foreach ($row as $item) {
562 $myxls->write($rownum, $colnum, $item, $format);
563 $colnum++;
564 }
565 $rownum++;
566 } else if ($download == 'CSV') {
567 $csvexport->add_data($row);
568 }
569 }
570 if (!$download) {
571 $table->finish_output();
572 if ($candelete) {
573 echo '<table id="commands">';
574 echo '<tr><td>';
575 echo '<a href="javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');">'.
576 get_string('selectall', 'scorm').'</a> / ';
577 echo '<a href="javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');">'.
578 get_string('selectnone', 'scorm').'</a> ';
579 echo '&nbsp;&nbsp;';
580 echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
581 echo '</td></tr></table>';
582 // Close form.
583 echo '</div>';
584 echo '</form>';
585 }
586 echo '</div>';
587 if (!empty($attempts)) {
588 echo '<table class="boxaligncenter"><tr>';
589 echo '<td>';
590 echo $OUTPUT->single_button(new moodle_url($PAGE->url,
591 array('download'=>'ODS') + $displayoptions),
592 get_string('downloadods'));
593 echo "</td>\n";
594 echo '<td>';
595 echo $OUTPUT->single_button(new moodle_url($PAGE->url,
596 array('download'=>'Excel') + $displayoptions),
597 get_string('downloadexcel'));
598 echo "</td>\n";
599 echo '<td>';
600 echo $OUTPUT->single_button(new moodle_url($PAGE->url,
601 array('download'=>'CSV') + $displayoptions),
602 get_string('downloadtext'));
603 echo "</td>\n";
604 echo "<td>";
605 echo "</td>\n";
606 echo '</tr></table>';
607 }
608 }
609 } else {
610 if ($candelete && !$download) {
611 echo '</div>';
612 echo '</form>';
613 $table->finish_output();
614 }
615 echo '</div>';
616 }
617 // Show preferences form irrespective of attempts are there to report or not.
618 if (!$download) {
619 $mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
620 $mform->display();
621 }
622 if ($download == 'Excel' or $download == 'ODS') {
623 $workbook->close();
624 exit;
625 } else if ($download == 'CSV') {
626 $csvexport->download_file();
627 exit;
628 }
629 } else {
630 echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
631 }
632 }// Function ends.
633}
634
635/**
636 * Returns The maximum numbers of Objectives associated with an Scorm Pack
637 *
638 * @param int $scormid Scorm instance id
639 * @return array an array of possible objectives.
640 */
641function get_scorm_objectives($scormid) {
642 global $DB;
643 $objectives = array();
644 $params = array();
645 $select = "scormid = ? AND ";
646 $select .= $DB->sql_like("element", "?", false);
647 $params[] = $scormid;
648 $params[] = "cmi.objectives_%.id";
649 $rs = $DB->get_recordset_select("scorm_scoes_track", $select, $params, 'value', 'DISTINCT value, scoid');
650 if ($rs->valid()) {
651 foreach ($rs as $record) {
652 $objectives[$record->scoid][] = $record->value;
653 }
654 // Now naturally sort the sco arrays.
655 foreach ($objectives as $scoid => $sco) {
656 natsort($objectives[$scoid]);
657 }
658 }
659 $rs->close();
660 return $objectives;
661}