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   * This is the external method for deleting a content.
  19   *
  20   * @package    mod_glossary
  21   * @since      Moodle 3.10
  22   * @copyright  2020 Juan Leyva <juan@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  namespace mod_glossary\external;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  global $CFG;
  31  require_once($CFG->libdir . '/externallib.php');
  32  require_once($CFG->dirroot . '/mod/glossary/lib.php');
  33  
  34  use external_api;
  35  use external_function_parameters;
  36  use external_multiple_structure;
  37  use external_single_structure;
  38  use external_value;
  39  use external_warnings;
  40  
  41  /**
  42   * This is the external method for deleting a content.
  43   *
  44   * @copyright  2020 Juan Leyva <juan@moodle.com>
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   */
  47  class delete_entry extends external_api {
  48      /**
  49       * Parameters.
  50       *
  51       * @return external_function_parameters
  52       */
  53      public static function execute_parameters(): external_function_parameters {
  54          return new external_function_parameters([
  55              'entryid' => new external_value(PARAM_INT, 'Glossary entry id to delete'),
  56          ]);
  57      }
  58  
  59      /**
  60       * Delete the indicated entry from the glossary.
  61       *
  62       * @param  int $entryid The entry to delete
  63       * @return array with result and warnings
  64       * @throws moodle_exception
  65       */
  66      public static function execute(int $entryid): array {
  67          global $DB;
  68  
  69          $params = self::validate_parameters(self::execute_parameters(), compact('entryid'));
  70          $id = $params['entryid'];
  71  
  72          // Get and validate the glossary.
  73          $entry = $DB->get_record('glossary_entries', ['id' => $id], '*', MUST_EXIST);
  74          list($glossary, $context, $course, $cm) = \mod_glossary_external::validate_glossary($entry->glossaryid);
  75  
  76          // Check and delete.
  77          mod_glossary_can_delete_entry($entry, $glossary, $context, false);
  78          mod_glossary_delete_entry($entry, $glossary, $cm, $context, $course);
  79  
  80          return [
  81              'result' => true,
  82              'warnings' => [],
  83          ];
  84      }
  85  
  86      /**
  87       * Return.
  88       *
  89       * @return external_single_structure
  90       */
  91      public static function execute_returns(): external_single_structure {
  92          return new external_single_structure([
  93              'result' => new external_value(PARAM_BOOL, 'The processing result'),
  94              'warnings' => new external_warnings()
  95          ]);
  96      }
  97  }