RatingVote
extends RatingVote
in package
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
- #[Entity]
- #[Table]
- $name: 'cms_mod_base_rating_votes'
- #[TableAlias]
- 'ratingVote'
Table of Contents
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'
$ip
protected
string
$ip
= ''
Attributes
- #[Column]
- $name: 'ip'
- $type: 'string'
- $length: 45
- $options: ['default' => '']
- #[PersonalData]
- PersonalDataKind::Hidden
$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]
$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>getId()
public
getId() : int|null
Return values
int|nullgetInsertDatetime()
public
getInsertDatetime() : DateTime
Return values
DateTimegetIp()
public
getIp() : string
Return values
stringgetKind()
public
getKind() : string
Return values
stringgetOwnerUserId()
Returns the id of the user who created the record; `null` for an unknown or anonymous owner.
public
getOwnerUserId() : int|null
Return values
int|nullgetRatingId()
public
getRatingId() : int
Return values
intgetUserId()
public
getUserId() : int|null
Return values
int|nullgetVote()
true = for (helpful), false = against.
public
getVote() : bool
Return values
boolisPersisted()
public
isPersisted() : bool
Return values
boolisReport()
public
isReport() : bool
Return values
boolisUp()
public
isUp() : bool
Return values
boolsetId()
public
setId(int|null $id) : $this
Parameters
- $id : int|null
Return values
$thissetInsertDatetime()
public
setInsertDatetime(DateTime $insertDatetime) : $this
Parameters
- $insertDatetime : DateTime
Return values
$thissetIp()
public
setIp(string $ip) : $this
Parameters
- $ip : string
Return values
$thissetKind()
public
setKind(string $kind) : $this
Parameters
- $kind : string
Return values
$thissetRatingId()
public
setRatingId(int $ratingId) : $this
Parameters
- $ratingId : int
Return values
$thissetUserId()
public
setUserId(int|null $userId) : $this
Parameters
- $userId : int|null
Return values
$thissetVote()
public
setVote(bool $vote) : $this
Parameters
- $vote : bool
Return values
$thisgetTraitsRecursive()
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>