src/AtechNet/CoreBundle/Entity/AbstractEntity.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping\Column;
  4. use Doctrine\ORM\Mapping\GeneratedValue;
  5. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  6. use Doctrine\ORM\Mapping\Id;
  7. use Doctrine\ORM\Mapping\MappedSuperclass;
  8. use Doctrine\ORM\Mapping\PrePersist;
  9. use Doctrine\ORM\Mapping\PreUpdate;
  10. /**
  11.  * Entity
  12.  *
  13.  * @MappedSuperclass
  14.  * @HasLifecycleCallbacks
  15.  */
  16. abstract class AbstractEntity
  17. {
  18.     /**
  19.      * @Id
  20.      * @Column(name="id", type="integer")
  21.      * @GeneratedValue(strategy="AUTO")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @var \DateTime
  26.      *
  27.      * @Column(name="created", type="datetime", nullable=false)
  28.      */
  29.     private $created;
  30.     /**
  31.      * @var \DateTime
  32.      *
  33.      * @Column(name="updated", type="datetime", nullable=false)
  34.      */
  35.     private $updated;
  36.     public function __construct()
  37.     {
  38.         $this->created = new \DateTime();
  39.         $this->updated = new \DateTime();
  40.     }
  41.     /**
  42.      * Set id
  43.      *
  44.      * @param $id
  45.      * @return int
  46.      */
  47.     public function setId($id)
  48.     {
  49.         $this->id = $id;
  50.     }
  51.     /**
  52.      * Get id
  53.      *
  54.      * @return integer
  55.      */
  56.     public function getId()
  57.     {
  58.         return $this->id;
  59.     }
  60.     /**
  61.      * @param \DateTime $created
  62.      * @return \DateTime
  63.      */
  64.     public function setCreated($created)
  65.     {
  66.         if ($created == null) {
  67.             return $this->created;
  68.         } else {
  69.             $this->created = $created;
  70.         }
  71.     }
  72.     /**
  73.      * @param \DateTime $updated
  74.      */
  75.     public function setUpdated($updated)
  76.     {
  77.         $this->updated = $updated;
  78.     }
  79.     /**
  80.      * @return \DateTime
  81.      */
  82.     public function getCreated()
  83.     {
  84.         return $this->created;
  85.     }
  86.     /**
  87.      * @return \DateTime
  88.      */
  89.     public function getUpdated()
  90.     {
  91.         return $this->updated;
  92.     }
  93.     /**
  94.      * @PrePersist
  95.      * @PreUpdate
  96.      */
  97.     public function setTimestamps()
  98.     {
  99.         if ($this->created === null) {
  100.             $this->created = new \DateTime();
  101.         }
  102.         $this->updated = new \DateTime();
  103.     }
  104. }