<?php
namespace App\Entity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use App\Entity\Traits\IdTrait;
use App\Entity\Traits\NameTrait;
use App\Entity\Traits\CategoryTrait;
use App\Entity\Traits\SubjectTrait;
use App\Entity\Traits\CollegeTrait;
use App\Entity\Traits\UserTrait;
use App\Entity\Traits\LevelTrait;
use App\Entity\Traits\NumberMethodTrait;
use App\Entity\Traits\YearTrait;
use App\Entity\Traits\PropertyTrait;
use App\Entity\Traits\UpdatedAtTrait;
use App\Util\DownloadUtil;
use App\Entity\Traits\GetColumnValueTrait;
use App\Entity\Traits\BatchTrait;
/*
* * @UniqueEntity(
* fields={"batch", "user", "category"},
* errorPath="category",
* / * message="每种类型项目只能申请一个"
* )
*/
/**
*
* @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
* @Vich\Uploadable
*
* @author wendell.zheng <wxzheng@ustc.edu.cn>
*/
class Project
{
use IdTrait, NameTrait, NumberMethodTrait, BatchTrait, UserTrait,SubjectTrait, CollegeTrait, CategoryTrait, LevelTrait;
use YearTrait, PropertyTrait, UpdatedAtTrait, GetColumnValueTrait;
const NAME = '项目';
const STATUS_NEW = '新申请';
const STATUS_COLLEGE_RECOMMEND = '学院已推荐';
const STATUS_COLLEGE_REJECT = '学院不推荐';
const STATUS_SCHOOL_RECOMMEND = '学校已推荐';
const STATUS_SCHOOL_REJECT = '学校不推荐';
const STATUS_APPROVAL = '已立项';
const STATUSES = [
self::STATUS_NEW,
self::STATUS_COLLEGE_RECOMMEND,
self::STATUS_COLLEGE_REJECT,
self::STATUS_SCHOOL_RECOMMEND,
self::STATUS_SCHOOL_REJECT,
self::STATUS_APPROVAL
];
const PROPERTIES = [
'name' => '项目名称',
'category' => '项目类别',
'level' => '子类别',
'user' => '申请人姓名',
'getUserTitle' => '申请人职称',
// 'schoolProjectNumber' => '校级项目编号',
'college' => '所在单位',
'status' => '状态',
'collegeSort' => '学院推荐排序'
];
const ACTIONS = [
'doc' => '申请书',
'attachments' => '附件',
'action' => '操作'
];
const COLUMNS = self::PROPERTIES + self::ACTIONS;
const COLLEGE_PROPERTIES = [
'name' => '项目名称',
'category' => '项目类别',
'level' => '子类别',
'user' => '申请人姓名',
'getUserTitle' => '申请人职称',
// 'schoolProjectNumber' => '校级项目编号',
'status' => '状态',
'collegeSort' => '学院推荐排序'
];
const COLLEGE_ACTIONS = [
'doc' => '申请书',
// 'collegeDoc' => '学院推荐申请书',
'attachments' => '附件',
'action' => '操作'
];
const COLLEGE_COLUMNS = self::COLLEGE_PROPERTIES + self::COLLEGE_ACTIONS;
public static function getStatuses(): array
{
return self::STATUSES;
}
/**
*
* @ORM\Column(nullable=true)
*/
protected $number;
/**
* 校级项目编号
*
* @ORM\Column(nullable=true)
*/
protected $schoolProjectNumber;
/**
*
* @ORM\Column
* @Assert\Choice(callback="getStatuses")
*/
protected $status = self::STATUS_NEW;
/**
*
* @ORM\Column(type="integer")
*/
protected $collegeSort = 0;
/**
*
* @ORM\Column(type="integer")
*/
protected $schoolSort = 0;
/**
*
* @Assert\File(maxSize="200M")
* @Vich\UploadableField(mapping="attachment", fileNameProperty="docName")
*/
protected $doc;
/**
*
* @ORM\Column(nullable=true)
*
*/
protected $docName;
/**
*
* @Assert\File(maxSize="200M")
* @Vich\UploadableField(mapping="attachment", fileNameProperty="collegeDocName")
*/
protected $collegeDoc;
/**
*
* @ORM\Column(nullable=true)
*
*/
protected $collegeDocName;
/**
*
* @ORM\OneToMany(targetEntity="ProjectAttachment", mappedBy="project")
*/
protected $attachments;
public function __construct()
{
$this->attachments = new ArrayCollection();
}
/**
*
* @return integer
*/
public function getCollegeSort()
{
return $this->collegeSort;
}
/**
*
* @param integer $collegeSort
*/
public function setCollegeSort($collegeSort)
{
$this->collegeSort = $collegeSort;
}
/**
*
* @return number
*/
public function getSchoolSort()
{
return $this->schoolSort;
}
/**
*
* @param number $schoolSort
*/
public function setSchoolSort($schoolSort)
{
$this->schoolSort = $schoolSort;
}
public function getSchoolProjectNumber()
{
return $this->schoolProjectNumber;
}
public function setSchoolProjectNumber($schoolProjectNumber)
{
$this->schoolProjectNumber = $schoolProjectNumber;
}
/**
*
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
*
* @param string $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $doc
*/
public function setDoc(?File $doc = null): void
{
$this->doc = $doc;
if (null !== $doc) {
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getDoc(): ?File
{
return $this->doc;
}
/**
*
* @return string
*/
public function getDocName()
{
return $this->docName;
}
/**
*
* @param string $docName
*/
public function setDocName($docName)
{
$this->docName = $docName;
}
/**
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $collegeDoc
*/
public function setCollegeDoc(?File $collegeDoc = null): void
{
$this->collegeDoc = $collegeDoc;
if (null !== $collegeDoc) {
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getCollegeDoc(): ?File
{
return $this->collegeDoc;
}
/**
*
* @return string
*/
public function getCollegeDocName()
{
return $this->collegeDocName;
}
/**
*
* @param string $collegeDocName
*/
public function setCollegeDocName($collegeDocName)
{
$this->collegeDocName = $collegeDocName;
}
/**
*
* @return Collection|ProjectAttachment[]
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function getCollegeName(): string
{
return $this->college ?: '--';
}
public function getCategoryName(): string
{
return $this->category ?: '--';
}
public function getLevelName(): string
{
return $this->level ?: '--';
}
public function getPropertyName(): string
{
return $this->property ?: '--';
}
public function getSubjectName(): string
{
return $this->subject ?: '--';
}
public function getYearName(): string
{
return $this->year ?: '--';
}
public function getUserNumber(): string
{
return $this->user->getUsername();
}
public function getUserName(): string
{
return $this->user->getName();
}
public function getUserTitle(): string
{
return $this->user->getUserInfo()
->getTitle()
->getName();
}
public function getUserGender(): string
{
return $this->user->getUserInfo()->getGender();
}
public function getUserMajor(): string
{
return $this->user->getUserInfo()->getMajor();
}
public function getUserQualification(): string
{
return $this->user->getUserInfo()->getQualification();
}
public function getUserDegree(): string
{
return $this->user->getUserInfo()->getDegree();
}
public function getUserIdNumber(): string
{
return $this->user->getUserInfo()->getNumber();
}
public function getUserPhone(): string
{
return $this->user->getUserInfo()->getPhone();
}
public function getUserMobile(): string
{
return $this->user->getUserInfo()->getMobile();
}
public function getUserEmail(): string
{
return $this->user->getUserInfo()->getEmail();
}
public function getUserAddress(): string
{
return $this->user->getUserInfo()->getAddress();
}
public function isNew(): bool
{
return $this->status == self::STATUS_NEW;
}
public function isCollegeRecommend(): bool
{
return $this->status == self::STATUS_COLLEGE_RECOMMEND;
}
public function getDocDownloadName(): string
{
return DownloadUtil::getDownalodName($this->docName, $this->name);
}
public function getCollegeDocDownloadName(): string
{
return DownloadUtil::getDownalodName($this->collegeDocName, $this->name . "_学院推荐.");
}
public function getExportName(array $nameColumns): string
{
$data = [];
foreach ($nameColumns as $column) {
if ($column[0] == '-') {
$data[] = ltrim($column, '-');
} else {
$data[] = $this->getColumnValue($column);
}
}
$rel = implode('_', $data);
return str_replace('/', '_', $rel);
}
}