CoolCMS API

InitializationTrait

Initialization and data loading of the rating component.

Requires in the host class: $this->ratingManager, $this->ratingThreadManager, $this->userManager, $this->threadId, $this->template.

Table of Contents

Methods

initializeRender()  : void
Public wrapper called by `FormTrait::handleSubmitSuccess()` before `redrawControl('rating')`.
computeCounts()  : array<int, int>
Returns the array [1..5 => count] from the given rating list.
initializeAggregate()  : void
Loads the denormalized aggregate (average and count) from the thread.
initializeForStyle()  : void
Loads template data according to the render style.
initializeMyVotes()  : void
Loads how this visitor voted on the displayed reviews, to highlight their choice and not offer it again.
initializeReviewFull()  : void
Loads aggregate, reviews and star distribution for `STYLE_REVIEW`.
initializeReviews()  : void
Loads approved ratings of the thread, paginated, plus their authors' avatars.
initializeReviewsDetailed()  : void
Summary plus review list with filter and sorting (`STYLE_REVIEWS_DETAILED`).
initializeSummary()  : void
Loads aggregate and star distribution for `STYLE_SUMMARY` (without the full review list).
initializeThumbs()  : void
Reads like/dislike counts from the denormalized thread columns (`count_5` is like, `count_1` is dislike), without querying the rating list, so it is fine in listings.
initializeUsers()  : void
Loads avatars of the users who rated.
resolveSort()  : string
Validated `$sort` value; an unknown one (e.g. from a hand-edited URL) falls back to `newest`.
userHasVoted()  : bool
Checks whether the given user already has a review in this thread (even a pending one).

Methods

initializeRender()

Public wrapper called by `FormTrait::handleSubmitSuccess()` before `redrawControl('rating')`.

public initializeRender() : void

computeCounts()

Returns the array [1..5 => count] from the given rating list.

private computeCounts(iterable<string|int, Rating> $ratingList) : array<int, int>
Parameters
$ratingList : iterable<string|int, Rating>
Return values
array<int, int>

initializeAggregate()

Loads the denormalized aggregate (average and count) from the thread.

private initializeAggregate() : void

initializeForStyle()

Loads template data according to the render style.

private initializeForStyle(string $style) : void
Parameters
$style : string

initializeMyVotes()

Loads how this visitor voted on the displayed reviews, to highlight their choice and not offer it again.

private initializeMyVotes(array<int, Rating> $ratingList) : void

One batch call for the whole page (no query per review). An anonymous visitor is recognized by IP, a logged-in one by account; the decision lives in the Api, here only the server-side identity is passed.

Parameters
$ratingList : array<int, Rating>

initializeReviewFull()

Loads aggregate, reviews and star distribution for `STYLE_REVIEW`.

private initializeReviewFull() : void

initializeReviews()

Loads approved ratings of the thread, paginated, plus their authors' avatars.

private initializeReviews() : void

$stars/$sort default to "no filter" and "newest", so styles without a filter (Reviews, Review) behave unchanged.

initializeReviewsDetailed()

Summary plus review list with filter and sorting (`STYLE_REVIEWS_DETAILED`).

private initializeReviewsDetailed() : void

The star bars must show the distribution of all reviews, not only the filtered ones, so they are counted from a separate query (as in STYLE_REVIEW), while $ratingList respects $this->stars.

initializeSummary()

Loads aggregate and star distribution for `STYLE_SUMMARY` (without the full review list).

private initializeSummary() : void

initializeThumbs()

Reads like/dislike counts from the denormalized thread columns (`count_5` is like, `count_1` is dislike), without querying the rating list, so it is fine in listings.

private initializeThumbs() : void

initializeUsers()

Loads avatars of the users who rated.

private initializeUsers(array<int, Rating> $ratingList) : void
Parameters
$ratingList : array<int, Rating>

resolveSort()

Validated `$sort` value; an unknown one (e.g. from a hand-edited URL) falls back to `newest`.

private resolveSort() : string
Return values
string

userHasVoted()

Checks whether the given user already has a review in this thread (even a pending one).

private userHasVoted(int $userId) : bool

Prevents double voting.

Parameters
$userId : int
Return values
bool
On this page

Search results