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  namespace mod_lti\external;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  
  23  require_once($CFG->dirroot . '/mod/lti/locallib.php');
  24  
  25  /**
  26   * External function for fetching the count of all tool types and proxies.
  27   *
  28   * @package    mod_lti
  29   * @author     Andrew Madden <andrewmadden@catalyst-au.net>
  30   * @copyright  2021 Catalyst IT
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class get_tool_types_and_proxies_count extends \external_api {
  34  
  35      /**
  36       * Get parameter definition for get_tool_types_and_proxies_count().
  37       *
  38       * @return \external_function_parameters
  39       */
  40      public static function execute_parameters(): \external_function_parameters {
  41          return new \external_function_parameters(
  42              [
  43                  'toolproxyid' => new \external_value(PARAM_INT, 'Tool proxy id', VALUE_DEFAULT, 0),
  44                  'orphanedonly' => new \external_value(PARAM_BOOL, 'Orphaned tool types only', VALUE_DEFAULT, 0),
  45              ]
  46          );
  47      }
  48  
  49      /**
  50       * Get count of every tool type and tool proxy.
  51       *
  52       * @param int $toolproxyid The tool proxy id
  53       * @param bool $orphanedonly Whether to get orphaned proxies only.
  54       * @return array
  55       */
  56      public static function execute($toolproxyid, $orphanedonly): array {
  57          $params = self::validate_parameters(self::execute_parameters(),
  58              [
  59                  'toolproxyid' => $toolproxyid,
  60                  'orphanedonly' => $orphanedonly,
  61              ]);
  62          $toolproxyid = $params['toolproxyid'];
  63          $orphanedonly = $params['orphanedonly'];
  64  
  65          $context = \context_system::instance();
  66          self::validate_context($context);
  67          require_capability('moodle/site:config', $context);
  68  
  69          return [
  70              'count' => lti_get_lti_types_and_proxies_count($orphanedonly, $toolproxyid),
  71          ];
  72      }
  73  
  74      /**
  75       * Get return definition for get_tool_types_and_proxies_count.
  76       *
  77       * @return \external_single_structure
  78       */
  79      public static function execute_returns(): \external_single_structure {
  80          return new \external_single_structure([
  81              'count' => new \external_value(PARAM_INT, 'Total number of tool types and proxies', VALUE_REQUIRED),
  82          ]);
  83      }
  84  }