public function ballot($user_id = 0, $ip = null)
	{
		if (User::isGuest())
		{
			$vote = new Vote();
			$vote->set('item_type', 'comment');
			$vote->set('item_id', $this->get('id'));
			$vote->set('created_by', $user_id);
			$vote->set('ip', $ip);

			return $vote;
		}

		$user = $user_id ? User::getInstance($user_id) : User::getInstance();
		$ip   = $ip ?: Request::ip();

		// See if a person from this IP has already voted in the last week
		$votes = $this->votes();

		if ($user->get('id'))
		{
			$votes->whereEquals('created_by', $user->get('id'));
		}
		elseif ($ip)
		{
			$votes->whereEquals('ip', $ip);
		}

		$vote = $votes
			->ordered()
			->limit(1)
			->row();

		if (!$vote || !$vote->get('id'))
		{
			$vote = new Vote();
			$vote->set('item_type', 'comment');
			$vote->set('item_id', $this->get('id'));
			$vote->set('created_by', $user_id);
			if ($ip)
			{
				$vote->set('ip', $ip);
			}
		}

		return $vote;
	}
public function ballot($user_id = 0, $ip = null)
	{
		if (User::isGuest())
		{
			$vote = new Vote();
			$vote->set('item_type', 'comment');
			$vote->set('item_id', $this->get('id'));
			$vote->set('created_by', $user_id);
			$vote->set('ip', $ip);

			return $vote;
		}

		$user = $user_id ? User::getInstance($user_id) : User::getInstance();
		$ip   = $ip ?: Request::ip();

		// See if a person from this IP has already voted in the last week
		$votes = $this->votes();

		if ($user->get('id'))
		{
			$votes->whereEquals('created_by', $user->get('id'));
		}
		elseif ($ip)
		{
			$votes->whereEquals('ip', $ip);
		}

		$vote = $votes
			->ordered()
			->limit(1)
			->row();

		if (!$vote || !$vote->get('id'))
		{
			$vote = new Vote();
			$vote->set('item_type', 'comment');
			$vote->set('item_id', $this->get('id'));
			$vote->set('created_by', $user_id);
			if ($ip)
			{
				$vote->set('ip', $ip);
			}
		}

		return $vote;
	}
public function ballot ( $ user_id = 0 , $ ip = null ) { if ( User :: isGuest ( ) ) { $ vote = new Vote ( ) ; $ vote -> set ( 'item_type' , 'comment' ) ; $ vote -> set ( 'item_id' , $ this -> get ( 'id' ) ) ; $ vote -> set ( 'created_by' , $ user_id ) ; $ vote -> set ( 'ip' , $ ip ) ; return $ vote ; } $ user = $ user_id ? User :: getInstance ( $ user_id ) : User :: getInstance ( ) ; $ ip = $ ip ? : Request :: ip ( ) ; // See if a person from this IP has already voted in the last week $ votes = $ this -> votes ( ) ; if ( $ user -> get ( 'id' ) ) { $ votes -> whereEquals ( 'created_by' , $ user -> get ( 'id' ) ) ; } elseif ( $ ip ) { $ votes -> whereEquals ( 'ip' , $ ip ) ; } $ vote = $ votes -> ordered ( ) -> limit ( 1 ) -> row ( ) ; if ( ! $ vote || ! $ vote -> get ( 'id' ) ) { $ vote = new Vote ( ) ; $ vote -> set ( 'item_type' , 'comment' ) ; $ vote -> set ( 'item_id' , $ this -> get ( 'id' ) ) ; $ vote -> set ( 'created_by' , $ user_id ) ; if ( $ ip ) { $ vote -> set ( 'ip' , $ ip ) ; } } return $ vote ; }
Check if a user has voted for this entry

@param   integer  $user_id  Optinal user ID to set as voter
@param   string   $ip       IP Address
@return  integer
Check if a user has voted for this entry