Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
core_favourites\local\repository\favourite_repository Class Reference

Class favourite_repository. More...

Inheritance diagram for core_favourites\local\repository\favourite_repository:
core_favourites\local\repository\favourite_repository_interface

Public Member Functions

 add (favourite $favourite)
 Add a favourite to the repository. More...
 
 add_all (array $items)
 Add a collection of favourites to the repository. More...
 
 count ()
 Return the total number of favourites in this repository. More...
 
 count_by (array $criteria)
 Return the number of user favourites matching the specified criteria. More...
 
 delete (int $id)
 Delete a favourite, by id. More...
 
 delete_by (array $criteria)
 Delete all favourites matching the specified criteria. More...
 
 exists (int $id)
 Check whether a favourite exists in this repository, based on its id. More...
 
 exists_by (array $criteria)
 Check whether an item exists in this repository, based on the specified criteria. More...
 
 find (int $id)
 Find a favourite by id. More...
 
 find_all (int $limitfrom=0, int $limitnum=0)
 Return all items in this repository, as an array, indexed by id. More...
 
 find_by (array $criteria, int $limitfrom=0, int $limitnum=0)
 Return all items matching the supplied criteria (a [key => value,..] list). More...
 
 find_favourite (int $userid, string $component, string $itemtype, int $itemid, int $contextid)
 Find a specific favourite, based on the properties known to identify it. More...
 
 update (favourite $favourite)
 Update a favourite. More...
 

Protected Member Functions

 get_favourite_from_record (\stdClass $record)
 Get a favourite object, based on a full record. More...
 
 get_list_of_favourites_from_records (array $records)
 Get a list of favourite objects, based on a list of records. More...
 
 validate (favourite $favourite)
 Basic validation, confirming we have the minimum field set needed to save a record to the store. More...
 

Protected Attributes

string $favouritetable = 'favourite'
 the name of the table which favourites are stored in.
 

Detailed Description

Class favourite_repository.

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

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ add()

core_favourites\local\repository\favourite_repository::add ( favourite  $favourite)

Add a favourite to the repository.

Parameters
favourite$favouritethe favourite to add.
Return values
favouritethe favourite which has been stored.
Exceptions
dml_exceptionif any database errors are encountered.
moodle_exceptionif the favourite has missing or invalid properties.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ add_all()

core_favourites\local\repository\favourite_repository::add_all ( array  $items)

Add a collection of favourites to the repository.

Parameters
array$itemsthe list of favourites to add.
Return values
arraythe list of favourites which have been stored.
Exceptions
dml_exceptionif any database errors are encountered.
moodle_exceptionif any of the favourites have missing or invalid properties.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ count()

core_favourites\local\repository\favourite_repository::count ( )

Return the total number of favourites in this repository.

Return values
intthe total number of items.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ count_by()

core_favourites\local\repository\favourite_repository::count_by ( array  $criteria)

Return the number of user favourites matching the specified criteria.

Parameters
array$criteriathe list of key/value criteria pairs.
Return values
intthe number of favourites matching the criteria.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ delete()

core_favourites\local\repository\favourite_repository::delete ( int  $id)

Delete a favourite, by id.

Parameters
int$idthe id of the favourite to delete.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ delete_by()

core_favourites\local\repository\favourite_repository::delete_by ( array  $criteria)

Delete all favourites matching the specified criteria.

Parameters
array$criteriathe list of key/value criteria pairs.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ exists()

core_favourites\local\repository\favourite_repository::exists ( int  $id)

Check whether a favourite exists in this repository, based on its id.

Parameters
int$idthe id to search for.
Return values
booltrue if the favourite exists, false otherwise.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ exists_by()

core_favourites\local\repository\favourite_repository::exists_by ( array  $criteria)

Check whether an item exists in this repository, based on the specified criteria.

Parameters
array$criteriathe list of key/value criteria pairs.
Return values
booltrue if the favourite exists, false otherwise.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ find()

core_favourites\local\repository\favourite_repository::find ( int  $id)

Find a favourite by id.

Parameters
int$idthe id of the favourite.
Return values
favouritethe favourite.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ find_all()

core_favourites\local\repository\favourite_repository::find_all ( int  $limitfrom = 0,
int  $limitnum = 0 
)

Return all items in this repository, as an array, indexed by id.

Parameters
int$limitfromoptional pagination control for returning a subset of records, starting at this point.
int$limitnumoptional pagination control for returning a subset comprising this many records.
Return values
arraythe list of all favourites stored within this repository.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ find_by()

core_favourites\local\repository\favourite_repository::find_by ( array  $criteria,
int  $limitfrom = 0,
int  $limitnum = 0 
)

Return all items matching the supplied criteria (a [key => value,..] list).

Parameters
array$criteriathe list of key/value criteria pairs.
int$limitfromoptional pagination control for returning a subset of records, starting at this point.
int$limitnumoptional pagination control for returning a subset comprising this many records.
Return values
arraythe list of favourites matching the criteria.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ find_favourite()

core_favourites\local\repository\favourite_repository::find_favourite ( int  $userid,
string  $component,
string  $itemtype,
int  $itemid,
int  $contextid 
)

Find a specific favourite, based on the properties known to identify it.

Used if we don't know its id.

Parameters
int$useridthe id of the user to which the favourite belongs.
string$componentthe frankenstyle component name.
string$itemtypethe type of the favourited item.
int$itemidthe id of the item which was favourited (not the favourite's id).
int$contextidthe contextid of the item which was favourited.
Return values
favouritethe favourite.
Exceptions
dml_exceptionif any database errors are encountered or if the record could not be found.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ get_favourite_from_record()

core_favourites\local\repository\favourite_repository::get_favourite_from_record ( \stdClass  $record)
protected

Get a favourite object, based on a full record.

Parameters
stdClass$recordthe record we wish to hydrate.
Return values
favouritethe favourite record.

◆ get_list_of_favourites_from_records()

core_favourites\local\repository\favourite_repository::get_list_of_favourites_from_records ( array  $records)
protected

Get a list of favourite objects, based on a list of records.

Parameters
array$recordsthe record we wish to hydrate.
Return values
arraythe list of favourites.

◆ update()

core_favourites\local\repository\favourite_repository::update ( favourite  $favourite)

Update a favourite.

Parameters
favourite$favouritethe favourite to update.
Return values
favouritethe updated favourite.
Exceptions
dml_exceptionif any database errors are encountered.

Implements core_favourites\local\repository\favourite_repository_interface.

◆ validate()

core_favourites\local\repository\favourite_repository::validate ( favourite  $favourite)
protected

Basic validation, confirming we have the minimum field set needed to save a record to the store.

Parameters
favourite$favouritethe favourite record to validate.
Exceptions
moodle_exceptionif the supplied favourite has missing or unsupported fields.

The documentation for this class was generated from the following file: