Commits

Vasiliy Toporov committed 216e287

Proper expires_at value for Jobs.

Comments (0)

Files changed (11)

src/Ens/JobeetBundle/Controller/JobController.php

      *
      */
     public function indexAction()
-    {
-        $em = $this->getDoctrine()->getManager();
-
-        $entities = $em->getRepository('EnsJobeetBundle:Job')->findAll();
+    {        
+        $em = $this->getDoctrine()->getEntityManager();
+ 
+        $query = $em->createQuery(
+          'SELECT j FROM EnsJobeetBundle:Job j WHERE j.expires_at > :date'
+        )->setParameter('date', date('Y-m-d H:i:s', time() - 86400 * 30));
+        $entities = $query->getResult();
 
         return $this->render('EnsJobeetBundle:Job:index.html.twig', array(
-            'entities' => $entities,
+          'entities' => $entities
         ));
     }
 

src/Ens/JobeetBundle/DataFixtures/ORM/LoadJobData.php

     $job_extreme_sensio->setToken('job_extreme_sensio');
     $job_extreme_sensio->setEmail('job@example.com');
     $job_extreme_sensio->setExpiresAt(new \DateTime('2012-10-10'));
+    
+    $job_expired = new Job();
+    $job_expired->setCategory($em->merge($this->getReference('category-programming')));
+    $job_expired->setType('full-time');
+    $job_expired->setCompany('Sensio Labs');
+    $job_expired->setLogo('sensio-labs.gif');
+    $job_expired->setUrl('http://www.sensiolabs.com/');
+    $job_expired->setPosition('Web Developer Expired');
+    $job_expired->setLocation('Paris, France');
+    $job_expired->setDescription('Lorem ipsum dolor sit amet, consectetur adipisicing elit.');
+    $job_expired->setHowToApply('Send your resume to lorem.ipsum [at] dolor.sit');
+    $job_expired->setIsPublic(true);
+    $job_expired->setIsActivated(true);
+    $job_expired->setToken('job_expired');
+    $job_expired->setEmail('job@example.com');
+    $job_expired->setCreatedAt(new \DateTime('2005-12-01'));
  
     $em->persist($job_sensio_labs);
     $em->persist($job_extreme_sensio);
+    $em->persist($job_expired);
  
     $em->flush();
   }

src/Ens/JobeetBundle/Entity/Affiliate.php

     {
         $this->created_at = new \DateTime();
     }
-}
+}

src/Ens/JobeetBundle/Entity/Affiliate.php~

