CoolCMS API

Rating extends BaseComponent
in package
uses InitializationTrait, HandleTrait, FormTrait

Generic rating component for any rateable content (articles, profiles, adverts...).

Render styles (first parameter of render()):

  • STYLE_CLASSIC: interactive stars, one click is one AJAX rating (default).
  • STYLE_STATIC: read-only aggregate, no interaction.
  • STYLE_REVIEW: summary bars, review button and review list.
  • STYLE_SUMMARY: static summary bars, no reviews.
  • STYLE_REVIEWS: review list only.
  • STYLE_REVIEWS_DETAILED: summary, star filter, sorting and the review list.
  • STYLE_NUMBER: average rating as a plain number, no HTML.
  • STYLE_THUMBS: thumb up (value 5) and thumb down (value 1).

The thread must exist (the rateable entity holds it through the scalar ratingThreadId). The presenter handles anonymous rating in createComponentRating() via setAllowAnonymous().

Table of Contents

Constants

REVIEWS_PER_PAGE  : mixed = 1
SORT_BEST  : mixed = 'best'
SORT_HELPFUL  : mixed = 'helpful'
SORT_NEWEST  : mixed = 'newest'
SORT_WORST  : mixed = 'worst'
SORTS  : mixed = [self::SORT_NEWEST => ['id' => false], self::SO...
Allowed `$sort` values mapped to the manager `orderBy`; an unknown value falls back to `newest`.
STYLE_CLASSIC  : mixed = 'Classic'
STYLE_NUMBER  : mixed = 'Number'
STYLE_REVIEW  : mixed = 'Review'
STYLE_REVIEWS  : mixed = 'Reviews'
STYLE_REVIEWS_DETAILED  : mixed = 'ReviewsDetailed'
Detailed review list (summary, star filter, sorting).
STYLE_STATIC  : mixed = 'Static'
STYLE_SUMMARY  : mixed = 'Summary'
STYLE_THUMBS  : mixed = 'Thumbs'
MODAL_REPLY_TARGET  : mixed = 'ratingReply'
MODAL_TARGET  : mixed = 'ratingReview'
PROS_CONS_MAX_ITEMS  : mixed = 10
Max count and length of pros/cons items (server-side sanitization).
PROS_CONS_MAX_LENGTH  : mixed = 120

Properties

$container  : Container
$page  : int
$routerDispatcher  : RouterDispatcher
$sort  : string
Review list sorting, see {@see self::SORTS}.
$stars  : int
Star-count filter of the review list; 0 means no filter (default, other styles ignore it).
$style  : string
$threadId  : int
$translator  : ITranslator
$appContext  : AppContext
$componentParameters  : array<string, mixed>
$currencyContext  : CurrencyContext|null
$deviceDetector  : DeviceDetector|null
$languageContext  : LanguageContext|null
$localizationContext  : LocalizationContext|null
$settingContext  : SettingContext
$themeContext  : ThemeContext|null
$translatorDomain  : string|null
$allowAnonymous  : bool
$allowVoting  : bool
$boundThreadId  : int
IMPORTANT: thread set by the parent on the server, see `setThreadId()`. `$threadId` is `#[Persistent]` (comes from the URL), so taking it from a hidden field would let a form on a foreign page write a rating into any thread, e.g. the visitor's own profile or a thread with ratings disabled. Writes (stars and reviews) are therefore allowed only into this thread; a component without a server-set thread never writes.
$eventDispatcher  : EventDispatcher
$hasVoted  : bool|null
$modalRegistry  : ModalRegistry
$overrideRatingUseAutoApprovalReview  : bool|null
$overrideRatingUseAutoApprovalStars  : bool|null
null uses the DB setting; true/false overrides it for this instance.
$ownerId  : int
$perPage  : int|null
Reviews per page; `null` means {@see REVIEWS_PER_PAGE}.
$ratingManager  : RatingManager
$ratingThreadManager  : RatingThreadManager
$showSummary  : bool
Whether to render the summary inside `STYLE_REVIEWS_DETAILED`, see `setShowSummary()`.
$thumbs  : array<int, string>
Thumbs shown by `STYLE_THUMBS`: 'up' (value 5) and/or 'down' (value 1).
$userManager  : UserManager
$verifiedBuyersResolver  : null|callable(array<int, int>): array<int, int>
Optional resolver telling which of the given authors really bought the item.

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
canRespond()  : bool
Whether the current visitor may reply to reviews (logged-in content owner).
canVote()  : bool
Whether the current visitor may rate (voting enabled and logged in, or anonymous allowed).
createComponent()  : IComponent|null
createComponentReplyForm()  : Form
Review reply form (in a modal): textarea and submit.
createComponentReviewForm()  : Form
Written review form (in a modal): stars, text, pros and cons.
getAppContext()  : AppContext
getComponentParameter()  : mixed
Returns a component parameter, or null when it is not set.
getContainer()  : Container
getCurrencyContext()  : CurrencyContext|null
getLanguageContext()  : LanguageContext|null
getLocalizationContext()  : LocalizationContext|null
getPerPage()  : int
Effective reviews per page: the instance setting, otherwise the constant.
getRouterDispatcher()  : RouterDispatcher
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getThemeContext()  : ThemeContext|null
handleFilterStars()  : void
AJAX signal: filters the list by star count (0 clears the filter).
handlePage()  : void
AJAX signal: switches the review list page.
handleRate()  : void
AJAX signal: saves the star rating (1-5) and redraws the component.
handleReportReview()  : void
AJAX signal: reports an inappropriate review.
handleShowReplyForm()  : void
Signal that shows the reply form in a modal (`STYLE_REVIEW`).
handleShowReviewForm()  : void
Signal that shows the review form in a modal (`STYLE_REVIEW`).
handleSortReviews()  : void
AJAX signal: sorts the review list. An unknown value falls back to "newest" (checked by `resolveSort()` on render), so a hand-edited URL breaks nothing.
handleVoteReview()  : void
AJAX signal: vote on the helpfulness of one review (thumb up/down).
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initializeAllContexts()  : void
initializeRender()  : void
Public wrapper called by `FormTrait::handleSubmitSuccess()` before `redrawControl('rating')`.
injectDeviceDetector()  : void
loadState()  : void
Ignores the persistent `threadId` from the URL when the parent set the thread.
onCreate()  : void
onReviewError()  : void
Re-renders the modal with errors when validation fails (no stars, forged value).
onSubmit()  : void
Handles the review submission.
onSubmitReply()  : void
Handles the review reply submission.
render()  : void
Default render; takes the style as the first parameter and the other `renderX()` call it.
renderNumber()  : void
renderReview()  : void
renderReviews()  : void
renderReviewsDetailed()  : void
Detailed review list: summary bars, star filter and sorting.
renderStatic()  : void
renderSummary()  : void
renderThumbs()  : void
Like/dislike rating with two thumbs. Under the hood it is the same star rating: thumb up is value 5, thumb down is value 1. Counts come from the denormalized `count_5` / `count_1` on the thread.
setAllowAnonymous()  : self
setAllowVoting()  : self
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setLanguageContext()  : $this
setLocalizationContext()  : $this
setOverrideRatingUseAutoApprovalReview()  : self
Overrides the DB flag `rating.useAutoApprovalReviews` for this instance; null uses the DB setting (default).
setOverrideRatingUseAutoApprovalStars()  : self
Overrides the DB flag `autoApprovalStars` for this instance; null uses the DB setting (default).
setOwnerId()  : self
setPerPage()  : self
Reviews per page for this instance (at least 1).
setSettingContext()  : $this
setShowSummary()  : self
Sets whether `STYLE_REVIEWS_DETAILED` also renders the summary (big score, bars, statistics).
setStyle()  : self
setThemeContext()  : $this
setThreadId()  : self
setThumbs()  : self
Limits the thumbs rendered by `STYLE_THUMBS`, e.g. ['up'] for like only.
setup()  : void
setupAppContext()  : void
setVerifiedBuyersResolver()  : self
Sets how to find which review authors really bought the rated item ("verified purchase").
typedComponent()  : T
Returns a subcomponent with a verified type.
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getModalTarget()  : string
getReplyModalTarget()  : string
getTranslator()  : ITranslator
setTemplateFile()  : void
setTranslator()  : self
buildRating()  : Rating
Builds the rating entity shared by stars and reviews.
buildSaveMeta()  : array<string, bool>
Builds the meta array for `save()`, passing component-level overrides to the Api layer.
computeCounts()  : array<int, int>
Returns the array [1..5 => count] from the given rating list.
createModalContent()  : string
createModalEvent()  : ModalWindowEvent
createMultiplierComponent()  : Multiplier<string|int, IComponent>
Creates a multiplier for the component.
createNewComponentInstance()  : IComponent|null
Creates a new component instance without adding it to the presenter; used by the multiplier.
createReplyModalContent()  : string
createReplyModalEvent()  : ModalWindowEvent
createStandardComponent()  : IComponent|null
Creates a standard component (not a multiplier).
createSuccessContent()  : string
decodeItems()  : array<int, string>|null
Decodes and sanitizes a JSON array of strings from a hidden input (pros/cons).
handleSubmitError()  : void
Handles a submission error. `$resultKey` selects the translation key under `.result.*` (`duplicated` for the dedup rejection from {@see \App\UI\Api\Base\Models\Managers\RatingManager::beforeSave()}, otherwise the generic `failure`), so the user sees "already rated" instead of a generic error.
handleSubmitSuccess()  : void
Handles a successful submission.
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.
normalizeText()  : string|null
Returns null for empty text (stars only), otherwise the trimmed text.
refusedVoteResultKey()  : string
Returns the translation key for a rejection from `canVote()`. A logged-in user who already rated gets the "already rated" message (same as the Api dedup), others a generic error.
resolveSort()  : string
Validated `$sort` value; an unknown one (e.g. from a hand-edited URL) falls back to `newest`.
resolveSubmittedThreadId()  : int
Returns the thread for writing a review. A component with a server-set thread (`setThreadId()` in the parent) always uses that one; any other hidden-field value yields 0, so `canVote()` rejects the write. Without a set thread nothing is written.
updateModalContent()  : void
Aktualizuje obsah modalu
userHasVoted()  : bool
Checks whether the given user already has a review in this thread (even a pending one).

Constants

REVIEWS_PER_PAGE

public mixed REVIEWS_PER_PAGE = 1

SORT_BEST

public mixed SORT_BEST = 'best'

SORT_HELPFUL

public mixed SORT_HELPFUL = 'helpful'

SORT_NEWEST

public mixed SORT_NEWEST = 'newest'

SORT_WORST

public mixed SORT_WORST = 'worst'

SORTS

Allowed `$sort` values mapped to the manager `orderBy`; an unknown value falls back to `newest`.

public mixed SORTS = [self::SORT_NEWEST => ['id' => false], self::SORT_BEST => ['value' => false, 'id' => false], self::SORT_WORST => ['value' => true, 'id' => false], self::SORT_HELPFUL => ['votesUp' => false, 'id' => false]]

helpful sorts by the denormalized votesUp; aggregating the vote table would run on every list render.

STYLE_CLASSIC

public mixed STYLE_CLASSIC = 'Classic'

STYLE_NUMBER

public mixed STYLE_NUMBER = 'Number'

STYLE_REVIEW

public mixed STYLE_REVIEW = 'Review'

STYLE_REVIEWS

public mixed STYLE_REVIEWS = 'Reviews'

STYLE_REVIEWS_DETAILED

Detailed review list (summary, star filter, sorting).

public mixed STYLE_REVIEWS_DETAILED = 'ReviewsDetailed'

STYLE_STATIC

public mixed STYLE_STATIC = 'Static'

STYLE_SUMMARY

public mixed STYLE_SUMMARY = 'Summary'

STYLE_THUMBS

public mixed STYLE_THUMBS = 'Thumbs'

MODAL_REPLY_TARGET

private mixed MODAL_REPLY_TARGET = 'ratingReply'

MODAL_TARGET

private mixed MODAL_TARGET = 'ratingReview'

PROS_CONS_MAX_ITEMS

Max count and length of pros/cons items (server-side sanitization).

private mixed PROS_CONS_MAX_ITEMS = 10

PROS_CONS_MAX_LENGTH

private mixed PROS_CONS_MAX_LENGTH = 120

Properties

$page

public int $page = 1
Attributes
#[Persistent]

$sort

Review list sorting, see {@see self::SORTS}.

public string $sort = self::SORT_NEWEST
Attributes
#[Persistent]

$stars

Star-count filter of the review list; 0 means no filter (default, other styles ignore it).

public int $stars = 0
Attributes
#[Persistent]

$style

public string $style = self::STYLE_CLASSIC
Attributes
#[Persistent]

$threadId

public int $threadId = 0
Attributes
#[Persistent]

$componentParameters

protected array<string, mixed> $componentParameters = []

component parameters set by setComponentParameter()

$translatorDomain

protected string|null $translatorDomain = 'front.base.components.rating'

$allowAnonymous

private bool $allowAnonymous = false

$allowVoting

private bool $allowVoting = true

$boundThreadId

IMPORTANT: thread set by the parent on the server, see `setThreadId()`. `$threadId` is `#[Persistent]` (comes from the URL), so taking it from a hidden field would let a form on a foreign page write a rating into any thread, e.g. the visitor's own profile or a thread with ratings disabled. Writes (stars and reviews) are therefore allowed only into this thread; a component without a server-set thread never writes.

private int $boundThreadId = 0

$hasVoted

private bool|null $hasVoted = null

$overrideRatingUseAutoApprovalReview

private bool|null $overrideRatingUseAutoApprovalReview = null

$overrideRatingUseAutoApprovalStars

null uses the DB setting; true/false overrides it for this instance.

private bool|null $overrideRatingUseAutoApprovalStars = null

$ownerId

private int $ownerId = 0

$perPage

Reviews per page; `null` means {@see REVIEWS_PER_PAGE}.

private int|null $perPage = null

Set per instance because each template lays reviews out differently.

$showSummary

Whether to render the summary inside `STYLE_REVIEWS_DETAILED`, see `setShowSummary()`.

private bool $showSummary = true

$thumbs

Thumbs shown by `STYLE_THUMBS`: 'up' (value 5) and/or 'down' (value 1).

private array<int, string> $thumbs = ['up', 'down']

$verifiedBuyersResolver

Optional resolver telling which of the given authors really bought the item.

private null|callable(array<int, int>): array<int, int> $verifiedBuyersResolver = null

See setVerifiedBuyersResolver().

Methods

__call()

Dispatches `renderXyz()` to `render('Xyz', ...$args)`.

public __call(string $name, array<string|int, mixed> $args) : mixed

Called only when the component has no renderXyz() method of its own.

Parameters
$name : string
$args : array<string|int, mixed>

canRespond()

Whether the current visitor may reply to reviews (logged-in content owner).

public canRespond() : bool
Return values
bool

canVote()

Whether the current visitor may rate (voting enabled and logged in, or anonymous allowed).

public canVote() : bool
Return values
bool

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

createComponentReplyForm()

Review reply form (in a modal): textarea and submit.

public createComponentReplyForm() : Form
Return values
Form

createComponentReviewForm()

Written review form (in a modal): stars, text, pros and cons.

public createComponentReviewForm() : Form
Return values
Form

getComponentParameter()

Returns a component parameter, or null when it is not set.

public getComponentParameter(string $name) : mixed
Parameters
$name : string

getContainer()

public getContainer() : Container
Return values
Container

getPerPage()

Effective reviews per page: the instance setting, otherwise the constant.

public getPerPage() : int
Return values
int

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

handleFilterStars()

AJAX signal: filters the list by star count (0 clears the filter).

public handleFilterStars(int $stars) : void

Pagination returns to the first page because a narrower selection has fewer pages.

Parameters
$stars : int

handlePage()

AJAX signal: switches the review list page.

public handlePage(int $page) : void
Parameters
$page : int

handleRate()

AJAX signal: saves the star rating (1-5) and redraws the component.

public handleRate(int $value) : void
Parameters
$value : int
Attributes
#[Requires]
$ajax: true

handleReportReview()

AJAX signal: reports an inappropriate review.

public handleReportReview(int $ratingId) : void

It neither deletes nor hides the review, only flags it for moderation; only an admin can delete it. The Api rejects a repeated report by the same person (dedup like votes).

Parameters
$ratingId : int
Attributes
#[Requires]
$ajax: true

handleShowReplyForm()

Signal that shows the reply form in a modal (`STYLE_REVIEW`).

public handleShowReplyForm(int $ratingId) : void
Parameters
$ratingId : int

handleShowReviewForm()

Signal that shows the review form in a modal (`STYLE_REVIEW`).

public handleShowReviewForm([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

handleSortReviews()

AJAX signal: sorts the review list. An unknown value falls back to "newest" (checked by `resolveSort()` on render), so a hand-edited URL breaks nothing.

public handleSortReviews(string $sort) : void
Parameters
$sort : string

handleVoteReview()

AJAX signal: vote on the helpfulness of one review (thumb up/down).

public handleVoteReview(int $ratingId, int $up) : void

The component decides nothing here: it takes identity and IP from the server and passes them to the Api, which decides whether an anonymous visitor may vote (setting 2/rating.allowAnonymousReviewVote) and whether this visitor already voted. A duplicate vote is rejected, not overwritten, hence result.duplicated.

Parameters
$ratingId : int
$up : int
Attributes
#[Requires]
$ajax: true

hasServiceByType()

Returns whether the container has a service of the given type.

public hasServiceByType(string $className) : bool

The name is composed dynamically (module plus component), so class_exists() runs first, and a true result guarantees a valid type.

Parameters
$className : string
Tags
phpstan-assert-if-true

class-string $className

Return values
bool

initializeRender()

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

public initializeRender() : void

loadState()

Ignores the persistent `threadId` from the URL when the parent set the thread.

public loadState(array<string, mixed> $params) : void
Parameters
$params : array<string, mixed>

onReviewError()

Re-renders the modal with errors when validation fails (no stars, forged value).

public onReviewError(Form $form) : void

IMPORTANT: without this handler an invalid submit (client validation bypassed or off) was rejected by the server and nothing happened in the modal, leaving the user with no hint why.

Parameters
$form : Form

onSubmit()

Handles the review submission.

public onSubmit(Form $form, ArrayHash $values) : void
Parameters
$form : Form
$values : ArrayHash

onSubmitReply()

Handles the review reply submission.

public onSubmitReply(Form $form, ArrayHash $values) : void
Parameters
$form : Form
$values : ArrayHash

render()

Default render; takes the style as the first parameter and the other `renderX()` call it.

public render([string $style = '' ][, int|null $threadId = null ]) : void

An empty string keeps the current $this->style (for the AJAX snippet re-render).

Parameters
$style : string = ''
$threadId : int|null = null

renderNumber()

public renderNumber([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

renderReview()

public renderReview([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

renderReviews()

public renderReviews([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

renderReviewsDetailed()

Detailed review list: summary bars, star filter and sorting.

public renderReviewsDetailed([int|null $threadId = null ]) : void

The summary is part of this style, so do not combine it with STYLE_SUMMARY on one page.

Parameters
$threadId : int|null = null

renderStatic()

public renderStatic([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

renderSummary()

public renderSummary([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

renderThumbs()

Like/dislike rating with two thumbs. Under the hood it is the same star rating: thumb up is value 5, thumb down is value 1. Counts come from the denormalized `count_5` / `count_1` on the thread.

public renderThumbs([int|null $threadId = null ]) : void
Parameters
$threadId : int|null = null

setAllowAnonymous()

public setAllowAnonymous(bool $allowAnonymous) : self
Parameters
$allowAnonymous : bool
Return values
self

setAllowVoting()

public setAllowVoting(bool $allowVoting) : self
Parameters
$allowVoting : bool
Return values
self

setComponentParameter()

Sets a component parameter.

public setComponentParameter(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

setOverrideRatingUseAutoApprovalReview()

Overrides the DB flag `rating.useAutoApprovalReviews` for this instance; null uses the DB setting (default).

public setOverrideRatingUseAutoApprovalReview(bool|null $value) : self
Parameters
$value : bool|null
Return values
self

setOverrideRatingUseAutoApprovalStars()

Overrides the DB flag `autoApprovalStars` for this instance; null uses the DB setting (default).

public setOverrideRatingUseAutoApprovalStars(bool|null $value) : self
Parameters
$value : bool|null
Return values
self

setOwnerId()

public setOwnerId(int $ownerId) : self
Parameters
$ownerId : int
Return values
self

setPerPage()

Reviews per page for this instance (at least 1).

public setPerPage(int $perPage) : self
Parameters
$perPage : int
Return values
self

setShowSummary()

Sets whether `STYLE_REVIEWS_DETAILED` also renders the summary (big score, bars, statistics).

public setShowSummary(bool $showSummary) : self

A standalone review section wants it (default true). The product detail already shows the summary above the tabs, so it turns this off to avoid repeating the numbers.

Parameters
$showSummary : bool
Return values
self

setStyle()

public setStyle(string $style) : self
Parameters
$style : string
Return values
self

setThreadId()

public setThreadId(int $threadId) : self
Parameters
$threadId : int
Return values
self

setThumbs()

Limits the thumbs rendered by `STYLE_THUMBS`, e.g. ['up'] for like only.

public setThumbs(array<int, string> $thumbs) : self

The array order is the render order.

Parameters
$thumbs : array<int, string>
Return values
self

setVerifiedBuyersResolver()

Sets how to find which review authors really bought the rated item ("verified purchase").

public setVerifiedBuyersResolver(null|callable(array<int, int>): array<int, int> $resolver) : self

The component is shared (blog, profile, shop) and knows nothing about orders, so it gets a function that is called once with the ids of all authors on the page and returns the verified subset. Without a resolver (blog, profile) there is no badge.

This does not decide who may write a review; that is setAllowVoting(), computed by the caller.

Parameters
$resolver : null|callable(array<int, int>): array<int, int>
Return values
self

typedComponent()

Returns a subcomponent with a verified type.

public typedComponent(string $name, T> $type) : T

Use it instead of an inline @var above $this['x'] (which does not narrow the type) and instead of the generic IComponent that $this['x'] returns. See Form::typedComponent().

Parameters
$name : string
$type : T>
Tags
template
Return values
T

frontPresenter()

Returns the front presenter the component is attached to (null outside the front end or when detached).

protected frontPresenter() : BasePresenter|null
Return values
BasePresenter|null

getModalTarget()

protected getModalTarget() : string
Return values
string

getReplyModalTarget()

protected getReplyModalTarget() : string
Return values
string

getTranslator()

protected getTranslator() : ITranslator
Return values
ITranslator

setTemplateFile()

protected setTemplateFile(string $dir, string $filename) : void
Parameters
$dir : string
$filename : string

setTranslator()

protected setTranslator(ITranslator $translator) : self
Parameters
$translator : ITranslator
Return values
self

buildRating()

Builds the rating entity shared by stars and reviews.

private buildRating(int $value) : Rating

Approval is handled by the Api layer in beforeSave per the setting ratingUseAutoApproval.

Parameters
$value : int
Return values
Rating

buildSaveMeta()

Builds the meta array for `save()`, passing component-level overrides to the Api layer.

private buildSaveMeta() : array<string, bool>

An empty array makes the Api use the DB settings.

Return values
array<string, bool>

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>

createModalContent()

private createModalContent() : string
Return values
string

createModalEvent()

private createModalEvent(string $content[, array<string, mixed> $extraOptions = [] ]) : ModalWindowEvent
Parameters
$content : string
$extraOptions : array<string, mixed> = []
Return values
ModalWindowEvent

createMultiplierComponent()

Creates a multiplier for the component.

private createMultiplierComponent(string $name) : Multiplier<string|int, IComponent>
Parameters
$name : string
Return values
Multiplier<string|int, IComponent>

createNewComponentInstance()

Creates a new component instance without adding it to the presenter; used by the multiplier.

private createNewComponentInstance(string $baseName[, int|string|null $uniqueKey = null ]) : IComponent|null
Parameters
$baseName : string
$uniqueKey : int|string|null = null
Return values
IComponent|null

createReplyModalContent()

private createReplyModalContent(int $ratingId) : string
Parameters
$ratingId : int
Return values
string

createReplyModalEvent()

private createReplyModalEvent(string $content[, array<string, mixed> $extraOptions = [] ]) : ModalWindowEvent
Parameters
$content : string
$extraOptions : array<string, mixed> = []
Return values
ModalWindowEvent

createStandardComponent()

Creates a standard component (not a multiplier).

private createStandardComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

createSuccessContent()

private createSuccessContent() : string
Return values
string

decodeItems()

Decodes and sanitizes a JSON array of strings from a hidden input (pros/cons).

private decodeItems(string|null $json) : array<int, string>|null
Parameters
$json : string|null
Return values
array<int, string>|null

handleSubmitError()

Handles a submission error. `$resultKey` selects the translation key under `.result.*` (`duplicated` for the dedup rejection from {@see \App\UI\Api\Base\Models\Managers\RatingManager::beforeSave()}, otherwise the generic `failure`), so the user sees "already rated" instead of a generic error.

private handleSubmitError(Form $form[, string $resultKey = 'result.failure' ]) : void
Parameters
$form : Form
$resultKey : string = 'result.failure'

handleSubmitSuccess()

Handles a successful submission.

private handleSubmitSuccess(Form $form) : void
Parameters
$form : Form

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>

normalizeText()

Returns null for empty text (stars only), otherwise the trimmed text.

private normalizeText(string|null $text) : string|null
Parameters
$text : string|null
Return values
string|null

refusedVoteResultKey()

Returns the translation key for a rejection from `canVote()`. A logged-in user who already rated gets the "already rated" message (same as the Api dedup), others a generic error.

private refusedVoteResultKey() : string

Call only after canVote(), which computes hasVoted.

Return values
string

resolveSort()

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

private resolveSort() : string
Return values
string

resolveSubmittedThreadId()

Returns the thread for writing a review. A component with a server-set thread (`setThreadId()` in the parent) always uses that one; any other hidden-field value yields 0, so `canVote()` rejects the write. Without a set thread nothing is written.

private resolveSubmittedThreadId(mixed $submitted) : int
Parameters
$submitted : mixed
Return values
int

updateModalContent()

Aktualizuje obsah modalu

private updateModalContent(string $content) : void
Parameters
$content : 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