RatingsServiceInterface
extends
DbServiceInterface
in
Database service interface for Ratings.
Tags
Table of Contents
- addOrUpdateRating() : int
- Add or update user's rating for a resource.
- deleteByUser() : void
- Deletes all ratings by a user.
- getCountsForRecord() : array<string|int, mixed>
- Get rating breakdown for the specified record.
- getRecordRatings() : array<string|int, mixed>
- Get average rating and rating count associated with the specified record.
- getStatistics() : array<string|int, mixed>
- Get statistics on use of Ratings.
- persistEntity() : void
- Persist an entity.
Methods
addOrUpdateRating()
Add or update user's rating for a resource.
public
addOrUpdateRating(ResourceEntityInterface|int $resourceOrId, UserEntityInterface|int $userOrId, int|null $rating) : int
Parameters
- $resourceOrId : ResourceEntityInterface|int
-
Resource to add or update rating.
- $userOrId : UserEntityInterface|int
-
User
- $rating : int|null
-
Rating (null to delete)
Tags
Return values
int —ID of rating added, deleted or updated
deleteByUser()
Deletes all ratings by a user.
public
deleteByUser(UserEntityInterface|int $userOrId) : void
Parameters
- $userOrId : UserEntityInterface|int
-
User object or identifier
Return values
void —getCountsForRecord()
Get rating breakdown for the specified record.
public
getCountsForRecord(string $id, string $source, array<string|int, mixed> $groups) : array<string|int, mixed>
Parameters
- $id : string
-
Record ID to look up
- $source : string
-
Source of record to look up
- $groups : array<string|int, mixed>
-
Group definition (key => [min, max])
Return values
array<string|int, mixed> —Array with keys count and rating (between 0 and 100) as well as an groups array with ratings from lowest to highest
getRecordRatings()
Get average rating and rating count associated with the specified record.
public
getRecordRatings(string $id, string $source, int|null $userId) : array<string|int, mixed>
Parameters
- $id : string
-
Record ID to look up
- $source : string
-
Source of record to look up
- $userId : int|null
-
User ID, or null for all users
Return values
array<string|int, mixed> —Array with keys count and rating (between 0 and 100)
getStatistics()
Get statistics on use of Ratings.
public
getStatistics() : array<string|int, mixed>
Return values
array<string|int, mixed> —persistEntity()
Persist an entity.
public
persistEntity(EntityInterface $entity) : void
Parameters
- $entity : EntityInterface
-
Entity to persist.