Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Vendor\AppBundle\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- use Vendor\AppBundle\Chat\ChatRequest;
- use Vendor\AppBundle\Document\CannedMessage;
- use Vendor\AppBundle\Document\Operator;
- use Vendor\AppBundle\Document\Session;
- use Vendor\AppBundle\Document\User;
- use Vendor\AppBundle\Document\Visit;
- use Vendor\AppBundle\Document\Visitor;
- use Vendor\AppBundle\Form\ChatRequestType;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpFoundation\Session\Session as SessionStorage;
- use Swift_Message;
- /**
- * @Route("/", name="app_homepage")
- * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
- * @return \Symfony\Bundle\FrameworkBundle\Controller\Response|\Symfony\Component\HttpFoundation\RedirectResponse
- */
- public function indexAction()
- {
- $visitor = $this->getVisitorByKey();
- $session = new SessionStorage();
- if ($this->getOperator()) {
- throw new NotFoundHttpException('No app found.');
- }
- $appRequest = new appRequest();
- /* @var $form \Symfony\Component\Form\Form */
- $form = $this->createForm(new appRequestType(), $appRequest);
- $response = new Response();
- if ('POST' == $this->getRequest()->getMethod()) {
- $form->bindRequest($this->getRequest());
- $appRequest = $form->getData();
- if ($form->isValid()) {
- $dm = $this->getDocumentManager();
- $visitor->setEmail($appRequest->getEmail());
- $visitor->setName($appRequest->getName());
- $dm->persist($visitor);
- $visit = $this->getVisitByKey($visitor);
- $appSession = Session::create($visit, $appRequest->getQuestion(), Session::STATUS_WAITING);
- $dm->persist($appSession);
- $dm->flush();
- $session->getBag('appsession')->set('appsession', $appSession->getId());
- $this->cacheUserForSession($visitor, $appSession);
- return $this->redirect($this->generateUrl('sglc_app_load', array('id' => $appSession->getId())));
- } else {
- $response->setStatusCode(403);
- }
- }
- return $this->render('VendorAppBundle:app:index.html.twig', array(
- 'visitor' => $visitor,
- 'errorMsg' => $session->getFlashBag()->get('errorMsg', array()),
- 'form' => $form->createView()
- ), $response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement