Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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   * This file is part of the User section Moodle
  19   *
  20   * @copyright 1999 Martin Dougiamas  http://dougiamas.com
  21   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   * @package core_user
  23   */
  24  
  25  require_once(__DIR__ . '/../config.php');
  26  
  27  if (empty($CFG->enableportfolios)) {
  28      throw new \moodle_exception('disabled', 'portfolio');
  29  }
  30  
  31  require_once($CFG->libdir . '/portfoliolib.php');
  32  require_once($CFG->libdir . '/portfolio/exporter.php');
  33  
  34  $courseid = optional_param('courseid', SITEID, PARAM_INT);
  35  $page     = optional_param('page', 0, PARAM_INT);
  36  $perpage  = optional_param('perpage', 10, PARAM_INT);
  37  
  38  if (! $course = $DB->get_record("course", array("id" => $courseid))) {
  39      throw new \moodle_exception('invalidcourseid');
  40  }
  41  
  42  require_login($course, false);
  43  
  44  $user = $USER;
  45  $fullname = fullname($user);
  46  $strportfolios = get_string('portfolios', 'portfolio');
  47  
  48  $url = new moodle_url('/user/portfoliologs.php', array('courseid' => $courseid));
  49  
  50  navigation_node::override_active_url(new moodle_url('/user/portfoliologs.php', array('courseid' => $courseid)));
  51  
  52  if ($page !== 0) {
  53      $url->param('page', $page);
  54  }
  55  if ($perpage !== 0) {
  56      $url->param('perpage', $perpage);
  57  }
  58  
  59  $PAGE->set_url($url);
  60  $PAGE->set_title(get_string('logs', 'portfolio'));
  61  $PAGE->set_heading($fullname);
  62  $PAGE->set_context(context_user::instance($user->id));
  63  $PAGE->set_pagelayout('report');
  64  
  65  echo $OUTPUT->header();
  66  
  67  $showroles = 1;
  68  $somethingprinted = false;
  69  
  70  echo $OUTPUT->box_start();
  71  
  72  $queued = $DB->get_records('portfolio_tempdata', array('userid' => $USER->id), 'expirytime DESC', 'id, expirytime');
  73  if (count($queued) > 0) {
  74      $table = new html_table();
  75      $table->head = array(
  76          get_string('displayarea', 'portfolio'),
  77          get_string('plugin', 'portfolio'),
  78          get_string('displayinfo', 'portfolio'),
  79          get_string('displayexpiry', 'portfolio'),
  80          '',
  81      );
  82      $table->data = array();
  83      $now = time();
  84      foreach ($queued as $q) {
  85          $e = portfolio_exporter::rewaken_object($q->id);
  86          $e->verify_rewaken(true);
  87          $queued = $e->get('queued');
  88          $baseurl = new moodle_url('/portfolio/add.php', array('id' => $q->id, 'logreturn' => 1, 'sesskey' => sesskey()));
  89  
  90          $iconstr = $OUTPUT->action_icon(new moodle_url($baseurl, array('cancel' => 1)), new pix_icon('t/stop', get_string('cancel')));
  91  
  92          if (!$e->get('queued') && $e->get('expirytime') > $now) {
  93              $iconstr .= $OUTPUT->action_icon($baseurl, new pix_icon('t/go', get_string('continue')));
  94          }
  95          $table->data[] = array(
  96              $e->get('caller')->display_name(),
  97              (($e->get('instance')) ? $e->get('instance')->get('name') : get_string('noinstanceyet', 'portfolio')),
  98              $e->get('caller')->heading_summary(),
  99              userdate($q->expirytime),
 100              $iconstr,
 101          );
 102          unset($e); // This could potentially be quite big, so free it.
 103      }
 104      echo $OUTPUT->heading(get_string('queuesummary', 'portfolio'));
 105      echo html_writer::table($table);
 106      $somethingprinted = true;
 107  }
 108  // Paging - get total count separately.
 109  $logcount = $DB->count_records('portfolio_log', array('userid' => $USER->id));
 110  if ($logcount > 0) {
 111      $table = new html_table();
 112      $table->head = array(
 113          get_string('plugin', 'portfolio'),
 114          get_string('displayarea', 'portfolio'),
 115          get_string('transfertime', 'portfolio'),
 116      );
 117      $logs = $DB->get_records('portfolio_log', array('userid' => $USER->id), 'time DESC', '*', ($page * $perpage), $perpage);
 118      foreach ($logs as $log) {
 119          if (!empty($log->caller_file)) {
 120              portfolio_include_callback_file($log->caller_file);
 121          } else if (!empty($log->caller_component)) {
 122              portfolio_include_callback_file($log->caller_component);
 123          } else { // Errrmahgerrrd - this should never happen. Skipping.
 124              continue;
 125          }
 126          $class = $log->caller_class;
 127          $pluginname = '';
 128          try {
 129              $plugin = portfolio_instance($log->portfolio);
 130              $url = $plugin->resolve_static_continue_url($log->continueurl);
 131              if ($url) {
 132                  $pluginname = '<a href="' . $url . '">' . $plugin->get('name') . '</a>';
 133              } else {
 134                  $pluginname = $plugin->get('name');
 135              }
 136          } catch (portfolio_exception $e) { // May have been deleted.
 137              $pluginname = get_string('unknownplugin', 'portfolio');
 138          }
 139  
 140          $table->data[] = array(
 141              $pluginname,
 142              '<a href="' . $log->returnurl . '">' . call_user_func(array($class, 'display_name')) . '</a>',
 143              userdate($log->time),
 144          );
 145      }
 146      echo $OUTPUT->heading(get_string('logsummary', 'portfolio'));
 147      $pagingbar = new paging_bar($logcount, $page, $perpage, $CFG->wwwroot . '/user/portfoliologs.php?');
 148      echo $OUTPUT->render($pagingbar);
 149      echo html_writer::table($table);
 150      echo $OUTPUT->render($pagingbar);
 151      $somethingprinted = true;
 152  }
 153  if (!$somethingprinted) {
 154      echo $OUTPUT->heading($strportfolios);
 155      echo get_string('nologs', 'portfolio');
 156  }
 157  echo $OUTPUT->box_end();
 158  echo $OUTPUT->footer();
 159  
 160