+<?php
+
+namespace Ens\JobeetBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Ens\JobeetBundle\Entity\Affiliate
+ */
+class Affiliate
+{
+    /**
+     * @var integer $id
+     */
+    private $id;
+
+    /**
+     * @var string $url
+     */
+    private $url;
+
+    /**
+     * @var string $email
+     */
+    private $email;
+
+    /**
+     * @var string $token
+     */
+    private $token;
+
+    /**
+     * @var \DateTime $created_at
+     */
+    private $created_at;
+
+    /**
+     * @var \Doctrine\Common\Collections\ArrayCollection
+     */
+    private $category_affiliates;
+
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        $this->category_affiliates = new \Doctrine\Common\Collections\ArrayCollection();
+    }
+    
+    /**
+     * Get id
+     *
+     * @return integer 
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set url
+     *
+     * @param string $url
+     * @return Affiliate
+     */
+    public function setUrl($url)
+    {
+        $this->url = $url;
+    
+        return $this;
+    }
+
+    /**
+     * Get url
+     *
+     * @return string 
+     */
+    public function getUrl()
+    {
+        return $this->url;
+    }
+
+    /**
+     * Set email
+     *
+     * @param string $email
+     * @return Affiliate
+     */
+    public function setEmail($email)
+    {
+        $this->email = $email;
+    
+        return $this;
+    }
+
+    /**
+     * Get email
+     *
+     * @return string 
+     */
+    public function getEmail()
+    {
+        return $this->email;
+    }
+
+    /**
+     * Set token
+     *
+     * @param string $token
+     * @return Affiliate
+     */
+    public function setToken($token)
+    {
+        $this->token = $token;
+    
+        return $this;
+    }
+
+    /**
+     * Get token
+     *
+     * @return string 
+     */
+    public function getToken()
+    {
+        return $this->token;
+    }
+
+    /**
+     * Set created_at
+     *
+     * @param \DateTime $createdAt
+     * @return Affiliate
+     */
+    public function setCreatedAt($createdAt)
+    {
+        $this->created_at = $createdAt;
+    
+        return $this;
+    }
+
+    /**
+     * Get created_at
+     *
+     * @return \DateTime 
+     */
+    public function getCreatedAt()
+    {
+        return $this->created_at;
+    }
+
+    /**
+     * Add category_affiliates
+     *
+     * @param Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates
+     * @return Affiliate
+     */
+    public function addCategoryAffiliate(\Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates)
+    {
+        $this->category_affiliates[] = $categoryAffiliates;
+    
+        return $this;
+    }
+
+    /**
+     * Remove category_affiliates
+     *
+     * @param Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates
+     */
+    public function removeCategoryAffiliate(\Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates)
+    {
+        $this->category_affiliates->removeElement($categoryAffiliates);
+    }
+
+    /**
+     * Get category_affiliates
+     *
+     * @return Doctrine\Common\Collections\Collection 
+     */
+    public function getCategoryAffiliates()
+    {
+        return $this->category_affiliates;
+    }
+    /**
+     * @ORM\PrePersist
+     */
+    public function setCreatedAtValue()
+    {
+        $this->created_at = new \DateTime();
+    }
+}

src/Ens/JobeetBundle/Entity/Category.php

     {
         return $this->getName();
     }
-}
+}

src/Ens/JobeetBundle/Entity/Category.php~

+<?php
+
+namespace Ens\JobeetBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Ens\JobeetBundle\Entity\Category
+ */
+class Category
+{
+    /**
+     * @var integer $id
+     */
+    private $id;
+
+    /**
+     * @var string $name
+     */
+    private $name;
+
+    /**
+     * @var \Doctrine\Common\Collections\ArrayCollection
+     */
+    private $jobs;
+
+    /**
+     * @var \Doctrine\Common\Collections\ArrayCollection
+     */
+    private $category_affiliates;
+
+    /**
+     * Constructor
+     */
+    public function __construct()
+    {
+        $this->jobs = new \Doctrine\Common\Collections\ArrayCollection();
+        $this->category_affiliates = new \Doctrine\Common\Collections\ArrayCollection();
+    }
+    
+    /**
+     * Get id
+     *
+     * @return integer 
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set name
+     *
+     * @param string $name
+     * @return Category
+     */
+    public function setName($name)
+    {
+        $this->name = $name;
+    
+        return $this;
+    }
+
+    /**
+     * Get name
+     *
+     * @return string 
+     */
+    public function getName()
+    {
+        return $this->name;
+    }
+
+    /**
+     * Add jobs
+     *
+     * @param Ens\JobeetBundle\Entity\Job $jobs
+     * @return Category
+     */
+    public function addJob(\Ens\JobeetBundle\Entity\Job $jobs)
+    {
+        $this->jobs[] = $jobs;
+    
+        return $this;
+    }
+
+    /**
+     * Remove jobs
+     *
+     * @param Ens\JobeetBundle\Entity\Job $jobs
+     */
+    public function removeJob(\Ens\JobeetBundle\Entity\Job $jobs)
+    {
+        $this->jobs->removeElement($jobs);
+    }
+
+    /**
+     * Get jobs
+     *
+     * @return Doctrine\Common\Collections\Collection 
+     */
+    public function getJobs()
+    {
+        return $this->jobs;
+    }
+
+    /**
+     * Add category_affiliates
+     *
+     * @param Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates
+     * @return Category
+     */
+    public function addCategoryAffiliate(\Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates)
+    {
+        $this->category_affiliates[] = $categoryAffiliates;
+    
+        return $this;
+    }
+
+    /**
+     * Remove category_affiliates
+     *
+     * @param Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates
+     */
+    public function removeCategoryAffiliate(\Ens\JobeetBundle\Entity\CategoryAffiliate $categoryAffiliates)
+    {
+        $this->category_affiliates->removeElement($categoryAffiliates);
+    }
+
+    /**
+     * Get category_affiliates
+     *
+     * @return Doctrine\Common\Collections\Collection 
+     */
+    public function getCategoryAffiliates()
+    {
+        return $this->category_affiliates;
+    }
+    
+    public function __toString()
+    {
+        return $this->getName();
+    }
+}

