MDL-63658 core_favourites: add a user favourites repository
[moodle.git] / favourites / classes / local / crud_repository.php
CommitLineData
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 */
23namespace core_favourites\local;
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * The crud_repository interface, defining the basic CRUD operations for any repository types within core_favourites.
29 */
30interface crud_repository {
31 /**
32 * Add one item to this repository.
33 *
34 * @param \stdClass $item the item to add.
35 * @return \stdClass the item which was added.
36 */
37 public function add(\stdClass $item) : \stdClass;
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.
51 * @return \stdClass the item.
52 */
53 public function find(int $id) : \stdClass;
54
55 /**
56 * Find all items in this repository.
57 *
58 * @return array list of all items in this repository.
59 */
60 public function find_all() : array;
61
62 /**
63 * Find all items with attributes matching certain values.
64 *
65 * @param array $criteria the array of attribute/value pairs.
66 * @return array the list of items matching the criteria.
67 */
68 public function find_by(array $criteria) : array;
69
70 /**
71 * Check whether an item exists in this repository, based on its id.
72 *
73 * @param int $id the id to search for.
74 * @return bool true if the item could be found, false otherwise.
75 */
76 public function exists(int $id) : bool;
77
78 /**
79 * Return the total number of items in this repository.
80 *
81 * @return int the total number of items.
82 */
83 public function count() : int;
84
85 /**
86 * Update an item within this repository.
87 *
88 * @param \stdClass $item the item to update.
89 * @return \stdClass the updated item.
90 */
91 public function update(\stdClass $item) : \stdClass;
92
93 /**
94 * Delete an item by id.
95 *
96 * @param int $id the id of the item to delete.
97 * @return void
98 */
99 public function delete(int $id);
100}