# Vote

### onVoteBeforeDelete

### onVoteAfterDelete

**Description**\
These events are triggered in `CompetitionModelVote::delete` (site - on unvote; admin - on vote delete). If the plugin returns `false` for `onVoteBeforeDelete` event then the vote is not being deleted.

```php
public function onVoteBeforeDelete($context, $table)
{
    // Do something
    return true;
}
```

**Arguments**\
`$context` - the context of the event, ‘com\_competition.vote’.\
`$table` - a reference to `CompetitionTableVote` object.

### onVoteSetScore

**Description**\
These event is triggered in `CompetitionModelVote::setScore` (site). It allows to provide own analytics and change the score and information for vote.

```php
public function onVoteSetScore($context, $entryId, $trackingData, $params, $score)
{
    // Do some analytics
    $score['score']  = 1;
    $score['info'][] = 'I do not like you';
    
    // Do more analytics
    $score['score']  = 1;
    $score['info'][] = 'I am still do not like you :)';
    
    return;
}
```

**Arguments**\
`$context` - the context of the event, ‘com\_competition.vote’.\
`$entryId` - ID of entry for which the vote is being processed.\
`$trackingData` - additional browser tracking data.\
`$params` - parameters of the contest.\
`$score` - array containing the score and info about the score.<br>

### onVoteSetValid

**Description**\
These event is triggered in `CompetitionModelVote::setValid` (site). It allows to provide own analytics and change the validity for vote: `0` - not valid, `1` - valid.

```php
public function onVoteSetValid($context, $entryId, $trackingData, $params, &$valid)
{
    // Do some analytics
    $valid = 0;
    
    return;
}
```

**Arguments**\
`$context` - the context of the event, ‘com\_competition.vote’.\
`$entryId` - ID of entry for which the vote is being processed.\
`$trackingData` - additional browser tracking data.\
`$params` - parameters of the contest.\
`&$valid` - the validity of the score.<br>

### onVoteBeforeSaveDetails

### onVoteAfterSaveDetails

**Description**\
These events are triggered in `CompetitionModelVote::saveDetails` (site). It allows to provide own analytics and set own vote details. Also it is possible to set additional data: country and city (does not set by component).

```php
public function onVoteBeforeSaveDetails($context, $table, $params)
{
    // Set city to London
    $table->country = 'UK';
    $table->city    = 'London';

    return;
}
```

**Arguments**\
`$context` - the context of the event, 'com\_competition.vote'.\
`$table` - a reference to `CompetitionTableVoteDetails` object.\
`$params` - parameters of the contest.

Below is the list of vote details class properties:

```php
/**
 * Vote details table class
 *
 * @property   integer  $id          Primary key
 * @property   integer  $vote_id     Vote ID
 * @property   string   $user_agent  User agent string
 * @property   string   $language    Browser language
 * @property   string   $timezone    User timezone
 * @property   string   $platform    User platform
 * @property   string   $scr_res     Screen resolution
 * @property   string   $canvas      Passed canvas or not
 * @property   string   $referrer    Referrer URL
 * @property   integer  $timediff    Time difference in milliseconds between entering the site and vote
 * @property   string   $country     Country of voter
 * @property   string   $city        City of voter
 */
```

### onVoteResponse

**Description**\
These event is triggered in `CompetitionControllerParticipant::ajaxVote` (site). It allows to change the response data send back to user. For example, you can change a message that is displayed to a user.

```php
public function onVoteResponse($context, $response)
{
	if ($context != 'com_competition.vote'
		|| !\Joomla\CMS\Factory::getApplication()->app->isClient('site'))
	{
		return;
	}

	$response->message = 'onVoteResponse is working fine';
}
```

**Arguments**\
`$context` - the context of the event, ‘com\_competition.vote’.\
`$response` - response object holding vote data, response status and response message.<br>

### onUnvoteResponse

**Description**\
These event is triggered in `CompetitionControllerParticipant::ajaxUnvote` (site). It allows to change the response data send back to user. For example, you can change a message that is displayed to a user.

```php
public function onUnvoteResponse($context, $response)
{
	if ($context != 'com_competition.vote'
		|| !\Joomla\CMS\Factory::getApplication()->app->isClient('site'))
	{
		return;
	}

	$response->message = 'onUnvoteResponse is working fine';
}
```

**Arguments**\
`$context` - the context of the event, ‘com\_competition.vote’.\
`$response` - response object holding vote data, response status and response message.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.norrnext.com/norrcompetition/customisation/events/vote.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
