Permalink
Browse files

updated to beta 1 & some improvments

  • Loading branch information...
1 parent 5c3aa8b commit baf8aba7aafa58a7192e354c34aff709eff4ea23 @carlossg00 committed May 18, 2011
View
@@ -0,0 +1,26 @@
+<?php
+
+//src/Application/Jobeet2Bundle/Admin/CategoryAdmin.php
+
+namespace Application\Jobeet2Bundle\Admin;
+
+use Sonata\AdminBundle\Admin\Admin;
+use Sonata\AdminBundle\Form\FormMapper;
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
+use Sonata\AdminBundle\Datagrid\ListMapper;
+
+class CategoryAdmin extends Admin
+{
+ protected $list = array(
+ 'id' => array('identifier' => true),
+ 'name',
+ );
+
+ protected $form = array(
+ 'name',
+ );
+
+ protected $filter = array(
+ 'name',
+ );
+}
View
@@ -0,0 +1,58 @@
+<?php
+
+//src/Application/Jobeet2Bundle/Admin/JobAdmin.php
+
+namespace Application\Jobeet2Bundle\Admin;
+
+use Sonata\AdminBundle\Admin\Admin;
+use Sonata\AdminBundle\Form\FormMapper;
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
+use Sonata\AdminBundle\Datagrid\ListMapper;
+
+class JobAdmin extends Admin
+{
+ protected $list = array(
+ 'company' => array('identifier' => true),
+ 'position',
+ 'location',
+ 'is_activated',
+ 'email',
+ 'category',
+ 'expires_at',
+ '_action' => array(
+ 'actions' => array(
+ 'delete' => array(),
+ 'edit' => array(),
+ )
+ ),
+ );
+
+
+ protected $maxPerPage = 5;
+
+ protected $form = array(
+ 'category',
+ 'type',
+ 'company',
+ 'logo',
+ 'url',
+ 'position',
+ 'location',
+ 'description',
+ 'how_to_apply',
+ 'is_public',
+ 'email',
+ 'is_activated',
+ );
+
+ protected $filter = array(
+ 'category',
+ 'company',
+ 'position',
+ 'description',
+ 'is_activated',
+ 'is_public',
+ 'email',
+// 'expiresAt', #Bundle still without date filters
+ );
+}
@@ -0,0 +1,11 @@
+<?php
+
+//src/Application/Jobeet2Bundle/Controller/JobAdminController.php
+
+namespace Application\Jobeet2Bundle\Controller;
+
+use Sonata\AdminBundle\Controller\CRUDController as Controller;
+
+class CategoryAdminController extends Controller
+{
+}
@@ -0,0 +1,11 @@
+<?php
+
+//src/Application/Jobeet2Bundle/Controller/JobAdminController.php
+
+namespace Application\Jobeet2Bundle\Controller;
+
+use Sonata\AdminBundle\Controller\CRUDController as Controller;
+
+class JobAdminController extends Controller
+{
+}
@@ -5,7 +5,7 @@
use Application\Jobeet2Bundle\Entity\Job;
use Application\Jobeet2Bundle\Entity\User;
use Application\Jobeet2Bundle\Entity\Category;
-use Application\Jobeet2Bundle\Form\JobForm;
+use Application\Jobeet2Bundle\Form\JobType;
use Symfony\Component\DependencyInjection\ContainerAware;
use Doctrine\ORM\EntityRepository;
@@ -23,6 +23,7 @@ class JobController extends ContainerAware
private $repository;
private $router;
private $templating;
+ private $em;
/**
* Post Constructor.
@@ -36,6 +37,8 @@ public function __postConstruct()
$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('jobeet2.object_manager');
+ $this->active_days = $this->container->getParameter('jobeet2.active_days');
}
/**
@@ -64,7 +67,7 @@ public function listAction(Category $category = null, $max = 10)
/**
* Show deatiled job info
- * @param: slug
+ * @param: id
*/
public function showAction($id)
@@ -76,40 +79,116 @@ public function showAction($id)
throw new NotFoundHttpException('The Job does not exist.');
}
return $this->templating->renderResponse('Jobeet2Bundle:Job:show.html.twig',
- array('job'=>$job));
+ array('job'=>$job,
+ 'active_days' => $this->active_days));
}
-
- //TODO Refactor
- public function newAction()
+
+ public function deleteAction($id)
{
- /*return $this->templating->renderResponse('Jobeet2:Job:new.html.twig',
- array('form'=>$form));*/
-
+ $this->container->get('session')->setFlash('notice', 'Your changes were saved!');
+
+ $job = $this->repository->findOneById($id);
+
+ if (!$job) {
+ throw new NotFoundHttpException('The Job does not exist.');
+ }
+
+ $this->em->remove($job);
+ $this->em->flush();
+
+ return new RedirectResponse($this->router->generate('homepage'));
+
+ /*$httpKernel = $this->container->get('http_kernel');
+ return $httpKernel->forward('job.controller:listAction');*/
+
}
+ public function editAction($id = null)
+ {
+ if (isset($id)) {
+ $job = $this->repository->findOneById($id);
- public function deleteAction($id)
+ if (!$job) {
+ throw new NotFoundHttpException('The Job does not exist.');
+ }
+
+ } else {
+ $job = new Job();
+ }
+
+ $form = $this->container->get('form.factory')->create(new JobType($this->em),$job);
+
+ if ($this->request->getMethod() == 'POST') {
+
+ $form->bindRequest($this->request);
+
+ if ($form->isValid()) {
+ $this->em->persist($job);
+ $this->em->flush();
+
+ $httpKernel = $this->container->get('http_kernel');
+ return $httpKernel->forward('job.controller:showAction', array(
+ 'id' => $job->getID()
+ ));
+ }
+ }
+
+ return $this->templating->renderResponse('Jobeet2Bundle:Job:create.html.twig',
+ array('form' => $form->createView(),
+ ));
+ }
+
+ public function publishAction($id)
{
- $em = $this->getEm();
- $job = $em->find("Jobeet2Bundle:Job",$id);
+ $job = $this->repository->findOneById($id);
- if (!$this->job) {
+ if (!$job) {
throw new NotFoundHttpException('The Job does not exist.');
}
- $em->remove($job);
- $em->flush();
+ $job->setIsActivated(true);
+
+ $this->em->persist($job);
+ $this->em->flush();
- return new RedirectResponse($this->router->generate('index'));
+ $this->container->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())
+ ));
}
- public function editAction($id)
+ public function extendAction($id)
{
-
+ $job = $this->repository->findOneById($id);
+
+ if (!$job) {
+ throw new NotFoundHttpException('The Job does not exist.');
+ }
+
+ $str = sprintf('P%sD',$this->active_days);
+ $expirationDate = clone $job->getExpiresAt();
+ $job->setExpiresAt($expirationDate->add(new \DateInterval($str)));
+
+ $this->em->persist($job);
+ $this->em->flush();
+
+ return new RedirectResponse($this->router->generate('show',array('id'=>$job->getID(),
+ 'company' => $job->getCompanySlug(),
+ 'location' => $job->getLocationSlug(),
+ 'position' => $job->getPositionSlug())
+ ));
+
}
}
@@ -45,7 +45,7 @@ public function load($manager)
$job1->setHowToApply("Send your resume to fabien.pontecier [at] sensio.com");
$job1->setIsActivated(true);
$job1->setIsPublic(true);
- $job1->setToken("job_sensio_labs");
+ $job1->set_Token("job_sensio_labs");
$job1->setEmail("job@example.com");
@@ -68,7 +68,7 @@ public function load($manager)
$job2->setHowToApply("Send your resume to fabien.pontecier [at] sensio.com");
$job2->setIsActivated(true);
$job2->setIsPublic(true);
- $job2->setToken("job_extreme_sensi");
+ $job2->set_Token("job_extreme_sensi");
$job2->setEmail("job@example.com");
@@ -104,7 +104,7 @@ public function load($manager)
$jobs[$i]->setHowToApply("Send your resume to lorem.ipsum [at] Company".$i);
$jobs[$i]->setIsActivated(true);
$jobs[$i]->setIsPublic(true);
- $jobs[$i]->setToken("job_".$i);
+ $jobs[$i]->set_Token("job_".$i);
$jobs[$i]->setEmail("job@example.com");
$manager->persist($jobs[$i]);
@@ -44,7 +44,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('model.xml');
$loader->load('orm.xml');
$loader->load('controller.xml');
- $loader->load('form.xml');
+ // $loader->load('form.xml');
}
public function getXsdValidationBasePath()
View
@@ -200,6 +200,16 @@ function getSlug()
{
return $this->slug;
}
+
+ /**
+ * To String
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->name;
+ }
}
@@ -31,7 +31,10 @@ public function getWithJobs()
->innerJoin('c.job','j');
//TODO ActiveJobs
- return $qb->getQuery()->getResult();
+ return $this->_em->getRepository('Jobeet2Bundle:Job')->addActiveJobsQuery($qb)
+ ->getResult();
+
+ //return $qb->getQuery()->getResult();
}
Oops, something went wrong.

0 comments on commit baf8aba

Please sign in to comment.