Events
Star Ratings events follow the same pattern as standard Craft events. (opens new window)
use doublesecretagency\starratings\StarRatings;
use doublesecretagency\starratings\events\RateEvent;
use yii\base\Event;
// Do something BEFORE the rating is cast...
Event::on(
StarRatings::class,
StarRatings::EVENT_BEFORE_RATE,
function (RateEvent $event) {
// See the complete list of parameters below
$elementId = $event->id;
}
);
use doublesecretagency\starratings\StarRatings;
use doublesecretagency\starratings\events\RateEvent;
use yii\base\Event;
// Do something AFTER the rating is cast...
Event::on(
StarRatings::class,
StarRatings::EVENT_AFTER_RATE,
function (RateEvent $event) {
// See the complete list of parameters below
$elementId = $event->id;
}
);
Both events give you access to the RateEvent
model in the $event
variable. The contents of that variable will look like this...
Parameter | Type | Description |
---|---|---|
id | int | Element ID of the element being rated. |
key | string or null | Optional key for allowing multiple rating types. |
rating | int | The value of the rating. |
changedFrom | int | The previous rating value (if it exists). |
userId | int | ID of the user casting a rating (if login is required to rate). |