[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/report/completion/ -> index.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  /**
  18   * Course completion progress report
  19   *
  20   * @package    report
  21   * @subpackage completion
  22   * @copyright  2009 Catalyst IT Ltd
  23   * @author     Aaron Barnes <[email protected]>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  require_once(dirname(__FILE__).'/../../config.php');
  28  require_once("{$CFG->libdir}/completionlib.php");
  29  
  30  /**
  31   * Configuration
  32   */
  33  define('COMPLETION_REPORT_PAGE',        25);
  34  define('COMPLETION_REPORT_COL_TITLES',  true);
  35  
  36  /*
  37   * Setup page, check permissions
  38   */
  39  
  40  // Get course
  41  $courseid = required_param('course', PARAM_INT);
  42  $format = optional_param('format','',PARAM_ALPHA);
  43  $sort = optional_param('sort','',PARAM_ALPHA);
  44  $edituser = optional_param('edituser', 0, PARAM_INT);
  45  
  46  
  47  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  48  $context = context_course::instance($course->id);
  49  
  50  $url = new moodle_url('/report/completion/index.php', array('course'=>$course->id));
  51  $PAGE->set_url($url);
  52  $PAGE->set_pagelayout('report');
  53  
  54  $firstnamesort = ($sort == 'firstname');
  55  $excel = ($format == 'excelcsv');
  56  $csv = ($format == 'csv' || $excel);
  57  
  58  // Load CSV library
  59  if ($csv) {
  60      require_once("{$CFG->libdir}/csvlib.class.php");
  61  }
  62  
  63  // Paging
  64  $start   = optional_param('start', 0, PARAM_INT);
  65  $sifirst = optional_param('sifirst', 'all', PARAM_ALPHA);
  66  $silast  = optional_param('silast', 'all', PARAM_ALPHA);
  67  
  68  // Whether to show extra user identity information
  69  $extrafields = get_extra_user_fields($context);
  70  $leftcols = 1 + count($extrafields);
  71  
  72  // Check permissions
  73  require_login($course);
  74  
  75  require_capability('report/completion:view', $context);
  76  
  77  // Get group mode
  78  $group = groups_get_course_group($course, true); // Supposed to verify group
  79  if ($group === 0 && $course->groupmode == SEPARATEGROUPS) {
  80      require_capability('moodle/site:accessallgroups',$context);
  81  }
  82  
  83  /**
  84   * Load data
  85   */
  86  
  87  // Retrieve course_module data for all modules in the course
  88  $modinfo = get_fast_modinfo($course);
  89  
  90  // Get criteria for course
  91  $completion = new completion_info($course);
  92  
  93  if (!$completion->has_criteria()) {
  94      print_error('err_nocriteria', 'completion', $CFG->wwwroot.'/course/report.php?id='.$course->id);
  95  }
  96  
  97  // Get criteria and put in correct order
  98  $criteria = array();
  99  
 100  foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_COURSE) as $criterion) {
 101      $criteria[] = $criterion;
 102  }
 103  
 104  foreach ($completion->get_criteria(COMPLETION_CRITERIA_TYPE_ACTIVITY) as $criterion) {
 105      $criteria[] = $criterion;
 106  }
 107  
 108  foreach ($completion->get_criteria() as $criterion) {
 109      if (!in_array($criterion->criteriatype, array(
 110              COMPLETION_CRITERIA_TYPE_COURSE, COMPLETION_CRITERIA_TYPE_ACTIVITY))) {
 111          $criteria[] = $criterion;
 112      }
 113  }
 114  
 115  // Can logged in user mark users as complete?
 116  // (if the logged in user has a role defined in the role criteria)
 117  $allow_marking = false;
 118  $allow_marking_criteria = null;
 119  
 120  if (!$csv) {
 121      // Get role criteria
 122      $rcriteria = $completion->get_criteria(COMPLETION_CRITERIA_TYPE_ROLE);
 123  
 124      if (!empty($rcriteria)) {
 125  
 126          foreach ($rcriteria as $rcriterion) {
 127              $users = get_role_users($rcriterion->role, $context, true);
 128  
 129              // If logged in user has this role, allow marking complete
 130              if ($users && in_array($USER->id, array_keys($users))) {
 131                  $allow_marking = true;
 132                  $allow_marking_criteria = $rcriterion->id;
 133                  break;
 134              }
 135          }
 136      }
 137  }
 138  
 139  /*
 140   * Setup page header
 141   */
 142  if ($csv) {
 143  
 144      $shortname = format_string($course->shortname, true, array('context' => $context));
 145      $shortname = preg_replace('/[^a-z0-9-]/', '_',core_text::strtolower(strip_tags($shortname)));
 146  
 147      $export = new csv_export_writer();
 148      $export->set_filename('completion-'.$shortname);
 149  
 150  } else {
 151      // Navigation and header
 152      $strcompletion = get_string('coursecompletion');
 153  
 154      $PAGE->set_title($strcompletion);
 155      $PAGE->set_heading($course->fullname);
 156  
 157      echo $OUTPUT->header();
 158  
 159      $PAGE->requires->js('/report/completion/textrotate.js');
 160      $PAGE->requires->js_function_call('textrotate_init', null, true);
 161  
 162      // Handle groups (if enabled)
 163      groups_print_course_menu($course, $CFG->wwwroot.'/report/completion/?course='.$course->id);
 164  }
 165  
 166  // Generate where clause
 167  $where = array();
 168  $where_params = array();
 169  
 170  if ($sifirst !== 'all') {
 171      $where[] = $DB->sql_like('u.firstname', ':sifirst', false);
 172      $where_params['sifirst'] = $sifirst.'%';
 173  }
 174  
 175  if ($silast !== 'all') {
 176      $where[] = $DB->sql_like('u.lastname', ':silast', false);
 177      $where_params['silast'] = $silast.'%';
 178  }
 179  
 180  // Get user match count
 181  $total = $completion->get_num_tracked_users(implode(' AND ', $where), $where_params, $group);
 182  
 183  // Total user count
 184  $grandtotal = $completion->get_num_tracked_users('', array(), $group);
 185  
 186  // If no users in this course what-so-ever
 187  if (!$grandtotal) {
 188      echo $OUTPUT->container(get_string('err_nousers', 'completion'), 'errorbox errorboxcontent');
 189      echo $OUTPUT->footer();
 190      exit;
 191  }
 192  
 193  // Get user data
 194  $progress = array();
 195  
 196  if ($total) {
 197      $progress = $completion->get_progress_all(
 198          implode(' AND ', $where),
 199          $where_params,
 200          $group,
 201          $firstnamesort ? 'u.firstname ASC' : 'u.lastname ASC',
 202          $csv ? 0 : COMPLETION_REPORT_PAGE,
 203          $csv ? 0 : $start,
 204          $context
 205      );
 206  }
 207  
 208  // Build link for paging
 209  $link = $CFG->wwwroot.'/report/completion/?course='.$course->id;
 210  if (strlen($sort)) {
 211      $link .= '&amp;sort='.$sort;
 212  }
 213  $link .= '&amp;start=';
 214  
 215  // Build the the page by Initial bar
 216  $initials = array('first', 'last');
 217  $alphabet = explode(',', get_string('alphabet', 'langconfig'));
 218  
 219  $pagingbar = '';
 220  foreach ($initials as $initial) {
 221      $var = 'si'.$initial;
 222  
 223      $othervar = $initial == 'first' ? 'silast' : 'sifirst';
 224      $othervar = $$othervar != 'all' ? "&amp;{$othervar}={$$othervar}" : '';
 225  
 226      $pagingbar .= ' <div class="initialbar '.$initial.'initial">';
 227      $pagingbar .= get_string($initial.'name').':&nbsp;';
 228  
 229      if ($$var == 'all') {
 230          $pagingbar .= '<strong>'.get_string('all').'</strong> ';
 231      }
 232      else {
 233          $pagingbar .= "<a href=\"{$link}{$othervar}\">".get_string('all').'</a> ';
 234      }
 235  
 236      foreach ($alphabet as $letter) {
 237          if ($$var === $letter) {
 238              $pagingbar .= '<strong>'.$letter.'</strong> ';
 239          }
 240          else {
 241              $pagingbar .= "<a href=\"$link&amp;$var={$letter}{$othervar}\">$letter</a> ";
 242          }
 243      }
 244  
 245      $pagingbar .= '</div>';
 246  }
 247  
 248  // Do we need a paging bar?
 249  if ($total > COMPLETION_REPORT_PAGE) {
 250  
 251      // Paging bar
 252      $pagingbar .= '<div class="paging">';
 253      $pagingbar .= get_string('page').': ';
 254  
 255      $sistrings = array();
 256      if ($sifirst != 'all') {
 257          $sistrings[] =  "sifirst={$sifirst}";
 258      }
 259      if ($silast != 'all') {
 260          $sistrings[] =  "silast={$silast}";
 261      }
 262      $sistring = !empty($sistrings) ? '&amp;'.implode('&amp;', $sistrings) : '';
 263  
 264      // Display previous link
 265      if ($start > 0) {
 266          $pstart = max($start - COMPLETION_REPORT_PAGE, 0);
 267          $pagingbar .= "(<a class=\"previous\" href=\"{$link}{$pstart}{$sistring}\">".get_string('previous').'</a>)&nbsp;';
 268      }
 269  
 270      // Create page links
 271      $curstart = 0;
 272      $curpage = 0;
 273      while ($curstart < $total) {
 274          $curpage++;
 275  
 276          if ($curstart == $start) {
 277              $pagingbar .= '&nbsp;'.$curpage.'&nbsp;';
 278          }
 279          else {
 280              $pagingbar .= "&nbsp;<a href=\"{$link}{$curstart}{$sistring}\">$curpage</a>&nbsp;";
 281          }
 282  
 283          $curstart += COMPLETION_REPORT_PAGE;
 284      }
 285  
 286      // Display next link
 287      $nstart = $start + COMPLETION_REPORT_PAGE;
 288      if ($nstart < $total) {
 289          $pagingbar .= "&nbsp;(<a class=\"next\" href=\"{$link}{$nstart}{$sistring}\">".get_string('next').'</a>)';
 290      }
 291  
 292      $pagingbar .= '</div>';
 293  }
 294  
 295  /*
 296   * Draw table header
 297   */
 298  
 299  // Start of table
 300  if (!$csv) {
 301      print '<br class="clearer"/>'; // ugh
 302  
 303      $total_header = ($total == $grandtotal) ? $total : "{$total}/{$grandtotal}";
 304      echo $OUTPUT->heading(get_string('allparticipants').": {$total_header}", 3);
 305  
 306      print $pagingbar;
 307  
 308      if (!$total) {
 309          echo $OUTPUT->heading(get_string('nothingtodisplay'), 2);
 310          echo $OUTPUT->footer();
 311          exit;
 312      }
 313  
 314      print '<table id="completion-progress" class="generaltable flexible boxaligncenter completionreport" style="text-align: left" cellpadding="5" border="1">';
 315  
 316      // Print criteria group names
 317      print PHP_EOL.'<thead><tr style="vertical-align: top">';
 318      echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
 319              get_string('criteriagroup', 'completion') . '</th>';
 320  
 321      $current_group = false;
 322      $col_count = 0;
 323      for ($i = 0; $i <= count($criteria); $i++) {
 324  
 325          if (isset($criteria[$i])) {
 326              $criterion = $criteria[$i];
 327  
 328              if ($current_group && $criterion->criteriatype === $current_group->criteriatype) {
 329                  ++$col_count;
 330                  continue;
 331              }
 332          }
 333  
 334          // Print header cell
 335          if ($col_count) {
 336              print '<th scope="col" colspan="'.$col_count.'" class="colheader criteriagroup">'.$current_group->get_type_title().'</th>';
 337          }
 338  
 339          if (isset($criteria[$i])) {
 340              // Move to next criteria type
 341              $current_group = $criterion;
 342              $col_count = 1;
 343          }
 344      }
 345  
 346      // Overall course completion status
 347      print '<th style="text-align: center;">'.get_string('course').'</th>';
 348  
 349      print '</tr>';
 350  
 351      // Print aggregation methods
 352      print PHP_EOL.'<tr style="vertical-align: top">';
 353      echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
 354              get_string('aggregationmethod', 'completion').'</th>';
 355  
 356      $current_group = false;
 357      $col_count = 0;
 358      for ($i = 0; $i <= count($criteria); $i++) {
 359  
 360          if (isset($criteria[$i])) {
 361              $criterion = $criteria[$i];
 362  
 363              if ($current_group && $criterion->criteriatype === $current_group->criteriatype) {
 364                  ++$col_count;
 365                  continue;
 366              }
 367          }
 368  
 369          // Print header cell
 370          if ($col_count) {
 371              $has_agg = array(
 372                  COMPLETION_CRITERIA_TYPE_COURSE,
 373                  COMPLETION_CRITERIA_TYPE_ACTIVITY,
 374                  COMPLETION_CRITERIA_TYPE_ROLE,
 375              );
 376  
 377              if (in_array($current_group->criteriatype, $has_agg)) {
 378                  // Try load a aggregation method
 379                  $method = $completion->get_aggregation_method($current_group->criteriatype);
 380  
 381                  $method = $method == 1 ? get_string('all') : get_string('any');
 382  
 383              } else {
 384                  $method = '-';
 385              }
 386  
 387              print '<th scope="col" colspan="'.$col_count.'" class="colheader aggheader">'.$method.'</th>';
 388          }
 389  
 390          if (isset($criteria[$i])) {
 391              // Move to next criteria type
 392              $current_group = $criterion;
 393              $col_count = 1;
 394          }
 395      }
 396  
 397      // Overall course aggregation method
 398      print '<th scope="col" class="colheader aggheader aggcriteriacourse">';
 399  
 400      // Get course aggregation
 401      $method = $completion->get_aggregation_method();
 402  
 403      print $method == 1 ? get_string('all') : get_string('any');
 404      print '</th>';
 405  
 406      print '</tr>';
 407  
 408      // Print criteria titles
 409      if (COMPLETION_REPORT_COL_TITLES) {
 410  
 411          print PHP_EOL.'<tr>';
 412          echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
 413                  get_string('criteria', 'completion') . '</th>';
 414  
 415          foreach ($criteria as $criterion) {
 416              // Get criteria details
 417              $details = $criterion->get_title_detailed();
 418              print '<th scope="col" class="colheader criterianame">';
 419              print '<span class="completion-criterianame">'.$details.'</span>';
 420              print '</th>';
 421          }
 422  
 423          // Overall course completion status
 424          print '<th scope="col" class="colheader criterianame">';
 425          print '<span class="completion-criterianame">'.get_string('coursecomplete', 'completion').'</span>';
 426          print '</th></tr>';
 427      }
 428  
 429      // Print user heading and icons
 430      print '<tr>';
 431  
 432      // User heading / sort option
 433      print '<th scope="col" class="completion-sortchoice" style="clear: both;">';
 434  
 435      $sistring = "&amp;silast={$silast}&amp;sifirst={$sifirst}";
 436  
 437      if ($firstnamesort) {
 438          print
 439              get_string('firstname')." / <a href=\"./?course={$course->id}{$sistring}\">".
 440              get_string('lastname').'</a>';
 441      } else {
 442          print "<a href=\"./?course={$course->id}&amp;sort=firstname{$sistring}\">".
 443              get_string('firstname').'</a> / '.
 444              get_string('lastname');
 445      }
 446      print '</th>';
 447  
 448      // Print user identity columns
 449      foreach ($extrafields as $field) {
 450          echo '<th scope="col" class="completion-identifyfield">' .
 451                  get_user_field_name($field) . '</th>';
 452      }
 453  
 454      ///
 455      /// Print criteria icons
 456      ///
 457      foreach ($criteria as $criterion) {
 458  
 459          // Generate icon details
 460          $icon = '';
 461          $iconlink = '';
 462          $icontitle = ''; // Required if $iconlink set
 463          $iconalt = ''; // Required
 464          switch ($criterion->criteriatype) {
 465  
 466              case COMPLETION_CRITERIA_TYPE_ACTIVITY:
 467  
 468                  // Display icon
 469                  $icon = $OUTPUT->pix_url('icon', $criterion->module);
 470                  $iconlink = $CFG->wwwroot.'/mod/'.$criterion->module.'/view.php?id='.$criterion->moduleinstance;
 471                  $icontitle = $modinfo->cms[$criterion->moduleinstance]->name;
 472                  $iconalt = get_string('modulename', $criterion->module);
 473                  break;
 474  
 475              case COMPLETION_CRITERIA_TYPE_COURSE:
 476                  // Load course
 477                  $crs = $DB->get_record('course', array('id' => $criterion->courseinstance));
 478  
 479                  // Display icon
 480                  $iconlink = $CFG->wwwroot.'/course/view.php?id='.$criterion->courseinstance;
 481                  $icontitle = format_string($crs->fullname, true, array('context' => context_course::instance($crs->id, MUST_EXIST)));
 482                  $iconalt = format_string($crs->shortname, true, array('context' => context_course::instance($crs->id)));
 483                  break;
 484  
 485              case COMPLETION_CRITERIA_TYPE_ROLE:
 486                  // Load role
 487                  $role = $DB->get_record('role', array('id' => $criterion->role));
 488  
 489                  // Display icon
 490                  $iconalt = $role->name;
 491                  break;
 492          }
 493  
 494          // Print icon and cell
 495          print '<th class="criteriaicon">';
 496  
 497          // Create icon if not supplied
 498          if (!$icon) {
 499              $icon = $OUTPUT->pix_url('i/'.$COMPLETION_CRITERIA_TYPES[$criterion->criteriatype]);
 500          }
 501  
 502          print ($iconlink ? '<a href="'.$iconlink.'" title="'.$icontitle.'">' : '');
 503          print '<img src="'.$icon.'" class="icon" alt="'.$iconalt.'" '.(!$iconlink ? 'title="'.$iconalt.'"' : '').' />';
 504          print ($iconlink ? '</a>' : '');
 505  
 506          print '</th>';
 507      }
 508  
 509      // Overall course completion status
 510      print '<th class="criteriaicon">';
 511      print '<img src="'.$OUTPUT->pix_url('i/course').'" class="icon" alt="'.get_string('course').'" title="'.get_string('coursecomplete', 'completion').'" />';
 512      print '</th>';
 513  
 514      print '</tr></thead>';
 515  
 516      echo '<tbody>';
 517  } else {
 518      // The CSV headers
 519      $row = array();
 520  
 521      $row[] = get_string('id', 'report_completion');
 522      $row[] = get_string('name', 'report_completion');
 523      foreach ($extrafields as $field) {
 524         $row[] = get_user_field_name($field);
 525      }
 526  
 527      // Add activity headers
 528      foreach ($criteria as $criterion) {
 529  
 530          // Handle activity completion differently
 531          if ($criterion->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
 532  
 533              // Load activity
 534              $mod = $criterion->get_mod_instance();
 535              $row[] = $mod->name;
 536              $row[] = $mod->name . ' - ' . get_string('completiondate', 'report_completion');
 537          }
 538          else {
 539              // Handle all other criteria
 540              $row[] = strip_tags($criterion->get_title_detailed());
 541          }
 542      }
 543  
 544      $row[] = get_string('coursecomplete', 'completion');
 545  
 546      $export->add_data($row);
 547  }
 548  
 549  ///
 550  /// Display a row for each user
 551  ///
 552  foreach ($progress as $user) {
 553  
 554      // User name
 555      if ($csv) {
 556          $row = array();
 557          $row[] = $user->id;
 558          $row[] = fullname($user);
 559          foreach ($extrafields as $field) {
 560              $row[] = $user->{$field};
 561          }
 562      } else {
 563          print PHP_EOL.'<tr id="user-'.$user->id.'">';
 564  
 565          if (completion_can_view_data($user->id, $course)) {
 566              $userurl = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
 567          } else {
 568              $userurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
 569          }
 570  
 571          print '<th scope="row"><a href="'.$userurl->out().'">'.fullname($user).'</a></th>';
 572          foreach ($extrafields as $field) {
 573              echo '<td>'.s($user->{$field}).'</td>';
 574          }
 575      }
 576  
 577      // Progress for each course completion criteria
 578      foreach ($criteria as $criterion) {
 579  
 580          $criteria_completion = $completion->get_user_completion($user->id, $criterion);
 581          $is_complete = $criteria_completion->is_complete();
 582  
 583          // Handle activity completion differently
 584          if ($criterion->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
 585  
 586              // Load activity
 587              $activity = $modinfo->cms[$criterion->moduleinstance];
 588  
 589              // Get progress information and state
 590              if (array_key_exists($activity->id, $user->progress)) {
 591                  $state = $user->progress[$activity->id]->completionstate;
 592              } else if ($is_complete) {
 593                  $state = COMPLETION_COMPLETE;
 594              } else {
 595                  $state = COMPLETION_INCOMPLETE;
 596              }
 597              if ($is_complete) {
 598                  $date = userdate($criteria_completion->timecompleted, get_string('strftimedatetimeshort', 'langconfig'));
 599              } else {
 600                  $date = '';
 601              }
 602  
 603              // Work out how it corresponds to an icon
 604              switch($state) {
 605                  case COMPLETION_INCOMPLETE    : $completiontype = 'n';    break;
 606                  case COMPLETION_COMPLETE      : $completiontype = 'y';    break;
 607                  case COMPLETION_COMPLETE_PASS : $completiontype = 'pass'; break;
 608                  case COMPLETION_COMPLETE_FAIL : $completiontype = 'fail'; break;
 609              }
 610  
 611              $auto = $activity->completion == COMPLETION_TRACKING_AUTOMATIC;
 612              $completionicon = 'completion-'.($auto ? 'auto' : 'manual').'-'.$completiontype;
 613  
 614              $describe = get_string('completion-'.$completiontype, 'completion');
 615              $a = new StdClass();
 616              $a->state     = $describe;
 617              $a->date      = $date;
 618              $a->user      = fullname($user);
 619              $a->activity  = strip_tags($activity->name);
 620              $fulldescribe = get_string('progress-title', 'completion', $a);
 621  
 622              if ($csv) {
 623                  $row[] = $describe;
 624                  $row[] = $date;
 625              } else {
 626                  print '<td class="completion-progresscell">';
 627  
 628                  print '<img src="'.$OUTPUT->pix_url('i/'.$completionicon).
 629                        '" alt="'.$describe.'" class="icon" title="'.$fulldescribe.'" />';
 630  
 631                  print '</td>';
 632              }
 633  
 634              continue;
 635          }
 636  
 637          // Handle all other criteria
 638          $completiontype = $is_complete ? 'y' : 'n';
 639          $completionicon = 'completion-auto-'.$completiontype;
 640  
 641          $describe = get_string('completion-'.$completiontype, 'completion');
 642  
 643          $a = new stdClass();
 644          $a->state    = $describe;
 645  
 646          if ($is_complete) {
 647              $a->date = userdate($criteria_completion->timecompleted, get_string('strftimedatetimeshort', 'langconfig'));
 648          } else {
 649              $a->date = '';
 650          }
 651  
 652          $a->user     = fullname($user);
 653          $a->activity = strip_tags($criterion->get_title());
 654          $fulldescribe = get_string('progress-title', 'completion', $a);
 655  
 656          if ($csv) {
 657              $row[] = $a->date;
 658          } else {
 659  
 660              print '<td class="completion-progresscell">';
 661  
 662              if ($allow_marking_criteria === $criterion->id) {
 663                  $describe = get_string('completion-'.$completiontype, 'completion');
 664  
 665                  $toggleurl = new moodle_url(
 666                      '/course/togglecompletion.php',
 667                      array(
 668                          'user' => $user->id,
 669                          'course' => $course->id,
 670                          'rolec' => $allow_marking_criteria,
 671                          'sesskey' => sesskey()
 672                      )
 673                  );
 674  
 675                  print '<a href="'.$toggleurl->out().'"><img src="'.$OUTPUT->pix_url('i/completion-manual-'.($is_complete ? 'y' : 'n')).
 676                      '" alt="'.$describe.'" class="icon" title="'.get_string('markcomplete', 'completion').'" /></a></td>';
 677              } else {
 678                  print '<img src="'.$OUTPUT->pix_url('i/'.$completionicon).'" alt="'.$describe.'" class="icon" title="'.$fulldescribe.'" /></td>';
 679              }
 680  
 681              print '</td>';
 682          }
 683      }
 684  
 685      // Handle overall course completion
 686  
 687      // Load course completion
 688      $params = array(
 689          'userid'    => $user->id,
 690          'course'    => $course->id
 691      );
 692  
 693      $ccompletion = new completion_completion($params);
 694      $completiontype =  $ccompletion->is_complete() ? 'y' : 'n';
 695  
 696      $describe = get_string('completion-'.$completiontype, 'completion');
 697  
 698      $a = new StdClass;
 699  
 700      if ($ccompletion->is_complete()) {
 701          $a->date = userdate($ccompletion->timecompleted, get_string('strftimedatetimeshort', 'langconfig'));
 702      } else {
 703          $a->date = '';
 704      }
 705  
 706      $a->state    = $describe;
 707      $a->user     = fullname($user);
 708      $a->activity = strip_tags(get_string('coursecomplete', 'completion'));
 709      $fulldescribe = get_string('progress-title', 'completion', $a);
 710  
 711      if ($csv) {
 712          $row[] = $a->date;
 713      } else {
 714  
 715          print '<td class="completion-progresscell">';
 716  
 717          // Display course completion status icon
 718          print '<img src="'.$OUTPUT->pix_url('i/completion-auto-'.$completiontype).
 719                 '" alt="'.$describe.'" class="icon" title="'.$fulldescribe.'" />';
 720  
 721          print '</td>';
 722      }
 723  
 724      if ($csv) {
 725          $export->add_data($row);
 726      } else {
 727          print '</tr>';
 728      }
 729  }
 730  
 731  if ($csv) {
 732      $export->download_file();
 733  } else {
 734      echo '</tbody>';
 735  }
 736  
 737  print '</table>';
 738  print $pagingbar;
 739  
 740  $csvurl = new moodle_url('/report/completion/index.php', array('course' => $course->id, 'format' => 'csv'));
 741  $excelurl = new moodle_url('/report/completion/index.php', array('course' => $course->id, 'format' => 'excelcsv'));
 742  
 743  print '<ul class="export-actions">';
 744  print '<li><a href="'.$csvurl->out().'">'.get_string('csvdownload','completion').'</a></li>';
 745  print '<li><a href="'.$excelurl->out().'">'.get_string('excelcsvdownload','completion').'</a></li>';
 746  print '</ul>';
 747  
 748  echo $OUTPUT->footer($course);
 749  
 750  // Trigger a report viewed event.
 751  $event = \report_completion\event\report_viewed::create(array('context' => $context));
 752  $event->trigger();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1