PageRenderTime 72ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/mod/scorm/report/objectives/report.php

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