Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 39 and 402]

Contains the content_item_service class.

Copyright: 2020 Jake Dallimore <jrhdallimore@gmail.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 386 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: content_item_service  - X-Ref

The content_item_service class, providing the api for interacting with content items.

__construct(content_item_readonly_repository_interface $repository)   X-Ref
The content_item_service constructor.

param: content_item_readonly_repository_interface $repository a content item repository.

get_favourite_content_items_for_user(\stdClass $user)   X-Ref
Returns an array of objects representing favourited content items.

Each object contains the following properties:
itemtype: a string containing the 'itemtype' key used by the favourites subsystem.
ids[]: an array of ids, representing the content items within a component.

Since two components can return (via their hook implementation) the same id, the itemtype is used for uniqueness.

param: \stdClass $user
return: array

get_recommendations()   X-Ref
Returns an array of objects representing recommended content items.

Each object contains the following properties:
itemtype: a string containing the 'itemtype' key used by the favourites subsystem.
ids[]: an array of ids, representing the content items within a component.

Since two components can return (via their hook implementation) the same id, the itemtype is used for uniqueness.

return: array

get_content_favourites(string $prefix, \context_user $usercontext)   X-Ref
Gets content favourites from the favourites system depending on the area.

param: string        $prefix      Prefix for the item type.
param: \context_user $usercontext User context for the favourite
return: array An array of favourite objects.

get_all_content_items(\stdClass $user)   X-Ref
Get all content items which may be added to courses, irrespective of course caps, for site admin views, etc.

param: \stdClass $user the user object.
return: array the array of exported content items.

get_content_items_by_name_pattern(\stdClass $user, string $pattern)   X-Ref
Get content items which name matches a certain pattern and may be added to courses,
irrespective of course caps, for site admin views, etc.

param: \stdClass $user The user object.
param: string $pattern The search pattern.
return: array The array of exported content items.

export_content_items(\stdClass $user, $contentitems)   X-Ref
Export content items.

param: \stdClass $user The user object.
param: array $contentitems The content items array.
return: array The array of exported content items.

get_content_items_for_user_in_course(\stdClass $user, \stdClass $course, array $linkparams = [])   X-Ref
Return a representation of the available content items, for a user in a course.

param: \stdClass $user the user to check access for.
param: \stdClass $course the course to scope the content items to.
param: array $linkparams the desired section to return to.
return: \stdClass[] the content items, scoped to a course.

add_to_user_favourites(\stdClass $user, string $componentname, int $contentitemid)   X-Ref
Add a content item to a user's favourites.

param: \stdClass $user the user whose favourite this is.
param: string $componentname the name of the component from which the content item originates.
param: int $contentitemid the id of the content item.
return: \stdClass the exported content item.

remove_from_user_favourites(\stdClass $user, string $componentname, int $contentitemid)   X-Ref
Remove the content item from a user's favourites.

param: \stdClass $user the user whose favourite this is.
param: string $componentname the name of the component from which the content item originates.
param: int $contentitemid the id of the content item.
return: \stdClass the exported content item.

toggle_recommendation(string $itemtype, int $itemid)   X-Ref
Toggle an activity to being recommended or not.

param: string $itemtype The component such as mod_assign, or assignsubmission_file
param: int    $itemid   The id related to this component item.
return: bool True on creating a favourite, false on deleting it.