DuplicateVoterGuardTrait
Shared core of the "has this visitor already voted or rated this item?" check.
A logged-in voter is guarded by the database unique(…, user_id) index; an anonymous voter
is guarded here by IP. Two null values never collide in a unique index, so without this
check an anonymous visitor could write repeatedly.
Used by RatingVoteManager::hasVoted() (review
usefulness votes) and RatingManager::hasRated()
(the rating itself). Both entities expose the queryable fields userId and ip under the
same names, so one implementation serves both.
Table of Contents
Methods
- voterFilters() : array<int, Filter>|null
- Builds the filters for "does a record of this voter already exist within `$scopeFilters`?".
Methods
voterFilters()
Builds the filters for "does a record of this voter already exist within `$scopeFilters`?".
private
voterFilters(int|null $userId, string $ip, array<int, Filter> $scopeFilters) : array<int, Filter>|null
$scopeFilters identify the item voted on (threadId, ratingId + kind, …). A logged-in
voter ($userId > 0) matches by userId only; the IP is ignored because one account is
one vote from any device. An anonymous voter ($userId null or <= 0) matches by
userId IS NULL AND ip = X. An empty IP cannot identify a voter and returns null;
the caller must read that as "cannot verify", not as "has not voted".
Parameters
- $userId : int|null
- $ip : string
- $scopeFilters : array<int, Filter>