Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * The main interface for recycle bin methods.
  19   *
  20   * @package    tool_recyclebin
  21   * @copyright  2015 University of Kent
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_recyclebin;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Represents a recyclebin.
  31   *
  32   * @package    tool_recyclebin
  33   * @copyright  2015 University of Kent
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  abstract class base_bin {
  37  
  38      /**
  39       * Is this recyclebin enabled?
  40       */
  41      public static function is_enabled() {
  42          return false;
  43      }
  44  
  45      /**
  46       * Returns an item from the recycle bin.
  47       *
  48       * @param int $itemid Item ID to retrieve.
  49       */
  50      public abstract function get_item($itemid);
  51  
  52      /**
  53       * Returns a list of items in the recycle bin.
  54       */
  55      public abstract function get_items();
  56  
  57      /**
  58       * Store an item in this recycle bin.
  59       *
  60       * @param \stdClass $item Item to store.
  61       */
  62      public abstract function store_item($item);
  63  
  64      /**
  65       * Restore an item from the recycle bin.
  66       *
  67       * @param \stdClass $item The item database record
  68       */
  69      public abstract function restore_item($item);
  70  
  71      /**
  72       * Delete an item from the recycle bin.
  73       *
  74       * @param \stdClass $item The item database record
  75       */
  76      public abstract function delete_item($item);
  77  
  78      /**
  79       * Empty the recycle bin.
  80       */
  81      public function delete_all_items() {
  82          // Cleanup all items.
  83          $items = $this->get_items();
  84          foreach ($items as $item) {
  85              if ($this->can_delete()) {
  86                  $this->delete_item($item);
  87              }
  88          }
  89      }
  90  
  91      /**
  92       * Can we view items in this recycle bin?
  93       */
  94      public abstract function can_view();
  95  
  96      /**
  97       * Can we restore items in this recycle bin?
  98       */
  99      public abstract function can_restore();
 100  
 101      /**
 102       * Can we delete this?
 103       */
 104      public abstract function can_delete();
 105  }