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 \stdClass $item the item to add.
35 * @return \stdClass the item which was added.
37 public function add(\stdClass $item) : \stdClass;
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 \stdClass the item.
53 public function find(int $id) : \stdClass;
56 * Find all items in this repository.
58 * @return array list of all items in this repository.
60 public function find_all() : array;
63 * Find all items with attributes matching certain values.
65 * @param array $criteria the array of attribute/value pairs.
66 * @return array the list of items matching the criteria.
68 public function find_by(array $criteria) : array;
71 * Check whether an item exists in this repository, based on its id.
73 * @param int $id the id to search for.
74 * @return bool true if the item could be found, false otherwise.
76 public function exists(int $id) : bool;
79 * Return the total number of items in this repository.
81 * @return int the total number of items.
83 public function count() : int;
86 * Update an item within this repository.
88 * @param \stdClass $item the item to update.
89 * @return \stdClass the updated item.
91 public function update(\stdClass $item) : \stdClass;
94 * Delete an item by id.
96 * @param int $id the id of the item to delete.
99 public function delete(int $id);