<?php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use App\Entity\Traits\IdTrait;
use App\Entity\Traits\NameTrait;
use App\Entity\Traits\OpenTrait;
/**
*
* @ORM\Entity(repositoryClass="App\Repository\BatchRepository")
*/
class Batch
{
use IdTrait, NameTrait, OpenTrait;
const NAME = '批次';
const TYPE_APPLY = '申报';
const TYPE_TASK_BOOK = '任务书提交';
const TYPE_APPROVAL = '验收';
const TYPE_BUDGET = '经费预算提交';
const TYPES = [
self::TYPE_APPLY,
self::TYPE_APPROVAL,
self::TYPE_TASK_BOOK,
self::TYPE_BUDGET
];
const TYPE_TWIGS = [
self::TYPE_APPLY => 'apply',
self::TYPE_APPROVAL => 'approval',
self::TYPE_TASK_BOOK => 'task_book',
self::TYPE_BUDGET => 'budget'
];
/**
*
* @ORM\Column
* @Assert\Choice(choices=BATCH::TYPES)
*/
protected $type;
/**
* 教师申请截止日期
*
* @ORM\Column(type="date")
*/
protected $applyDeadline;
/**
* 学院推荐截止日期
*
* @ORM\Column(type="date")
*/
protected $collegeDeadline;
/**
*
* @ORM\OneToMany(targetEntity="Notice", mappedBy="batch")
*/
protected $notices;
/**
*
* @ORM\OneToMany(targetEntity="BatchCollegeAttachment", mappedBy="batch")
*/
protected $collegeAttachments;
public function __construct()
{
$this->notices = new ArrayCollection();
$this->collegeAttachments = new ArrayCollection();
}
/**
*
* @return string
*/
public function getType(): ?string
{
return $this->type;
}
/**
*
* @param string $type
*/
public function setType(?string $type)
{
$this->type = $type;
}
public function getApplyDeadline(): ?\DateTime
{
return $this->applyDeadline;
}
public function setApplyDeadline(?\DateTime $applyDeadline)
{
$this->applyDeadline = $applyDeadline;
}
public function getCollegeDeadline(): ?\DateTime
{
return $this->collegeDeadline;
}
public function setCollegeDeadline(?\DateTime $collegeDeadline)
{
$this->collegeDeadline = $collegeDeadline;
}
/**
*
* @return Collection|Notice[]
*/
public function getNotices(): Collection
{
return $this->notices;
}
/**
*
* @return Collection|BatchCollegeAttachment[]
*/
public function getCollegeAttachments(): Collection
{
return $this->collegeAttachments;
}
public function isApplyActive(): bool
{
$today = new \DateTime('today');
return ($this->open <= $today) && ($this->applyDeadline >= $today);
}
public function isCollegeActive(): bool
{
$today = new \DateTime('today');
return ($this->open <= $today) && ($this->collegeDeadline >= $today);
}
}