Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/user/ -> portfolio.php (source)

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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      print_error('disabled', 'portfolio');
  29  }
  30  
  31  require_once($CFG->libdir . '/portfoliolib.php');
  32  require_once($CFG->libdir . '/portfolio/forms.php');
  33  
  34  $config   = optional_param('config', 0, PARAM_INT);
  35  $hide     = optional_param('hide', 0, PARAM_INT);
  36  $courseid = optional_param('courseid', SITEID, PARAM_INT);
  37  
  38  $url = new moodle_url('/user/portfolio.php', array('courseid' => $courseid));
  39  
  40  if ($config !== 0) {
  41      $url->param('config', $config);
  42  }
  43  if (! $course = $DB->get_record("course", array("id" => $courseid))) {
  44      print_error('invalidcourseid');
  45  }
  46  
  47  $user = $USER;
  48  $fullname = fullname($user);
  49  $strportfolios = get_string('portfolios', 'portfolio');
  50  $configstr = get_string('manageyourportfolios', 'portfolio');
  51  $namestr = get_string('name');
  52  $pluginstr = get_string('plugin', 'portfolio');
  53  $baseurl = $CFG->wwwroot . '/user/portfolio.php';
  54  $introstr = get_string('intro', 'portfolio');
  55  $showhide = get_string('showhide', 'portfolio');
  56  
  57  $display = true; // Set this to false in the conditions to stop processing.
  58  
  59  require_login($course, false);
  60  
  61  $PAGE->set_url($url);
  62  $PAGE->set_context(context_user::instance($user->id));
  63  $PAGE->set_title($configstr);
  64  $PAGE->set_heading($fullname);
  65  $PAGE->set_pagelayout('admin');
  66  
  67  echo $OUTPUT->header();
  68  $showroles = 1;
  69  
  70  if (!empty($config)) {
  71      navigation_node::override_active_url(new moodle_url('/user/portfolio.php', array('courseid' => $courseid)));
  72      $instance = portfolio_instance($config);
  73      $mform = new portfolio_user_form('', array('instance' => $instance, 'userid' => $user->id));
  74      if ($mform->is_cancelled()) {
  75          redirect($baseurl);
  76          exit;
  77      } else if ($fromform = $mform->get_data()) {
  78          if (!confirm_sesskey()) {
  79              print_error('confirmsesskeybad', '', $baseurl);
  80          }
  81          // This branch is where you process validated data.
  82          $instance->set_user_config($fromform, $USER->id);
  83          core_plugin_manager::reset_caches();
  84          redirect($baseurl, get_string('instancesaved', 'portfolio'), 3);
  85  
  86          exit;
  87      } else {
  88          echo $OUTPUT->heading(get_string('configplugin', 'portfolio'));
  89          echo $OUTPUT->box_start();
  90          $mform->display();
  91          echo $OUTPUT->box_end();
  92          $display = false;
  93      }
  94  
  95  } else if (!empty($hide)) {
  96      $instance = portfolio_instance($hide);
  97      $instance->set_user_config(array('visible' => !$instance->get_user_config('visible', $USER->id)), $USER->id);
  98      core_plugin_manager::reset_caches();
  99  }
 100  
 101  if ($display) {
 102      echo $OUTPUT->heading($configstr);
 103      echo $OUTPUT->box_start();
 104  
 105      echo html_writer::tag('p', $introstr);
 106  
 107      if (!$instances = portfolio_instances(true, false)) {
 108          print_error('noinstances', 'portfolio', $CFG->wwwroot . '/user/view.php');
 109      }
 110  
 111      $table = new html_table();
 112      $table->head = array($namestr, $pluginstr, $showhide);
 113      $table->data = array();
 114  
 115      foreach ($instances as $i) {
 116          // Contents of the actions (Show / hide) column.
 117          $actions = '';
 118  
 119          // Configure icon.
 120          if ($i->has_user_config()) {
 121              $configurl = new moodle_url($baseurl);
 122              $configurl->param('config', $i->get('id'));
 123              $actions .= html_writer::link($configurl, $OUTPUT->pix_icon('t/edit', get_string('configure', 'portfolio')));
 124          }
 125  
 126          // Hide/show icon.
 127          $visible = $i->get_user_config('visible', $USER->id);
 128          $visibilityaction = $visible ? 'hide' : 'show';
 129          $showhideurl = new moodle_url($baseurl);
 130          $showhideurl->param('hide', $i->get('id'));
 131          $actions .= html_writer::link($showhideurl, $OUTPUT->pix_icon('t/' . $visibilityaction, get_string($visibilityaction)));
 132  
 133          $table->data[] = array($i->get('name'), $i->get('plugin'), $actions);
 134      }
 135  
 136      echo html_writer::table($table);
 137      echo $OUTPUT->box_end();
 138  }
 139  echo $OUTPUT->footer();