mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-63058 core_favourites: add existence checks to the service layer
This allows someone using the user_favourite_service to check whether an item is already marked as a favourite.
This commit is contained in:
parent
cc486e6125
commit
b81722e22f
2 changed files with 68 additions and 0 deletions
|
@ -135,4 +135,25 @@ class user_favourite_service {
|
|||
|
||||
$this->repo->delete($favourite->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an item has been marked as a favourite in the respective area.
|
||||
*
|
||||
* @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 \context $context the context of the item which was favourited.
|
||||
* @return bool true if the item is favourited, false otherwise.
|
||||
*/
|
||||
public function favourite_exists(string $component, string $itemtype, int $itemid, \context $context) : bool {
|
||||
return $this->repo->exists_by(
|
||||
[
|
||||
'userid' => $this->userid,
|
||||
'component' => $component,
|
||||
'itemtype' => $itemtype,
|
||||
'itemid' => $itemid,
|
||||
'contextid' => $context->id
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue