CoolCMS API

RatingVote extends BaseEntity
in package
implements OwnerAwareInterface, IdentifiableInterface uses IdentifiableTrait

AbstractYes

One vote on one rating: "was this review helpful?".

NOTE: not to be confused with Rating: Rating rates an object (product, article), RatingVote is one level below and votes on a specific review; hence a separate table instead of a column on Rating.

vote is deliberately generic (1 = for, 0 = against), not "helpful"/"thumb": it holds the vote, not today's question or visual. Same convention as cms_mod_discussion_message_votes.vote; denormalized counts live on Rating::$votesUp/$votesDown.

The same table also holds reports of a review (kind, see the constructor).

Dedup: UNIQUE (rating_id, user_id, kind) guards logged-in users. An anonymous vote has userId NULL and MySQL allows multiple NULLs in UNIQUE, so the application must dedupe anonymous votes by ip and kind (index idx_rating_ip_kind), and only when the setting 2/rating.allowAnonymousReviewVote allows it.

Attributes
#[MappedSuperclass]
#[TableAlias]
$alias: 'ratingVote'

Table of Contents

Interfaces

OwnerAwareInterface
Entity that knows who created it (the owner is the author or sender of the record); the named entry point to the generic base of the conditional RBAC role `owner`.
IdentifiableInterface
Entity with a simple integer primary key. Most entities have one (often via {@see \App\Core\Traits\Shared\Models\Entities\IdentifiableTrait}); texts and links with a composite key do not, which is why `getId()` is not on {@see \App\Core\Base\BaseEntity}. Code that needs the id of a generic entity asks for this interface (parameter type, template bound, `instanceof`).

Constants

KIND_REPORT  : string = 'report'
Record kind: report of an inappropriate review.
KIND_VOTE  : string = 'vote'
Record kind: vote on review helpfulness.
VOTE_DOWN  : int = 0
Vote against (currently "unhelpful", thumb down).
VOTE_UP  : int = 1
Vote for (currently "helpful", thumb up).

Properties

$id  : int|null
$insertDatetime  : DateTime
$ip  : string
$kind  : string
$ratingId  : int
$userId  : int|null
$vote  : bool

Methods

__construct()  : mixed
callInitMethods()  : void
Calls `init{TraitName}()` for every used trait that defines such a method.
getAllTraits()  : array<string, string>
Returns all traits the class uses, including those used by parent classes and nested traits.
getId()  : int|null
getInsertDatetime()  : DateTime
getIp()  : string
getKind()  : string
getOwnerUserId()  : int|null
Returns the id of the user who created the record; `null` for an unknown or anonymous owner.
getRatingId()  : int
getUserId()  : int|null
getVote()  : bool
true = for (helpful), false = against.
isPersisted()  : bool
isReport()  : bool
isUp()  : bool
setId()  : $this
setInsertDatetime()  : $this
setIp()  : $this
setKind()  : $this
setRatingId()  : $this
setUserId()  : $this
setVote()  : $this
getTraitsRecursive()  : array<string, string>
Walks the trait list recursively and collects nested traits too.

Constants

KIND_REPORT

Record kind: report of an inappropriate review.

public string KIND_REPORT = 'report'

KIND_VOTE

Record kind: vote on review helpfulness.

public string KIND_VOTE = 'vote'

VOTE_DOWN

Vote against (currently "unhelpful", thumb down).

public int VOTE_DOWN = 0

VOTE_UP

Vote for (currently "helpful", thumb up).

public int VOTE_UP = 1

Properties

$id

protected int|null $id = null
Attributes
#[Column]
$type: 'bigint'
$name: 'rating_vote_id'
$options: ['unsigned' => true]
#[GeneratedValue]
#[Id]

$insertDatetime

protected DateTime $insertDatetime = new DateTime()
Attributes
#[Column]
$name: 'insert_datetime'
$type: 'datetime'
#[ExternalReadonly]

$kind

protected string $kind = self::KIND_VOTE
Attributes
#[Column]
$name: 'kind'
$type: 'string'
$length: 16
$options: ['default' => self::KIND_VOTE]

$ratingId

protected int $ratingId = 0
Attributes
#[Column]
$type: 'integer'
$name: 'cms_mod_base_ratings_rating_id'
$options: ['unsigned' => true]

$userId

protected int|null $userId = null
Attributes
#[Column]
$type: 'integer'
$name: 'cms_system_users_user_id'
$nullable: true
$options: ['unsigned' => true]
#[ExternalReadonly]

$vote

protected bool $vote = true
Attributes
#[Column]
$name: 'vote'
$type: 'boolean'

Methods

__construct()

public __construct([int|null $id = null ][, int $ratingId = 0 ][, int|null $userId = null ][, string $kind = self::KIND_VOTE ][, string $ip = '' ][, bool $vote = true ][, DateTime $insertDatetime = new DateTime() ]) : mixed
Parameters
$id : int|null = null
$ratingId : int = 0
$userId : int|null = null
$kind : string = self::KIND_VOTE
$ip : string = ''
$vote : bool = true
$insertDatetime : DateTime = new DateTime()

callInitMethods()

Calls `init{TraitName}()` for every used trait that defines such a method.

public callInitMethods() : void

getAllTraits()

Returns all traits the class uses, including those used by parent classes and nested traits.

public getAllTraits() : array<string, string>
Return values
array<string, string>

getInsertDatetime()

public getInsertDatetime() : DateTime
Return values
DateTime

getIp()

public getIp() : string
Return values
string

getKind()

public getKind() : string
Return values
string

getOwnerUserId()

Returns the id of the user who created the record; `null` for an unknown or anonymous owner.

public getOwnerUserId() : int|null
Return values
int|null

getRatingId()

public getRatingId() : int
Return values
int

getUserId()

public getUserId() : int|null
Return values
int|null

getVote()

true = for (helpful), false = against.

public getVote() : bool
Return values
bool

isReport()

public isReport() : bool
Return values
bool

setId()

public setId(int|null $id) : $this
Parameters
$id : int|null
Return values
$this

setInsertDatetime()

public setInsertDatetime(DateTime $insertDatetime) : $this
Parameters
$insertDatetime : DateTime
Return values
$this

setIp()

public setIp(string $ip) : $this
Parameters
$ip : string
Return values
$this

setKind()

public setKind(string $kind) : $this
Parameters
$kind : string
Return values
$this

setRatingId()

public setRatingId(int $ratingId) : $this
Parameters
$ratingId : int
Return values
$this

setUserId()

public setUserId(int|null $userId) : $this
Parameters
$userId : int|null
Return values
$this

setVote()

public setVote(bool $vote) : $this
Parameters
$vote : bool
Return values
$this

getTraitsRecursive()

Walks the trait list recursively and collects nested traits too.

private static getTraitsRecursive(array<string, string> $traits) : array<string, string>
Parameters
$traits : array<string, string>
Return values
array<string, string>
On this page

Search results