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.
/tag/ -> user.php (source)

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

   1  <?php
   2  
   3  require_once('../config.php');
   4  require_once ('lib.php');
   5  
   6  $action = optional_param('action', '', PARAM_ALPHA);
   7  
   8  require_login();
   9  
  10  if (empty($CFG->usetags)) {
  11      throw new \moodle_exception('tagdisabled');
  12  }
  13  
  14  if (isguestuser()) {
  15      throw new \moodle_exception('noguest');
  16  }
  17  
  18  if (!confirm_sesskey()) {
  19      throw new \moodle_exception('sesskey');
  20  }
  21  
  22  $usercontext = context_user::instance($USER->id);
  23  
  24  switch ($action) {
  25      case 'addinterest':
  26          if (!core_tag_tag::is_enabled('core', 'user')) {
  27              throw new \moodle_exception('tagdisabled');
  28          }
  29          $tag = required_param('tag', PARAM_TAG);
  30          core_tag_tag::add_item_tag('core', 'user', $USER->id, $usercontext, $tag);
  31          $tc = core_tag_area::get_collection('core', 'user');
  32          redirect(core_tag_tag::make_url($tc, $tag));
  33          break;
  34  
  35      case 'removeinterest':
  36          if (!core_tag_tag::is_enabled('core', 'user')) {
  37              throw new \moodle_exception('tagdisabled');
  38          }
  39          $tag = required_param('tag', PARAM_TAG);
  40          core_tag_tag::remove_item_tag('core', 'user', $USER->id, $tag);
  41          $tc = core_tag_area::get_collection('core', 'user');
  42          redirect(core_tag_tag::make_url($tc, $tag));
  43          break;
  44  
  45      case 'flaginappropriate':
  46          require_capability('moodle/tag:flag', context_system::instance());
  47          $id = required_param('id', PARAM_INT);
  48          $tagobject = core_tag_tag::get($id, '*', MUST_EXIST);
  49          $tagobject->flag();
  50          redirect($tagobject->get_view_url(), get_string('responsiblewillbenotified', 'tag'));
  51          break;
  52  
  53      default:
  54          throw new \moodle_exception('unknowaction');
  55          break;
  56  }