src/Ens/JobeetBundle/Entity/CategoryAffiliate.php

     {
         return $this->affiliate;
     }
-}
+}

src/Ens/JobeetBundle/Entity/CategoryAffiliate.php~

+<?php
+
+namespace Ens\JobeetBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Ens\JobeetBundle\Entity\CategoryAffiliate
+ */
+class CategoryAffiliate
+{
+    /**
+     * @var integer $id
+     */
+    private $id;
+
+    /**
+     * @var Ens\JobeetBundle\Entity\Category
+     */
+    private $category;
+
+    /**
+     * @var Ens\JobeetBundle\Entity\Affiliate
+     */
+    private $affiliate;
+
+
+    /**
+     * Get id
+     *
+     * @return integer 
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set category
+     *
+     * @param Ens\JobeetBundle\Entity\Category $category
+     * @return CategoryAffiliate
+     */
+    public function setCategory(\Ens\JobeetBundle\Entity\Category $category = null)
+    {
+        $this->category = $category;
+    
+        return $this;
+    }
+
+    /**
+     * Get category
+     *
+     * @return Ens\JobeetBundle\Entity\Category 
+     */
+    public function getCategory()
+    {
+        return $this->category;
+    }
+
+    /**
+     * Set affiliate
+     *
+     * @param Ens\JobeetBundle\Entity\Affiliate $affiliate
+     * @return CategoryAffiliate
+     */
+    public function setAffiliate(\Ens\JobeetBundle\Entity\Affiliate $affiliate = null)
+    {
+        $this->affiliate = $affiliate;
+    
+        return $this;
+    }
+
+    /**
+     * Get affiliate
+     *
+     * @return Ens\JobeetBundle\Entity\Affiliate 
+     */
+    public function getAffiliate()
+    {
+        return $this->affiliate;
+    }
+}

src/Ens/JobeetBundle/Entity/Job.php

     {
         return Jobeet::slugify($this->getLocation());
     }
-}
+
+    /**
+     * @ORM\PrePersist
+     */
+    public function setExpiresAtValue()
+    {
+        if(!$this->getExpiresAt())
+        {
+            $now = $this->getCreatedAt() ? $this->getCreatedAt()->format('U') : time();
+            $this->expires_at = new \DateTime(date('Y-m-d H:i:s', $now + 86400 * 30));
+        }
+    }
+}

src/Ens/JobeetBundle/Entity/Job.php~

