kekrozsak/src/KekRozsak/FrontBundle/Controller/DefaultController.php

96 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace KekRozsak\FrontBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
2012-07-15 12:56:31 +00:00
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use KekRozsak\FrontBundle\Entity\UserGroupMembership;
2012-07-15 12:56:31 +00:00
use KekRozsak\FrontBundle\Entity\UserData;
2012-07-15 12:56:31 +00:00
use KekRozsak\SecurityBundle\Form\Type\UserType;
2012-07-09 15:29:37 +00:00
class DefaultController extends Controller
{
/**
* @Route("/", name="KekRozsakFrontBundle_homepage")
*/
public function homepageAction()
{
2012-07-15 12:56:31 +00:00
$mainPageArticle = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBy(array('mainPage' => true), true, array('createdAt', 'DESC'), 1);
if (!$mainPageArticle)
throw $this->createNotFoundException('A keresett cikk nem létezik!');
return $this->forward('KekRozsakFrontBundle:Default:article', array('articleSlug' => $mainPageArticle->getSlug()));
}
/**
* @Route("/cikk/{articleSlug}", name="KekRozsakFrontBundle_article")
2012-07-15 12:56:31 +00:00
* @Template()
*
* @param string $articleSlug
*/
public function articleAction($articleSlug)
{
$article = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBySlug($articleSlug);
if (!$article)
throw $this->createNotFoundException('A keresett cikk nem létezik!');
2012-07-15 12:56:31 +00:00
return array(
'article' => $article,
);
}
2012-07-09 15:29:37 +00:00
/**
* @Route("/profil", name="KekRozsakFrontBundle_profile_edit")
2012-07-15 12:56:31 +00:00
* @Template("KekRozsakFrontBundle:Default:userprofile.html.twig")
*/
2012-07-09 15:29:37 +00:00
public function profileEditAction()
{
$user = $this->get('security.context')->getToken()->getUser();
2012-07-15 12:56:31 +00:00
$oldPassword = $user->getPassword();
$form = $this->createForm(new UserType(), $user);
2012-07-09 15:29:37 +00:00
$saveSuccess = false;
$request = $this->getRequest();
2012-07-15 12:56:31 +00:00
2012-07-09 15:29:37 +00:00
if ($request->getMethod() == 'POST')
{
$form->bindRequest($request);
if ($form->isValid())
{
if ($user->getPassword() == '')
2012-07-09 15:29:37 +00:00
$user->setPassword($oldPassword);
2012-07-15 12:56:31 +00:00
else
$user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt()));
2012-07-09 15:29:37 +00:00
$em = $this->getDoctrine()->getEntityManager();
$em->persist($user);
$em->flush();
}
}
2012-07-15 12:56:31 +00:00
return array(
2012-07-09 15:29:37 +00:00
'form' => $form->createView(),
'saveSuccess' => $saveSuccess,
2012-07-15 12:56:31 +00:00
);
2012-07-09 15:29:37 +00:00
}
2012-07-17 07:21:33 +00:00
/**
* @Route("/dokumentum/{documentSlug}", name="KekRozsakFrontBundle_documentView")
* @Template()
*/
public function documentViewAction($documentSlug)
{
$docRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Document');
if (!($document = $docRepo->findOneBySlug($documentSlug)))
throw $this->createNotFoundException('A kért dokumentum nem létezik!');
return array(
'document' => $document,
);
}
}