RatingsService
in package
Ratings service
Tags
Table of Contents
- $dbService : RatingsServiceInterface
- $ratingCache : array<string|int, mixed>
- Cache for rating data
- $resourcePopulator : ResourcePopulator
- __construct() : mixed
- Constructor
- getRatingBreakdown() : array<string|int, mixed>
- Get rating breakdown for the provided record.
- getRatingData() : array<string|int, mixed>
- Get rating information for the provided record.
- saveRating() : void
- Add or update user's rating for the record.
Properties
$dbService
protected
RatingsServiceInterface
$dbService
$ratingCache
Cache for rating data
protected
array<string|int, mixed>
$ratingCache
= []
$resourcePopulator
protected
ResourcePopulator
$resourcePopulator
Methods
__construct()
Constructor
public
__construct(RatingsServiceInterface $dbService, ResourcePopulator $resourcePopulator) : mixed
Parameters
- $dbService : RatingsServiceInterface
-
Ratings database service
- $resourcePopulator : ResourcePopulator
-
Resource populator
Return values
mixed —getRatingBreakdown()
Get rating breakdown for the provided record.
public
getRatingBreakdown(AbstractBase $driver, array<string|int, mixed> $groups) : array<string|int, mixed>
Returns an array with the following keys:
rating - average rating (0-100) count - count of ratings groups - grouped counts
Parameters
- $driver : AbstractBase
-
Record to look up
- $groups : array<string|int, mixed>
-
Group definition (key => [min, max])
Return values
array<string|int, mixed> —getRatingData()
Get rating information for the provided record.
public
getRatingData(AbstractBase $driver[, int|null $userId = null ]) : array<string|int, mixed>
Returns an array with the following keys:
rating - average rating (0-100) count - count of ratings
Parameters
- $driver : AbstractBase
-
Record to look up
- $userId : int|null = null
-
User ID, or null for all users
Return values
array<string|int, mixed> —saveRating()
Add or update user's rating for the record.
public
saveRating(AbstractBase $driver, int $userId, int|null $rating) : void
Parameters
- $driver : AbstractBase
-
Record associated with rating
- $userId : int
-
ID of the user posting the rating
- $rating : int|null
-
The user-provided rating, or null to clear any existing rating