. // }}} namespace Plugin\PollPlugin\Controller; use App\Core\DB\DB; use App\Entity\Poll; use App\Entity\PollResponse; use App\Util\Common; use App\Util\Exception\InvalidFormException; use League\Uri\Exception; use Plugin\PollPlugin\Forms\PollResponseForm; use Symfony\Component\HttpFoundation\Request; class RespondPoll { /** * Handle poll response */ public function respondpoll(Request $request, string $id) { $user = Common::ensureLoggedIn(); $poll = Poll::getFromId((int) $id); //var_dump($poll); if ($poll == null) {//|| !$poll->isVisibleTo($user)) { todo throw new Exception(); //?fix } $opts = $poll->getOptionsArr(); //var_dump($opts); $form = PollResponseForm::make($opts); $form->handleRequest($request); if ($form->isSubmitted()) { $data = $form->getData(); $selection = array_values($data)[1]; echo $selection; if (!$poll->isValidSelection($selection)) { throw new InvalidFormException(); } $pollResponse = PollResponse::create(['poll_id' => $poll->getId(), 'gsactor_id' => $user->getId(), 'selection' => $selection]); DB::persist($pollResponse); DB::flush(); //var_dump($pollResponse); } //return ['_template' => 'base.html.twig']; return ['_template' => 'Poll/newpoll.html.twig', 'form' => $form->createView()]; } }