mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-63658 core_favourites: let service object use get_component_names
This was using a helper, but now we have the function in core to achieve the same thing, so use this instead.
This commit is contained in:
parent
3a1ece149f
commit
8d9cd27b02
@ -57,17 +57,6 @@ class user_favourite_service {
|
||||
$this->userid = $usercontext->instanceid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper, returning a flat list of component names.
|
||||
*
|
||||
* @return array the array of component names.
|
||||
*/
|
||||
protected function get_component_list() {
|
||||
return array_keys(array_reduce(\core_component::get_component_list(), function($carry, $item) {
|
||||
return array_merge($carry, $item);
|
||||
}, []));
|
||||
}
|
||||
|
||||
/**
|
||||
* Favourite an item defined by itemid/context, in the area defined by component/itemtype.
|
||||
*
|
||||
@ -84,7 +73,7 @@ class user_favourite_service {
|
||||
// Access: Any component can ask to favourite something, we can't verify access to that 'something' here though.
|
||||
|
||||
// Validate the component name.
|
||||
if (!in_array($component, $this->get_component_list())) {
|
||||
if (!in_array($component, \core_component::get_component_names())) {
|
||||
throw new \moodle_exception("Invalid component name '$component'");
|
||||
}
|
||||
|
||||
@ -107,7 +96,7 @@ class user_favourite_service {
|
||||
* @throws \moodle_exception if the component name is invalid, or if the repository encounters any errors.
|
||||
*/
|
||||
public function find_favourites_by_type(string $component, string $itemtype, int $limitfrom = 0, int $limitnum = 0) : array {
|
||||
if (!in_array($component, $this->get_component_list())) {
|
||||
if (!in_array($component, \core_component::get_component_names())) {
|
||||
throw new \moodle_exception("Invalid component name '$component'");
|
||||
}
|
||||
return $this->repo->find_by(
|
||||
@ -133,7 +122,7 @@ class user_favourite_service {
|
||||
* @throws \moodle_exception if the user does not control the favourite, or it doesn't exist.
|
||||
*/
|
||||
public function delete_favourite(string $component, string $itemtype, int $itemid, \context $context) {
|
||||
if (!in_array($component, $this->get_component_list())) {
|
||||
if (!in_array($component, \core_component::get_component_names())) {
|
||||
throw new \moodle_exception("Invalid component name '$component'");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user