2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * Contains the crud_repository interface.
19 * @package core_favourites
20 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 namespace core_favourites\local\repository;
25 defined('MOODLE_INTERNAL') || die();
28 * The crud_repository interface, defining the basic CRUD operations for any repository types within core_favourites.
30 interface crud_repository {
32 * Add one item to this repository.
34 * @param object $item the item to add.
35 * @return object the item which was added.
37 public function add($item);
40 * Add all the items in the list to this repository.
42 * @param array $items the list of items to add.
43 * @return array the list of items added to this repository.
45 public function add_all(array $items) : array;
48 * Find an item in this repository based on its id.
50 * @param int $id the id of the item.
51 * @return object the item.
53 public function find(int $id);
56 * Find all items in this repository.
58 * @param int $limitfrom optional pagination control for returning a subset of records, starting at this point.
59 * @param int $limitnum optional pagination control for returning a subset comprising this many records.
60 * @return array list of all items in this repository.
62 public function find_all(int $limitfrom = 0, int $limitnum = 0) : array;
65 * Find all items with attributes matching certain values.
67 * @param array $criteria the array of attribute/value pairs.
68 * @param int $limitfrom optional pagination control for returning a subset of records, starting at this point.
69 * @param int $limitnum optional pagination control for returning a subset comprising this many records.
70 * @return array the list of items matching the criteria.
72 public function find_by(array $criteria, int $limitfrom = 0, int $limitnum = 0) : array;
75 * Check whether an item exists in this repository, based on its id.
77 * @param int $id the id to search for.
78 * @return bool true if the item could be found, false otherwise.
80 public function exists(int $id) : bool;
83 * Return the total number of items in this repository.
85 * @return int the total number of items.
87 public function count() : int;
90 * Update an item within this repository.
92 * @param object $item the item to update.
93 * @return object the updated item.
95 public function update($item);
98 * Delete an item by id.
100 * @param int $id the id of the item to delete.
103 public function delete(int $id);