Permalink
Browse files

removed controllers as services

  • Loading branch information...
1 parent e327137 commit ebbe34224d54446c78959ace0ea13ecb31d3b016 @carlossg00 committed Jun 27, 2011
@@ -1,11 +0,0 @@
-<?php
-
-//src/Application/Jobeet2Bundle/Controller/JobAdminController.php
-
-namespace Application\Jobeet2Bundle\Controller;
-
-use Sonata\AdminBundle\Controller\CRUDController as Controller;
-
-class CategoryAdminController extends Controller
-{
-}
@@ -2,68 +2,45 @@
namespace Application\Jobeet2Bundle\Controller;
-use Symfony\Component\DependencyInjection\ContainerAware;
-use Doctrine\ORM\EntityRepository;
-use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-use Symfony\Component\HttpFoundation\Request;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Zend\Paginator\Paginator;
-class CategoryController extends ContainerAware
+
+class CategoryController extends Controller
{
- private $request;
- private $repository;
- private $router;
- private $templating;
- private $max_jobs_on_homepage;
-
- /**
- * Post Constructor.
- * Called from DIC after setContainer method
- * assign values to member variables for better code readability
- */
-
- public function __postConstruct()
- {
- $this->request = $this->container->get('request');
- $this->router = $this->container->get('router');
- $this->repository = $this->container->get('jobeet2.category.repository');
- $this->templating = $this->container->get('templating');
- $this->max_jobs_on_category = $this->container->getParameter('jobeet2.max_jobs_on_category');
- }
/**
- *
- * Show Jobs in category
- * @param string $slug
+ * @Route("/{slug}", name="_category_job_show")
*/
-
+
public function showAction($slug)
{
-
- $category = $this->repository->findOneBySlug($slug);
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Category');
+
+ $category = $repository->findOneBySlug($slug);
if (!$category) {
throw new NotFoundHttpException('The Category does not exist.');
}
- $page = $this->request->query->get('page', 1);
-
+ $page = $this->getRequest()->query->get('page', 1);
- $adapter = $this->container->get('knplabs_paginator.adapter');
+ $adapter = $this->get('knplabs_paginator.adapter');
$adapter->setQuery($this->repository->getActiveJobsByCategoryQuery($category));
$adapter->setDistinct(true);
$jobs = new Paginator($adapter);
$jobs->setCurrentPageNumber($page);
- $jobs->setItemCountPerPage($this->max_jobs_on_category);
+ $jobs->setItemCountPerPage($this->container->getParameter('jobeet2.max_jobs_on_category'));
$jobs->setPageRange(5);
- return $this->templating->renderResponse('Jobeet2Bundle:Category:show.html.twig',
+ return $this->render('Jobeet2Bundle:Category:show.html.twig',
array('category' => $category,
'jobs' => $jobs));
@@ -1,11 +0,0 @@
-<?php
-
-//src/Application/Jobeet2Bundle/Controller/JobAdminController.php
-
-namespace Application\Jobeet2Bundle\Controller;
-
-use Sonata\AdminBundle\Controller\CRUDController as Controller;
-
-class JobAdminController extends Controller
-{
-}
@@ -7,110 +7,121 @@
use Application\Jobeet2Bundle\Entity\Category;
use Application\Jobeet2Bundle\Form\JobType;
-use Symfony\Component\DependencyInjection\ContainerAware;
-use Doctrine\ORM\EntityRepository;
-use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-use Symfony\Component\HttpFoundation\Request;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
-class JobController extends ContainerAware
+
+class JobController extends Controller
{
-
- private $request;
- private $repository;
- private $router;
- private $templating;
- private $em;
-
- /**
- * Post Constructor.
- * Called from DIC after setContainer method
- * assign values to member variables for better code readability
- */
-
- public function __postConstruct()
- {
- $this->request = $this->container->get('request');
- $this->router = $this->container->get('router');
- $this->repository = $this->container->get('jobeet2.job.repository');
- $this->templating = $this->container->get('templating');
- $this->em = $this->container->get('doctrine')->getEntityManager();
- $this->active_days = $this->container->getParameter('jobeet2.active_days');
- }
-
/**
- *
- * List jobs by Category in homepage
- * @param Category $category
- * @param string $context
- * @param integer $page
+ * @Route("/", name="_job_category_list")
*/
public function listAction(Category $category = null, $max = 10)
{
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Job');
if (null !== $category) {
- $jobs = $this->repository->getActiveJobsByCategory($category, $max);
+ $jobs = $repository->getActiveJobsByCategory($category, $max);
} else {
- $jobs = $this->repository->findAll(true);
+ $jobs = $repository->findAll(true);
}
- return $this->templating->renderResponse('Jobeet2Bundle:Job:list.html.twig', array(
+ return $this->render('Jobeet2Bundle:Job:list.html.twig', array(
'jobs' => $jobs,
'category' => $category,
));
}
+
/**
- * Show deatiled job info
- * @param id
+ * @Route("/show/{company}/{location}/{id}/{position}", name="_job_show")
*/
+
public function showAction($id)
{
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Job');
- $job = $this->repository->findOneById($id);
+ $job = $repository->findOneById($id);
if (!$job) {
throw new NotFoundHttpException('The Job does not exist.');
}
- return $this->templating->renderResponse('Jobeet2Bundle:Job:show.html.twig',
+ return $this->render('Jobeet2Bundle:Job:show.html.twig',
array('job'=>$job,
- 'active_days' => $this->active_days));
+ 'active_days' => $this->container->getParameter('jobeet2.active_days')
+ ));
}
+ /**
+ * @Route("/{token}/show", name="_job_show_tokenized")
+ */
+
+ public function showTokenizedAction($token)
+ {
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Job');
+
+ $job = $repository->findOneByToken($token);
+
+ if (!$job) {
+ throw new NotFoundHttpException('The Job does not exist.');
+ }
+ return $this->render('Jobeet2Bundle:Job:show.html.twig',
+ array('job'=>$job,
+ 'active_days' => $this->active_days));
+
+ }
+
+ /**
+ * @Route("/{token}/delete", name="_job_delete")
+ */
- public function deleteAction($id)
+ public function deleteAction($token)
{
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Job');
+
$this->container->get('session')->setFlash('notice', 'Your changes were saved!');
- $job = $this->repository->findOneById($id);
+ $job = $repository->findOneByToken($token);
if (!$job) {
throw new NotFoundHttpException('The Job does not exist.');
}
- $this->em->remove($job);
- $this->em->flush();
+ $em->remove($job);
+ $em->flush();
+
+ return $this->redirect($this->generateUrl('_homepage'));
- return new RedirectResponse($this->router->generate('homepage'));
- /*$httpKernel = $this->container->get('http_kernel');
- return $httpKernel->forward('job.controller:listAction');*/
}
- public function editAction($id = null)
+ /**
+ * @Route("/create", name="_job_create")
+ * @Route("{id}/edit", name="_job_edit")
+ */
+
+
+ public function editAction($token = null)
{
- if (isset($id)) {
- $job = $this->repository->findOneById($id);
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Job');
+
+ if (isset($token)) {
+ $job = $repository->findOneByToken($token);
if (!$job) {
throw new NotFoundHttpException('The Job does not exist.');
@@ -120,58 +131,65 @@ public function editAction($id = null)
$job = new Job();
}
- $form = $this->container->get('form.factory')->create(new JobType($this->em),$job);
+ $form = $this->createForm(new JobType($this->em),$job);
- if ($this->request->getMethod() == 'POST') {
+ if ($this->getRequest()->getMethod() == 'POST') {
- $form->bindRequest($this->request);
+ $form->bindRequest($this->getRequest());
if ($form->isValid()) {
- $this->em->persist($job);
- $this->em->flush();
+ $em->persist($job);
+ $em->flush();
- $httpKernel = $this->container->get('http_kernel');
- return $httpKernel->forward('job.controller:showAction', array(
- 'id' => $job->getID()
- ));
+ return $this->redirect($this->generateUrl('_job_show_tokenized'
+ ,array('token'=>$job->get_Token())
+ ));
}
}
- return $this->templating->renderResponse('Jobeet2Bundle:Job:create.html.twig',
+ return $this->render('Jobeet2Bundle:Job:create.html.twig',
array('form' => $form->createView(),
));
}
- public function publishAction($id)
+ /**
+ * @Route("/{token}/publish", name="_job_publish")
+ */
+
+ public function publishAction($token)
{
- $job = $this->repository->findOneById($id);
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Job');
+
+ $job = $repository->findOneByToken($token);
if (!$job) {
throw new NotFoundHttpException('The Job does not exist.');
}
$job->setIsActivated(true);
- $this->em->persist($job);
- $this->em->flush();
+ $em->persist($job);
+ $em->flush();
- $this->container->get('session')->setFlash('notice', "Your job is now online for $this->active_days days");
+ $this->get('session')->setFlash('notice', "Your job is now online for $this->active_days days");
- $httpKernel = $this->container->get('http_kernel');
- return $httpKernel->forward('job.controller:showAction', array(
- 'id' => $job->getID()
- ));
- return new RedirectResponse($this->router->generate('show',array('id'=>$job->getID(),
- 'company' => $job->getCompanySlug(),
- 'location' => $job->getLocationSlug(),
- 'position' => $job->getPositionSlug())
- ));
+ return $this->redirect($this->generateUrl('_job_show_tokenized'
+ ,array('token'=>$job->get_Token())
+ ));
}
- public function extendAction($id)
+ /**
+ * @Route("/{token}/extend", name="_job_extend")
+ */
+
+ public function extendAction($token)
{
- $job = $this->repository->findOneById($id);
+ $em = $this->get('doctrine')->getEntityManager();
+ $repository = $em->getRepository('Jobeet2Bundle:Job');
+
+ $job = $repository->findOneById($token);
if (!$job) {
throw new NotFoundHttpException('The Job does not exist.');
@@ -181,14 +199,12 @@ public function extendAction($id)
$expirationDate = clone $job->getExpiresAt();
$job->setExpiresAt($expirationDate->add(new \DateInterval($str)));
- $this->em->persist($job);
- $this->em->flush();
+ $em->persist($job);
+ $em->flush();
- return new RedirectResponse($this->router->generate('show',array('id'=>$job->getID(),
- 'company' => $job->getCompanySlug(),
- 'location' => $job->getLocationSlug(),
- 'position' => $job->getPositionSlug())
- ));
+ return $this->redirect($this->generateUrl('_job_show_tokenized'
+ ,array('token'=>$job->get_Token())
+ ));
}
}
Oops, something went wrong.

0 comments on commit ebbe342

Please sign in to comment.