MDL-63658 core_favourites: consolidate interfaces and rename
Let's worry about reuse of the crud code later, when that requirement arises, so moved that into the ifavourite_repository interface, and then renamed it favourite_repository_interface.
This commit is contained in:
@@ -33,7 +33,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2018 Jake Dallimore <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class favourite_repository implements ifavourite_repository {
|
||||
class favourite_repository implements favourite_repository_interface {
|
||||
|
||||
/**
|
||||
* @var string the name of the table which favourites are stored in.
|
||||
|
||||
+15
-3
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Contains the crud_repository interface.
|
||||
* Contains the favourite_repository interface.
|
||||
*
|
||||
* @package core_favourites
|
||||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
@@ -26,9 +26,9 @@ use \core_favourites\local\entity\favourite;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The crud_repository interface, defining the basic CRUD operations for any repository types within core_favourites.
|
||||
* The favourite_repository interface, defining the basic CRUD operations for favourite type items within core_favourites.
|
||||
*/
|
||||
interface crud_repository {
|
||||
interface favourite_repository_interface {
|
||||
/**
|
||||
* Add one item to this repository.
|
||||
*
|
||||
@@ -102,4 +102,16 @@ interface crud_repository {
|
||||
* @return void
|
||||
*/
|
||||
public function delete(int $id);
|
||||
|
||||
/**
|
||||
* Find a single favourite, based on it's unique identifiers.
|
||||
*
|
||||
* @param int $userid the id of the user to which the favourite belongs.
|
||||
* @param string $component the frankenstyle component name.
|
||||
* @param string $itemtype the type of the favourited item.
|
||||
* @param int $itemid the id of the item which was favourited (not the favourite's id).
|
||||
* @param int $contextid the contextid of the item which was favourited.
|
||||
* @return favourite the favourite.
|
||||
*/
|
||||
public function find_favourite(int $userid, string $component, string $itemtype, int $itemid, int $contextid) : favourite;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
/**
|
||||
* Contains the favourite_repository interface.
|
||||
*
|
||||
* @package core_favourites
|
||||
* @copyright 2018 Jake Dallimore <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_favourites\local\repository;
|
||||
use \core_favourites\local\entity\favourite;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The favourite_repository interface, defining additional operations useful to favourite type repositories.
|
||||
*
|
||||
* @copyright 2018 Jake Dallimore <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
interface ifavourite_repository extends crud_repository {
|
||||
/**
|
||||
* Find a single favourite, based on it's unique identifiers.
|
||||
*
|
||||
* @param int $userid the id of the user to which the favourite belongs.
|
||||
* @param string $component the frankenstyle component name.
|
||||
* @param string $itemtype the type of the favourited item.
|
||||
* @param int $itemid the id of the item which was favourited (not the favourite's id).
|
||||
* @param int $contextid the contextid of the item which was favourited.
|
||||
* @return favourite the favourite.
|
||||
*/
|
||||
public function find_favourite(int $userid, string $component, string $itemtype, int $itemid, int $contextid) : favourite;
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
namespace core_favourites\local\service;
|
||||
use \core_favourites\local\entity\favourite;
|
||||
use \core_favourites\local\repository\favourite_repository_interface;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -32,14 +33,14 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* This class is responsible for exposing key operations (add, remove, find) and enforces any business logic necessary to validate
|
||||
* authorization/data integrity for these operations.
|
||||
*
|
||||
* All object persistence is delegated to the ifavourite_repository.
|
||||
* All object persistence is delegated to the favourite_repository_interface object.
|
||||
*
|
||||
* @copyright 2018 Jake Dallimore <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class user_favourite_service {
|
||||
|
||||
/** @var ifavourite_repository $repo the user favourites repository object. */
|
||||
/** @var favourite_repository_interface $repo the favourite repository object. */
|
||||
protected $repo;
|
||||
|
||||
/** @var int $userid the id of the user to which this favourites service is scoped. */
|
||||
@@ -49,9 +50,9 @@ class user_favourite_service {
|
||||
* The user_favourite_service constructor.
|
||||
*
|
||||
* @param \context_user $usercontext The context of the user to which this service operations are scoped.
|
||||
* @param \core_favourites\local\repository\ifavourite_repository $repository a user favourites repository.
|
||||
* @param \core_favourites\local\repository\favourite_repository_interface $repository a favourites repository.
|
||||
*/
|
||||
public function __construct(\context_user $usercontext, \core_favourites\local\repository\ifavourite_repository $repository) {
|
||||
public function __construct(\context_user $usercontext, favourite_repository_interface $repository) {
|
||||
$this->repo = $repository;
|
||||
$this->userid = $usercontext->instanceid;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class user_favourite_service_testcase extends advanced_testcase {
|
||||
*/
|
||||
protected function get_mock_repository(array $mockstore) {
|
||||
// This mock will just store data in an array.
|
||||
$mockrepo = $this->getMockBuilder(\core_favourites\local\repository\ifavourite_repository::class)
|
||||
$mockrepo = $this->getMockBuilder(\core_favourites\local\repository\favourite_repository_interface::class)
|
||||
->setMethods([])
|
||||
->getMock();
|
||||
$mockrepo->expects($this->any())
|
||||
|
||||
Reference in New Issue
Block a user