src/Entity/Batch.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Validator\Constraints as Assert;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use App\Entity\Traits\IdTrait;
  8. use App\Entity\Traits\NameTrait;
  9. use App\Entity\Traits\OpenTrait;
  10. /**
  11.  *
  12.  * @ORM\Entity(repositoryClass="App\Repository\BatchRepository")
  13.  */
  14. class Batch
  15. {
  16.     use IdTraitNameTraitOpenTrait;
  17.     const NAME '批次';
  18.     const TYPE_APPLY '申报';
  19.     const TYPE_TASK_BOOK '任务书提交';
  20.     const TYPE_APPROVAL '验收';
  21.     const TYPE_BUDGET '经费预算提交';
  22.     const TYPES = [
  23.         self::TYPE_APPLY,
  24.         self::TYPE_APPROVAL,
  25.         self::TYPE_TASK_BOOK,
  26.         self::TYPE_BUDGET
  27.     ];
  28.     const TYPE_TWIGS = [
  29.         self::TYPE_APPLY => 'apply',
  30.         self::TYPE_APPROVAL => 'approval',
  31.         self::TYPE_TASK_BOOK => 'task_book',
  32.         self::TYPE_BUDGET => 'budget'
  33.     ];
  34.     /**
  35.      *
  36.      * @ORM\Column
  37.      * @Assert\Choice(choices=BATCH::TYPES)
  38.      */
  39.     protected $type;
  40.     /**
  41.      * 教师申请截止日期
  42.      *
  43.      * @ORM\Column(type="date")
  44.      */
  45.     protected $applyDeadline;
  46.     /**
  47.      * 学院推荐截止日期
  48.      *
  49.      * @ORM\Column(type="date")
  50.      */
  51.     protected $collegeDeadline;
  52.     /**
  53.      *
  54.      * @ORM\OneToMany(targetEntity="Notice", mappedBy="batch")
  55.      */
  56.     protected $notices;
  57.     /**
  58.      *
  59.      * @ORM\OneToMany(targetEntity="BatchCollegeAttachment", mappedBy="batch")
  60.      */
  61.     protected $collegeAttachments;
  62.     public function __construct()
  63.     {
  64.         $this->notices = new ArrayCollection();
  65.         $this->collegeAttachments = new ArrayCollection();
  66.     }
  67.     /**
  68.      *
  69.      * @return string
  70.      */
  71.     public function getType(): ?string
  72.     {
  73.         return $this->type;
  74.     }
  75.     /**
  76.      *
  77.      * @param string $type
  78.      */
  79.     public function setType(?string $type)
  80.     {
  81.         $this->type $type;
  82.     }
  83.     public function getApplyDeadline(): ?\DateTime
  84.     {
  85.         return $this->applyDeadline;
  86.     }
  87.     public function setApplyDeadline(?\DateTime $applyDeadline)
  88.     {
  89.         $this->applyDeadline $applyDeadline;
  90.     }
  91.     public function getCollegeDeadline(): ?\DateTime
  92.     {
  93.         return $this->collegeDeadline;
  94.     }
  95.     public function setCollegeDeadline(?\DateTime $collegeDeadline)
  96.     {
  97.         $this->collegeDeadline $collegeDeadline;
  98.     }
  99.     /**
  100.      *
  101.      * @return Collection|Notice[]
  102.      */
  103.     public function getNotices(): Collection
  104.     {
  105.         return $this->notices;
  106.     }
  107.     /**
  108.      *
  109.      * @return Collection|BatchCollegeAttachment[]
  110.      */
  111.     public function getCollegeAttachments(): Collection
  112.     {
  113.         return $this->collegeAttachments;
  114.     }
  115.     public function isApplyActive(): bool
  116.     {
  117.         $today = new \DateTime('today');
  118.         return ($this->open <= $today) && ($this->applyDeadline >= $today);
  119.     }
  120.     public function isCollegeActive(): bool
  121.     {
  122.         $today = new \DateTime('today');
  123.         return ($this->open <= $today) && ($this->collegeDeadline >= $today);
  124.     }
  125. }