PageRenderTime 62ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/scorm/report/interactions/classes/report.php

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