public function vote($vote = 0, $user_id = 0, $ip = null)
	{
		if (!$this->get('id'))
		{
			$this->addError(Lang::txt('No record found'));
			return false;
		}

		if (!$vote)
		{
			$this->addError(Lang::txt('No vote provided'));
			return false;
		}

		$ip = $ip ?: Request::ip();

		$al = $this->ballot($user_id, $ip);
		$al->set('item_type', 'comment');
		$al->set('item_id', $this->get('id'));
		$al->set('created_by', $user_id);
		if ($ip)
		{
			$al->set('ip', $ip);
		}

		$vote = $al->automaticVote(['vote' => $vote]);

		if ($this->get('created_by') == $user_id)
		{
			$this->addError(Lang::txt('Cannot vote for your own entry'));
			return false;
		}

		if ($vote != $al->get('vote', 0))
		{
			if ($vote > 0)
			{
				$this->set('positive', (int) $this->get('positive') + 1);
				if ($al->get('id'))
				{
					$this->set('negative', (int) $this->get('negative') - 1);
				}
			}
			else
			{
				if ($al->get('id'))
				{
					$this->set('positive', (int) $this->get('positive') - 1);
				}
				$this->set('negative', (int) $this->get('negative') + 1);
			}

			if (!$this->save())
			{
				return false;
			}

			$al->set('vote', $vote);

			if (!$al->save())
			{
				$this->addError($al->getError());
				return false;
			}
		}

		return true;
	}
public function vote($vote = 0, $user_id = 0, $ip = null)
	{
		if (!$this->get('id'))
		{
			$this->addError(Lang::txt('No record found'));
			return false;
		}

		if (!$vote)
		{
			$this->addError(Lang::txt('No vote provided'));
			return false;
		}

		$ip = $ip ?: Request::ip();

		$al = $this->ballot($user_id, $ip);
		$al->set('item_type', 'comment');
		$al->set('item_id', $this->get('id'));
		$al->set('created_by', $user_id);
		if ($ip)
		{
			$al->set('ip', $ip);
		}

		$vote = $al->automaticVote(['vote' => $vote]);

		if ($this->get('created_by') == $user_id)
		{
			$this->addError(Lang::txt('Cannot vote for your own entry'));
			return false;
		}

		if ($vote != $al->get('vote', 0))
		{
			if ($vote > 0)
			{
				$this->set('positive', (int) $this->get('positive') + 1);
				if ($al->get('id'))
				{
					$this->set('negative', (int) $this->get('negative') - 1);
				}
			}
			else
			{
				if ($al->get('id'))
				{
					$this->set('positive', (int) $this->get('positive') - 1);
				}
				$this->set('negative', (int) $this->get('negative') + 1);
			}

			if (!$this->save())
			{
				return false;
			}

			$al->set('vote', $vote);

			if (!$al->save())
			{
				$this->addError($al->getError());
				return false;
			}
		}

		return true;
	}
public function vote ( $ vote = 0 , $ user_id = 0 , $ ip = null ) { if ( ! $ this -> get ( 'id' ) ) { $ this -> addError ( Lang :: txt ( 'No record found' ) ) ; return false ; } if ( ! $ vote ) { $ this -> addError ( Lang :: txt ( 'No vote provided' ) ) ; return false ; } $ ip = $ ip ? : Request :: ip ( ) ; $ al = $ this -> ballot ( $ user_id , $ ip ) ; $ al -> set ( 'item_type' , 'comment' ) ; $ al -> set ( 'item_id' , $ this -> get ( 'id' ) ) ; $ al -> set ( 'created_by' , $ user_id ) ; if ( $ ip ) { $ al -> set ( 'ip' , $ ip ) ; } $ vote = $ al -> automaticVote ( [ 'vote' => $ vote ] ) ; if ( $ this -> get ( 'created_by' ) == $ user_id ) { $ this -> addError ( Lang :: txt ( 'Cannot vote for your own entry' ) ) ; return false ; } if ( $ vote != $ al -> get ( 'vote' , 0 ) ) { if ( $ vote > 0 ) { $ this -> set ( 'positive' , ( int ) $ this -> get ( 'positive' ) + 1 ) ; if ( $ al -> get ( 'id' ) ) { $ this -> set ( 'negative' , ( int ) $ this -> get ( 'negative' ) - 1 ) ; } } else { if ( $ al -> get ( 'id' ) ) { $ this -> set ( 'positive' , ( int ) $ this -> get ( 'positive' ) - 1 ) ; } $ this -> set ( 'negative' , ( int ) $ this -> get ( 'negative' ) + 1 ) ; } if ( ! $ this -> save ( ) ) { return false ; } $ al -> set ( 'vote' , $ vote ) ; if ( ! $ al -> save ( ) ) { $ this -> addError ( $ al -> getError ( ) ) ; return false ; } } return true ; }
Vote for the entry

@param   integer  $vote     The vote [0, 1]
@param   integer  $user_id  Optinal user ID to set as voter
@param   string   $ip       Optional IP address
@return  boolean  False if error, True on success
Vote for the entry