Commit | Line | Data |
---|---|---|
d4e98ee5 JD |
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 | * Contains the crud_repository interface. | |
18 | * | |
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 | |
22 | */ | |
4a02aae5 | 23 | namespace core_favourites\local\repository; |
d4e98ee5 JD |
24 | |
25 | defined('MOODLE_INTERNAL') || die(); | |
26 | ||
27 | /** | |
28 | * The crud_repository interface, defining the basic CRUD operations for any repository types within core_favourites. | |
29 | */ | |
30 | interface crud_repository { | |
31 | /** | |
32 | * Add one item to this repository. | |
33 | * | |
8ffbe9c1 JD |
34 | * @param object $item the item to add. |
35 | * @return object the item which was added. | |
d4e98ee5 | 36 | */ |
8ffbe9c1 | 37 | public function add($item); |
d4e98ee5 JD |
38 | |
39 | /** | |
40 | * Add all the items in the list to this repository. | |
41 | * | |
42 | * @param array $items the list of items to add. | |
43 | * @return array the list of items added to this repository. | |
44 | */ | |
45 | public function add_all(array $items) : array; | |
46 | ||
47 | /** | |
48 | * Find an item in this repository based on its id. | |
49 | * | |
50 | * @param int $id the id of the item. | |
8ffbe9c1 | 51 | * @return object the item. |
d4e98ee5 | 52 | */ |
8ffbe9c1 | 53 | public function find(int $id); |
d4e98ee5 JD |
54 | |
55 | /** | |
56 | * Find all items in this repository. | |
57 | * | |
8ffbe9c1 JD |
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. | |
d4e98ee5 JD |
60 | * @return array list of all items in this repository. |
61 | */ | |
8ffbe9c1 | 62 | public function find_all(int $limitfrom = 0, int $limitnum = 0) : array; |
d4e98ee5 JD |
63 | |
64 | /** | |
65 | * Find all items with attributes matching certain values. | |
66 | * | |
67 | * @param array $criteria the array of attribute/value pairs. | |
8ffbe9c1 JD |
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. | |
d4e98ee5 JD |
70 | * @return array the list of items matching the criteria. |
71 | */ | |
8ffbe9c1 | 72 | public function find_by(array $criteria, int $limitfrom = 0, int $limitnum = 0) : array; |
d4e98ee5 JD |
73 | |
74 | /** | |
75 | * Check whether an item exists in this repository, based on its id. | |
76 | * | |
77 | * @param int $id the id to search for. | |
78 | * @return bool true if the item could be found, false otherwise. | |
79 | */ | |
80 | public function exists(int $id) : bool; | |
81 | ||
82 | /** | |
83 | * Return the total number of items in this repository. | |
84 | * | |
85 | * @return int the total number of items. | |
86 | */ | |
87 | public function count() : int; | |
88 | ||
89 | /** | |
90 | * Update an item within this repository. | |
91 | * | |
8ffbe9c1 JD |
92 | * @param object $item the item to update. |
93 | * @return object the updated item. | |
d4e98ee5 | 94 | */ |
8ffbe9c1 | 95 | public function update($item); |
d4e98ee5 JD |
96 | |
97 | /** | |
98 | * Delete an item by id. | |
99 | * | |
100 | * @param int $id the id of the item to delete. | |
101 | * @return void | |
102 | */ | |
103 | public function delete(int $id); | |
104 | } |