public function newAction() { $request = $this->get('request'); $form = $this->get('lichess.form.manager')->createHookForm(); if ($request->getMethod() === 'POST') { $form->bindRequest($request); if ($form->isValid()) { $config = $form->getData(); $hook = new Hook(); $hook->fromArray($config->toArray()); if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { $hook->setUser($this->get('security.context')->getToken()->getUser()); } $this->get('lichess.config.persistence')->saveConfigFor('hook', $config->toArray()); $this->get('doctrine.odm.mongodb.document_manager')->persist($hook); $this->get('doctrine.odm.mongodb.document_manager')->flush(); $this->get('lila')->lobbyCreate($hook->getOwnerId()); return new RedirectResponse($this->generateUrl('lichess_hook', array('id' => $hook->getOwnerId()))); } else { return new RedirectResponse($this->generateUrl('lichess_homepage')); } } elseif (!$request->isXmlHttpRequest() && $this->container->getParameter('kernel.environment') !== 'test') { return new RedirectResponse($this->generateUrl('lichess_homepage') . '#hook'); } $response = $this->get('lichess.provider')->uncachableResponse(); return $this->render('LichessOpeningBundle:Config:hook.html.twig', array('form' => $form->createView(), 'config' => $form->getData()), $response); }
public function expandHook(Hook $hook) { return sprintf('hook(%s,%s,%s,%s)', $hook->getOwnerId(), $hook->getUsername(), $hook->getVariant(), $hook->getMode() ? 'rated' : 'casual'); }
public function isAlive(Hook $hook) { return (bool) apc_fetch($this->getHookKey($hook->getOwnerId())); }