2012-07-01 08:02:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Controller;
|
|
|
|
|
2012-07-13 10:07:21 +00:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
2012-07-01 08:02:35 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
|
2012-07-09 15:29:37 +00:00
|
|
|
use KekRozsak\FrontBundle\Form\Type\UserType;
|
|
|
|
|
2012-07-01 08:02:35 +00:00
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
2012-07-13 10:07:21 +00:00
|
|
|
/**
|
|
|
|
* @Route("/", name="KekRozsakFrontBundle_homepage")
|
|
|
|
*/
|
2012-07-01 18:29:59 +00:00
|
|
|
public function homepageAction()
|
|
|
|
{
|
2012-07-13 10:07:21 +00:00
|
|
|
$mainPageArticle = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBy(array('mainPage' => 1), true, array('createdAt', 'DESC'), 1);
|
2012-07-01 18:29:59 +00:00
|
|
|
if (!$mainPageArticle)
|
|
|
|
throw $this->createNotFoundException('A keresett cikk nem létezik!');
|
|
|
|
|
|
|
|
return $this->forward('KekRozsakFrontBundle:Default:article', array('articleSlug' => $mainPageArticle->getSlug()));
|
|
|
|
}
|
|
|
|
|
2012-07-13 10:07:21 +00:00
|
|
|
/**
|
|
|
|
* @Route("/cikk/{articleSlug}", name="KekRozsakFrontBundle_article")
|
|
|
|
*/
|
2012-07-01 17:11:31 +00:00
|
|
|
public function articleAction($articleSlug)
|
|
|
|
{
|
|
|
|
$article = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBySlug($articleSlug);
|
|
|
|
|
2012-07-01 18:29:59 +00:00
|
|
|
if (!$article)
|
|
|
|
throw $this->createNotFoundException('A keresett cikk nem létezik!');
|
|
|
|
|
2012-07-01 17:11:31 +00:00
|
|
|
return $this->render('KekRozsakFrontBundle:Default:article.html.twig', array(
|
|
|
|
'article' => $article
|
|
|
|
));
|
|
|
|
}
|
2012-07-09 15:29:37 +00:00
|
|
|
|
2012-07-13 10:07:21 +00:00
|
|
|
/**
|
|
|
|
* @Route("/profil", name="KekRozsakFrontBundle_profile_edit")
|
|
|
|
*/
|
2012-07-09 15:29:37 +00:00
|
|
|
public function profileEditAction()
|
|
|
|
{
|
|
|
|
$user = $this->get('security.context')->getToken()->getUser();
|
|
|
|
$oldPassword = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:User')->findOneById($user->getId())->getPassword();
|
|
|
|
$form = $this->createForm(new UserType(), $user);
|
|
|
|
|
|
|
|
$saveSuccess = false;
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->getMethod() == 'POST')
|
|
|
|
{
|
|
|
|
$form->bindRequest($request);
|
|
|
|
if ($form->isValid())
|
|
|
|
{
|
|
|
|
if ($user->getPassword() != '')
|
|
|
|
{
|
|
|
|
$user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$user->setPassword($oldPassword);
|
|
|
|
}
|
|
|
|
if ($user->getUserData()->getUserId() === null)
|
|
|
|
{
|
|
|
|
$user->getUserData()->setUser($user);
|
|
|
|
}
|
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->persist($user);
|
|
|
|
$em->flush();
|
|
|
|
// $saveSuccess = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('KekRozsakFrontBundle:Default:userprofile.html.twig', array(
|
|
|
|
'form' => $form->createView(),
|
|
|
|
'saveSuccess' => $saveSuccess,
|
|
|
|
));
|
|
|
|
}
|
2012-07-01 08:02:35 +00:00
|
|
|
}
|