Creates an empty vote instance

@param RatingInterface $rating
@param UserInterface $voter
@return \DCS\RatingBundle\Model\VoteInterface
509746
public function createVote(RatingInterface $rating, UserInterface $voter)
    {
        $class = $this->getClass();
        $vote = new $class;
        $vote->setRating($rating);
        $vote->setVoter($voter);

        $this->dispatcher->dispatch(DCSRatingEvents::VOTE_CREATE, new Event\VoteEvent($vote));

        return $vote;
    }
68107
public function update_rating($rating) {
        global $DB;

        $time = time();

        $data = new stdClass;
        $data->rating       = $rating;
        $data->timemodified = $time;

        $item = new stdclass();
        $item->id = $this->itemid;
        $items = array($item);

        $ratingoptions = new stdClass;
        $ratingoptions->context = $this->context;
        $ratingoptions->component = $this->component;
        $ratingoptions->ratingarea = $this->ratingarea;
        $ratingoptions->items = $items;
        $ratingoptions->aggregate = RATING_AGGREGATE_AVERAGE; // We dont actually care what aggregation method is applied.
        $ratingoptions->scaleid = $this->scaleid;
        $ratingoptions->userid = $this->userid;

        $rm = new rating_manager();
        $items = $rm->get_ratings($ratingoptions);
        $firstitem = $items[0]->rating;

        if (empty($firstitem->id)) {
            // Insert a new rating.
            $data->contextid    = $this->context->id;
            $data->component    = $this->component;
            $data->ratingarea   = $this->ratingarea;
            $data->rating       = $rating;
            $data->scaleid      = $this->scaleid;
            $data->userid       = $this->userid;
            $data->itemid       = $this->itemid;
            $data->timecreated  = $time;
            $data->timemodified = $time;
            $DB->insert_record('rating', $data);
        } else {
            // Update the rating.
            $data->id           = $firstitem->id;
            $DB->update_record('rating', $data);
        }
    }
71124
public function voteup($voter)
    {
        //first check if we have voted down if yes then just remove that
        if ($votedown = $this->votedowns->getQuery(true)
                                        ->disableChain()
                                        ->voter($voter)
                                        ->fetch()
        ) {
            $votedown->delete();
        } else {
            //find ore create a voteup
            $voteup = $this->voteups->addNew(array('voter' => $voter, 'votee' => $this));
            //if the votee is suscribable then subscribe the voter
            if ($this->isSubscribable() && !$this->subscribed($voter)) {
                $this->addSubscriber($voter);
            }
            $this->_mixer->execute('after.voteup', new AnCommandContext(array('vote' => $voteup)));
        }
    }
736800
public static function build($pollId, $userId, $optionId)
    {
        $vote = new static();

        $vote->poll_id = $pollId;
        $vote->user_id = $userId;
        $vote->option_id = $optionId;

        return $vote;
    }
1346912
public function rate($rating, $userId = null)
    {
        return app(RatingServiceContract::class)->addRateTo($this, $rating, $userId);
    }
104087
public function userRate(RateableContract $rateable, $userId): ?float
    {
        $userId = $this->getRaterUserId($userId);

        $rate = $rateable->ratings()->where([
            'user_id' => $userId,
        ])->first();

        return ($rate) ? $rate->rating : null;
    }
83140
public function deleteReview($userId, $reviewId)
    {
        $review = $this->getReviewById($reviewId);

        $this->validateUserPermissionsToManageReview($review, $userId);

        $review->delete();
    }
931286
private function createProductReview(
        ProductInterface $product,
        $title,
        $rating,
        $comment,
        CustomerInterface $customer = null,
        $transition = ProductReviewTransitions::TRANSITION_ACCEPT
    ) {
        /** @var ReviewInterface $review */
        $review = $this->productReviewFactory->createNew();
        $review->setTitle($title);
        $review->setRating((int) $rating);
        $review->setComment($comment);
        $review->setReviewSubject($product);
        $review->setAuthor($customer);

        $product->addReview($review);

        if (null !== $transition) {
            $stateMachine = $this->stateMachineFactory->get($review, ProductReviewTransitions::GRAPH);
            $stateMachine->apply($transition);
        }

        $this->sharedStorage->set('product_review', $review);

        return $review;
    }
272238
public function vote(TokenInterface $token, $subject, array $attributes): int
    {
        if ($token->getUser() instanceof AdminUserInterface) {
            return self::ACCESS_GRANTED;
        }

        return self::ACCESS_ABSTAIN;
    }
874934
public function getVoteCollectionByReview($reviewId)
    {
        $votesCollection = $this->voteCollection->create()
            ->setReviewFilter($reviewId);

        $votesCollection->getSelect()->join(
            ['rating' => $this->getTable('rating')],
            'rating.rating_id = main_table.rating_id',
            ['rating_code' => 'rating.rating_code']
        );

        return $votesCollection;
    }
137579
public function addVoterVote(VoterInterface $voter, array $attributes, int $vote)
    {
        $currentLogIndex = \count($this->currentLog) - 1;
        $this->currentLog[$currentLogIndex]['voterDetails'][] = [
            'voter' => $voter,
            'attributes' => $attributes,
            'vote' => $vote,
        ];
    }
861823
public function rating($value, $rating) {
		if (strpos($value, $this->baseUrl) === false && strpos($value, $this->httpsUrl) === false) {
			throw new InvalidArgumentException("You can only add a rating to an existing Gravatar URL");
		}
		else if (!in_array(strtolower($rating), $this->ratings)) {
			throw new InvalidArgumentException("Rating must be g,pg,r or x");
		}
		else {
			return $this->query($value, array("rating" => $rating));
		}
	}
103855
protected function getCriterionsAverageScore(\SimpleXMLElement $rating)
    {
        $criterions = array('criterion1', 'criterion2', 'criterion3', 'criterion4', 'criterion5', 'criterion6');
        $sum = 0;
        $divider = 0;
        foreach ($criterions as $criterion) {
            $criterionValue = (float) $rating->$criterion;
            if ($criterionValue > 0) {
                ++$divider;
                $sum += $criterionValue;
            }
        }
        $divider = (0 == $divider) ? count($criterions) : $divider;

        return $sum / $divider;
    }
524794
public function onVote(EventInterface $event)
    {
        $repository = $this->repositoryResolver->getRepositoryForEvent($event);

        if (!$repository) {
            return;
        }

        $vote = $repository->countByReferenceAndByIp($event->getReference(), $event->getRequest()->getClientIp());

        if ($vote >= $this->maxNumber) {
            $event->stopPropagation();
        }
    }
1117562
public function rate($id, $rating)
    {
        return $this->getFactory()->createResult(
            $this->getApi()->rateMovie($id, $rating)
        );
    }
801345
public function createRating($id = null)
    {
        $class = $this->getClass();
        $rating = new $class;

        if (null !== $id) {
            $rating->setId($id);
        }

        $this->dispatcher->dispatch(DCSRatingEvents::RATING_CREATE, new Event\RatingEvent($rating));

        return $rating;
    }
543338
def vote(self, voter, author, permlink, voteweight):
        ''' 
        '''
        vote = Vote(voter, author, permlink, voteweight)
        result = self.steemconnect().broadcast(
            [vote.to_operation_structure()])
        return result