+<?php
+
+namespace Ens\JobeetBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use Ens\JobeetBundle\Utils\Jobeet as Jobeet;
+
+/**
+ * Ens\JobeetBundle\Entity\Job
+ */
+class Job
+{
+    /**
+     * @var integer $id
+     */
+    private $id;
+
+    /**
+     * @var string $type
+     */
+    private $type;
+
+    /**
+     * @var string $company
+     */
+    private $company;
+
+    /**
+     * @var string $logo
+     */
+    private $logo;
+
+    /**
+     * @var string $url
+     */
+    private $url;
+
+    /**
+     * @var string $position
+     */
+    private $position;
+
+    /**
+     * @var string $location
+     */
+    private $location;
+
+    /**
+     * @var string $description
+     */
+    private $description;
+
+    /**
+     * @var string $how_to_apply
+     */
+    private $how_to_apply;
+
+    /**
+     * @var string $token
+     */
+    private $token;
+
+    /**
+     * @var boolean $is_public
+     */
+    private $is_public;
+
+    /**
+     * @var boolean $is_activated
+     */
+    private $is_activated;
+
+    /**
+     * @var string $email
+     */
+    private $email;
+
+    /**
+     * @var \DateTime $expires_at
+     */
+    private $expires_at;
+
+    /**
+     * @var \DateTime $created_at
+     */
+    private $created_at;
+
+    /**
+     * @var \DateTime $updated_at
+     */
+    private $updated_at;
+
+    /**
+     * @var Ens\JobeetBundle\Entity\Category
+     */
+    private $category;
+
+
+    /**
+     * Get id
+     *
+     * @return integer 
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * Set type
+     *
+     * @param string $type
+     * @return Job
+     */
+    public function setType($type)
+    {
+        $this->type = $type;
+    
+        return $this;
+    }
+
+    /**
+     * Get type
+     *
+     * @return string 
+     */
+    public function getType()
+    {
+        return $this->type;
+    }
+
+    /**
+     * Set company
+     *
+     * @param string $company
+     * @return Job
+     */
+    public function setCompany($company)
+    {
+        $this->company = $company;
+    
+        return $this;
+    }
+
+    /**
+     * Get company
+     *
+     * @return string 
+     */
+    public function getCompany()
+    {
+        return $this->company;
+    }
+
+    /**
+     * Set logo
+     *
+     * @param string $logo
+     * @return Job
+     */
+    public function setLogo($logo)
+    {
+        $this->logo = $logo;
+    
+        return $this;
+    }
+
+    /**
+     * Get logo
+     *
+     * @return string 
+     */
+    public function getLogo()
+    {
+        return $this->logo;
+    }
+
+    /**
+     * Set url
+     *
+     * @param string $url
+     * @return Job
+     */
+    public function setUrl($url)
+    {
+        $this->url = $url;
+    
+        return $this;
+    }
+
+    /**
+     * Get url
+     *
+     * @return string 
+     */
+    public function getUrl()
+    {
+        return $this->url;
+    }
+
+    /**
+     * Set position
+     *
+     * @param string $position
+     * @return Job
+     */
+    public function setPosition($position)
+    {
+        $this->position = $position;
+    
+        return $this;
+    }
+
+    /**
+     * Get position
+     *
+     * @return string 
+     */
+    public function getPosition()
+    {
+        return $this->position;
+    }
+
+    /**
+     * Set location
+     *
+     * @param string $location
+     * @return Job
+     */
+    public function setLocation($location)
+    {
+        $this->location = $location;
+    
+        return $this;
+    }
+
+    /**
+     * Get location
+     *
+     * @return string 
+     */
+    public function getLocation()
+    {
+        return $this->location;
+    }
+
+    /**
+     * Set description
+     *
+     * @param string $description
+     * @return Job
+     */
+    public function setDescription($description)
+    {
+        $this->description = $description;
+    
+        return $this;
+    }
+
+    /**
+     * Get description
+     *
+     * @return string 
+     */
+    public function getDescription()
+    {
+        return $this->description;
+    }
+
+    /**
+     * Set how_to_apply
+     *
+     * @param string $howToApply
+     * @return Job
+     */
+    public function setHowToApply($howToApply)
+    {
+        $this->how_to_apply = $howToApply;
+    
+        return $this;
+    }
+
+    /**
+     * Get how_to_apply
+     *
+     * @return string 
+     */
+    public function getHowToApply()
+    {
+        return $this->how_to_apply;
+    }
+
+    /**
+     * Set token
+     *
+     * @param string $token
+     * @return Job
+     */
+    public function setToken($token)
+    {
+        $this->token = $token;
+    
+        return $this;
+    }
+
+    /**
+     * Get token
+     *
+     * @return string 
+     */
+    public function getToken()
+    {
+        return $this->token;
+    }
+
+    /**
+     * Set is_public
+     *
+     * @param boolean $isPublic
+     * @return Job
+     */
+    public function setIsPublic($isPublic)
+    {
+        $this->is_public = $isPublic;
+    
+        return $this;
+    }
+
+    /**
+     * Get is_public
+     *
+     * @return boolean 
+     */
+    public function getIsPublic()
+    {
+        return $this->is_public;
+    }
+
+    /**
+     * Set is_activated
+     *
+     * @param boolean $isActivated
+     * @return Job
+     */
+    public function setIsActivated($isActivated)
+    {
+        $this->is_activated = $isActivated;
+    
+        return $this;
+    }
+
+    /**
+     * Get is_activated
+     *
+     * @return boolean 
+     */
+    public function getIsActivated()
+    {
+        return $this->is_activated;
+    }
+
+    /**
+     * Set email
+     *
+     * @param string $email
+     * @return Job
+     */
+    public function setEmail($email)
+    {
+        $this->email = $email;
+    
+        return $this;
+    }
+
+    /**
+     * Get email
+     *
+     * @return string 
+     */
+    public function getEmail()
+    {
+        return $this->email;
+    }
+
+    /**
+     * Set expires_at
+     *
+     * @param \DateTime $expiresAt
+     * @return Job
+     */
+    public function setExpiresAt($expiresAt)
+    {
+        $this->expires_at = $expiresAt;
+    
+        return $this;
+    }
+
+    /**
+     * Get expires_at
+     *
+     * @return \DateTime 
+     */
+    public function getExpiresAt()
+    {
+        return $this->expires_at;
+    }
+
+    /**
+     * Set created_at
+     *
+     * @param \DateTime $createdAt
+     * @return Job
+     */
+    public function setCreatedAt($createdAt)
+    {
+        $this->created_at = $createdAt;
+    
+        return $this;
+    }
+
+    /**
+     * Get created_at
+     *
+     * @return \DateTime 
+     */
+    public function getCreatedAt()
+    {
+        return $this->created_at;
+    }
+
+    /**
+     * Set updated_at
+     *
+     * @param \DateTime $updatedAt
+     * @return Job
+     */
+    public function setUpdatedAt($updatedAt)
+    {
+        $this->updated_at = $updatedAt;
+    
+        return $this;
+    }
+
+    /**
+     * Get updated_at
+     *
+     * @return \DateTime 
+     */
+    public function getUpdatedAt()
+    {
+        return $this->updated_at;
+    }
+
+    /**
+     * Set category
+     *
+     * @param Ens\JobeetBundle\Entity\Category $category
+     * @return Job
+     */
+    public function setCategory(\Ens\JobeetBundle\Entity\Category $category = null)
+    {
+        $this->category = $category;
+    
+        return $this;
+    }
+
+    /**
+     * Get category
+     *
+     * @return Ens\JobeetBundle\Entity\Category 
+     */
+    public function getCategory()
+    {
+        return $this->category;
+    }
+    /**
+     * @ORM\PrePersist
+     */
+    public function setCreatedAtValue()
+    {
+        if(!$this->getCreatedAt())
+        {
+            $this->created_at = new \DateTime();
+        }
+    }
+
+    /**
+     * @ORM\PreUpdate
+     */
+    public function setUpdatedAtValue()
+    {
+        $this->updated_at = new \DateTime();
+    }
+    
+    public function getCompanySlug()
+    {
+        return Jobeet::slugify($this->getCompany());
+    }
+ 
+    public function getPositionSlug()
+    {
+        return Jobeet::slugify($this->getPosition());
+    }
+ 
+    public function getLocationSlug()
+    {
+        return Jobeet::slugify($this->getLocation());
+    }
+}

src/Ens/JobeetBundle/Resources/config/doctrine/Job.orm.yml

         name: category_id
         referencedColumnName: id
   lifecycleCallbacks:
-    prePersist: [ setCreatedAtValue ]
+    prePersist: [ setCreatedAtValue, setExpiresAtValue ]
     preUpdate: [ setUpdatedAtValue ]