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 401 and 402] [Versions 401 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   * Tag external functions utility class.
  19   *
  20   * @package    core_tag
  21   * @copyright  2019 Juan Leyva
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_tag\external;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once($CFG->libdir . '/externallib.php');
  30  
  31  use core_tag\external\tag_item_exporter;
  32  use core_tag_tag;
  33  
  34  /**
  35   * Tag external functions utility class.
  36   *
  37   * @package   core_tag
  38   * @copyright 2019 Juan Leyva
  39   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   * @since     Moodle 3.7
  41   */
  42  class util {
  43  
  44  
  45      /**
  46       * Get the array of core_tag_tag objects for external functions associated with an item (instances).
  47       *
  48       * @param string $component component responsible for tagging. For BC it can be empty but in this case the
  49       *               query will be slow because DB index will not be used.
  50       * @param string $itemtype type of the tagged item
  51       * @param int $itemid
  52       * @param int $standardonly wether to return only standard tags or any
  53       * @param int $tiuserid tag instance user id, only needed for tag areas with user tagging
  54       * @return array tags for external functions
  55       */
  56      public static function get_item_tags($component, $itemtype, $itemid, $standardonly = core_tag_tag::BOTH_STANDARD_AND_NOT,
  57              $tiuserid = 0) {
  58          global $PAGE;
  59  
  60          $output = $PAGE->get_renderer('core');
  61  
  62          $tagitems = core_tag_tag::get_item_tags($component, $itemtype, $itemid, $standardonly, $tiuserid);
  63          $exportedtags = [];
  64          foreach ($tagitems as $tagitem) {
  65              $exporter = new tag_item_exporter($tagitem->to_object());
  66              $exportedtags[] = (array) $exporter->export($output);
  67          }
  68          return $exportedtags;
  69      }
  70  }