[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/scorm/report/objectives/classes/ -> report.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1