private function _handleVote()

in pp3/module/Application/src/Application/Controller/VerificationController.php [108:163]


    private function _handleVote($vote) {
        $verificationId = $this->params()->fromQuery('id');
        if (empty($verificationId)) {
            return $this->redirect()->toRoute('verification', array(
                'action' => 'list'
            ));
        }
        $verification = $this->_verificationRepository->find($verificationId);
        if (!$verification) {
            return $this->redirect()->toRoute('verification', array(
                'action' => 'list'
            ));
        }
        $req = null;
        foreach($verification->getVerificationRequests() as $verificationRequest) {
            if($verificationRequest->getVerifierId() == $this->getAuthenticatedUserId()) {
                $req = $verificationRequest;
                break;
            }
        }
        if($req == null) {
            $req = new VerificationRequest();
            $req->setCreatedAt(new \DateTime('now'));
            $req->setVerification($verification);
            $req->setVerifier($this->_userRepository->find($this->getAuthenticatedUserId()));
            $req->setVote(VerificationRequest::VOTE_UNDECIDED);
            $verification->addVerificationRequest($req);
        }

        $req->setVote($vote);
        $req->setVotedAt(new \DateTime('now'));
        $comment = $this->params()->fromPost('comment');
        if (!empty($comment)) {
            $config = HTMLPurifier_Config::createDefault();
            $purifier = new HTMLPurifier($config);
            $comment = $purifier->purify($comment);
            $req->setComment($comment);
        }
        $this->_verificationRequestRepository->persist($req);
        $votesBreakdown = $this->_verificationRequestRepository->getVotesBreakdownForVerification($req->getVerification()->getid());
        $verification = $req->getVerification();
        $verification->resolveStatus($votesBreakdown);
        $this->_verificationRepository->persist($verification);
        if ($verification->getStatus() == \Application\Entity\Verification::STATUS_NOGO) {
            $this->_sendNoGoNotification($req->getVerification(), $comment);
        } elseif ($verification->getStatus() == \Application\Entity\Verification::STATUS_GO) {
            $this->_sendGoNotification($req->getVerification(), $comment);
            $nbVersion = $verification->getNbVersionPluginVersion()->getNbVersion();
            $nbVersion->requestCatalogRebuild();
            $this->_nbVersionRepository->persist($nbVersion);
        }
        $this->flashMessenger()->setNamespace('success')->addMessage('Vote cast');
        return $this->redirect()->toRoute('verification', array(
            'action' => 'list'
        ));
    }