Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

Contains the favourite_repository class, responsible for CRUD operations for favourites.

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

Defines 1 class

favourite_repository:: (16 methods):
  get_favourite_from_record()
  get_list_of_favourites_from_records()
  validate()
  add()
  add_all()
  find()
  find_all()
  find_by()
  find_favourite()
  exists()
  exists_by()
  update()
  delete()
  delete_by()
  count()
  count_by()


Class: favourite_repository  - X-Ref

Class favourite_repository.

This class handles persistence of favourites. Favourites from all areas are supported by this repository.

get_favourite_from_record(\stdClass $record)   X-Ref
Get a favourite object, based on a full record.

return: favourite the favourite record.
param: \stdClass $record the record we wish to hydrate.

get_list_of_favourites_from_records(array $records)   X-Ref
Get a list of favourite objects, based on a list of records.

return: array the list of favourites.
param: array $records the record we wish to hydrate.

validate(favourite $favourite)   X-Ref
Basic validation, confirming we have the minimum field set needed to save a record to the store.

param: favourite $favourite the favourite record to validate.

add(favourite $favourite)   X-Ref
Add a favourite to the repository.

return: favourite the favourite which has been stored.
param: favourite $favourite the favourite to add.

add_all(array $items)   X-Ref
Add a collection of favourites to the repository.

return: array the list of favourites which have been stored.
param: array $items the list of favourites to add.

find(int $id)   X-Ref
Find a favourite by id.

return: favourite the favourite.
param: int $id the id of the favourite.

find_all(int $limitfrom = 0, int $limitnum = 0)   X-Ref
Return all items in this repository, as an array, indexed by id.

return: array the list of all favourites stored within this repository.
param: int $limitfrom optional pagination control for returning a subset of records, starting at this point.
param: int $limitnum optional pagination control for returning a subset comprising this many records.

find_by(array $criteria, int $limitfrom = 0, int $limitnum = 0)   X-Ref
Return all items matching the supplied criteria (a [key => value,..] list).

return: array the list of favourites matching the criteria.
param: array $criteria the list of key/value(s) criteria pairs.
param: int $limitfrom optional pagination control for returning a subset of records, starting at this point.
param: int $limitnum optional pagination control for returning a subset comprising this many records.

find_favourite(int $userid, string $component, string $itemtype, int $itemid, int $contextid)   X-Ref
Find a specific favourite, based on the properties known to identify it.

Used if we don't know its id.

return: favourite the favourite.
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.

exists(int $id)   X-Ref
Check whether a favourite exists in this repository, based on its id.

return: bool true if the favourite exists, false otherwise.
param: int $id the id to search for.

exists_by(array $criteria)   X-Ref
Check whether an item exists in this repository, based on the specified criteria.

return: bool true if the favourite exists, false otherwise.
param: array $criteria the list of key/value criteria pairs.

update(favourite $favourite)   X-Ref
Update a favourite.

return: favourite the updated favourite.
param: favourite $favourite the favourite to update.

delete(int $id)   X-Ref
Delete a favourite, by id.

param: int $id the id of the favourite to delete.

delete_by(array $criteria)   X-Ref
Delete all favourites matching the specified criteria.

param: array $criteria the list of key/value criteria pairs.

count()   X-Ref
Return the total number of favourites in this repository.

return: int the total number of items.

count_by(array $criteria)   X-Ref
Return the number of user favourites matching the specified criteria.

return: int the number of favourites matching the criteria.
param: array $criteria the list of key/value criteria pairs.