public function editAction(Player $me, Team $team) { $response = $this->edit($team, $me, "team"); if ($this->newLeader) { // Redirect to a confirmation form if we are assigning a new leader $url = Service::getGenerator()->generate('team_assign_leader', array('team' => $team->getAlias(), 'player' => $this->newLeader->getAlias())); return new RedirectResponse($url); } return $response; }
public function editAction(Player $me, Match $match) { // TODO: Generating this response is unnecessary $response = $this->edit($match, $me, "match"); if ($this->recalculateNeeded && $match->isOfficial()) { // Redirect to a confirmation form if we are assigning a new leader $url = Service::getGenerator()->generate('match_recalculate', array('match' => $match->getId())); return new RedirectResponse($url); } return $response; }
public function loginAction(Request $request, Player $me) { if ($me->isValid()) { throw new ForbiddenException("You are already logged in!"); } $query = $request->query; $session = $request->getSession(); $token = $query->get("token"); $username = $query->get("username"); if (!$token || !$username) { throw new BadRequestException(); } // Don't check whether IPs match if we're on a development environment $checkIP = !$this->isDebug(); $info = validate_token($token, $username, array(), $checkIP); if (!isset($info)) { throw new ForbiddenException("There was an error processing your login. Please go back and try again."); } $session->set("username", $info['username']); $session->set("groups", $info['groups']); $redirectToProfile = false; if (!Player::playerBZIDExists($info['bzid'])) { // If they're new, redirect to their profile page so they can add some info $player = Player::newPlayer($info['bzid'], $info['username']); $redirectToProfile = true; } else { $player = Player::getFromBZID($info['bzid']); if ($player->isDeleted()) { $player->setStatus('active'); } } $session->set("playerId", $player->getId()); $player->updateLastLogin(); $player->setUsername($info['username']); Visit::enterVisit($player->getId(), $request->getClientIp(), gethostbyaddr($request->getClientIp()), $request->server->get('HTTP_USER_AGENT'), $request->server->get('HTTP_REFERER')); $this->configPromoteAdmin($player); if ($redirectToProfile) { $profile = Service::getGenerator()->generate('profile_show'); return new RedirectResponse($profile); } else { return $this->goBack(); } }
/** * Generates a URL from the given parameters. * @param string $name The name of the route * @param mixed $parameters An array of parameters * @param boolean $absolute Whether to generate an absolute URL * @return string The generated URL */ public static function generate($name, $parameters = array(), $absolute = false) { return Service::getGenerator()->generate($name, $parameters, $absolute); }
/** * {@inheritdoc} */ protected function build($builder) { $notBlank = array('constraints' => new NotBlank()); return $builder->add('Recipients', new AdvancedModelType(array('player', 'team')), array('constraints' => new Count(array('min' => 2, 'minMessage' => 'You need to specify the recipients of your message')), 'multiple' => true, 'include' => $this->editing))->add('Subject', 'text', $notBlank)->add('Message', 'textarea', $notBlank)->add('Send', 'submit')->setAction(\Service::getGenerator()->generate('message_compose')); }
/** * Generate a link for a route related to this object * * @param mixed $identifier A parameter representing the model (e.g an ID or alias) * @param string $action The action to perform * @param bool $absolute Whether to return an absolute URL * @param array $params Extra parameters to pass to the URL generator * * @return string A link */ protected function getLink($identifier, $action, $absolute, $params) { return Service::getGenerator()->generate(static::getRouteName($action), array_merge(array(static::getParamName() => $identifier), $params), $absolute); }
/** * Returns the path to the home page * @return string */ protected function getHomeURL() { return Service::getGenerator()->generate('index'); }
protected function redirectToList($model) { return new RedirectResponse(Service::getGenerator()->generate("index")); }
/** * Get the URL that points to the team's list of matches * * @return string The team's list of matches */ public function getMatchesURL() { return Service::getGenerator()->generate("match_by_team_list", array("team" => $this->getAlias())); }
/** * Get a redirection response to a list of models * * @param ModelInterface $model The model to whose list we should redirect * @return Response */ protected function redirectToList($model) { $route = $model->getRouteName('list'); $url = Service::getGenerator()->generate($route); return new RedirectResponse($url); }
public function leaveAction(Player $me, Group $discussion) { if (!$discussion->isMember($me)) { throw new ForbiddenException("You are not a member of this discussion."); } elseif ($discussion->getCreator()->getId() == $me->getId()) { throw new ForbiddenException("You can't abandon the conversation you started!"); } return $this->showConfirmationForm(function () use($discussion, $me) { $discussion->removeMember($me); $event = new GroupAbandonEvent($discussion, $me); Service::getDispatcher()->dispatch(Events::GROUP_ABANDON, $event); return new RedirectResponse(Service::getGenerator()->generate('message_list')); }, "Are you sure you want to abandon this discussion?", "You will no longer receive messages from this conversation", "Leave"); }
/** * Modify the current page URL * * @param array $parameters An array of parameters to add/modify in the request * @return string The HTML link */ public function __invoke(array $parameters) { $attributes = \Service::getRequest()->attributes; $query = \Service::getRequest()->query; return \Service::getGenerator()->generate($attributes->get('_route'), $parameters + $attributes->get('_route_params') + $query->all()); }
/** * {@inheritDoc} */ protected function build($builder) { return $builder->add('q', 'search')->setAction(\Service::getGenerator()->generate('message_search'))->setMethod('GET'); }
private function setUpTwig() { $cacheDir = $this->isDebug() ? null : $this->getCacheDir() . '/twig'; // Set up the twig templating environment to parse views $loader = new Twig_Loader_Filesystem(__DIR__ . '/../views'); $twig = new Twig_Environment($loader, array('cache' => $cacheDir, 'debug' => $this->isDebug())); // Load the routing extension to twig, which adds functions such as path() $formEngine = new TwigRendererEngine(array('form_layout.html.twig')); $formEngine->setEnvironment($twig); $twig->addExtension(new RoutingExtension(Service::getGenerator())); $twig->addExtension(new FormExtension(new TwigRenderer($formEngine))); $twig->addExtension(new ImagineExtension($this->container->get('liip_imagine.cache.manager'))); $twig->addExtension(new AssetExtension($this->container->get('assets.packages'))); $twig->addExtension(new StopwatchExtension($this->container->get('debug.stopwatch', null))); if ($this->getEnvironment() == 'profile') { $twig->addExtension(new DumpExtension($this->container->get('var_dumper.cloner'))); } $twig->addFunction(LinkToFunction::get()); $twig->addFilter(HumanDateFilter::get()); $twig->addFilter(TruncateFilter::get()); $twig->addFilter(MarkdownFilter::get()); $twig->addFilter(PluralFilter::get()); $twig->addFilter(YesNoFilter::get()); $twig->addTest(ValidTest::get()); $twig->addTest(InvalidTest::get()); if ($this->isDebug()) { $twig->addExtension(new Twig_Extension_Debug()); } Service::setTemplateEngine($twig); }
protected function redirectTo($model) { // Redirect to the server list after creating/editing a role return new RedirectResponse(Service::getGenerator()->generate('admin_landing')); }