src/Entity/Project.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Symfony\Component\HttpFoundation\File\File;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use App\Entity\Traits\IdTrait;
  11. use App\Entity\Traits\NameTrait;
  12. use App\Entity\Traits\CategoryTrait;
  13. use App\Entity\Traits\SubjectTrait;
  14. use App\Entity\Traits\CollegeTrait;
  15. use App\Entity\Traits\UserTrait;
  16. use App\Entity\Traits\LevelTrait;
  17. use App\Entity\Traits\NumberMethodTrait;
  18. use App\Entity\Traits\YearTrait;
  19. use App\Entity\Traits\PropertyTrait;
  20. use App\Entity\Traits\UpdatedAtTrait;
  21. use App\Util\DownloadUtil;
  22. use App\Entity\Traits\GetColumnValueTrait;
  23. use App\Entity\Traits\BatchTrait;
  24. /*
  25.  * * @UniqueEntity(
  26.  * fields={"batch", "user", "category"},
  27.  * errorPath="category",
  28.  * / * message="每种类型项目只能申请一个"
  29.  * )
  30.  */
  31. /**
  32.  *
  33.  * @ORM\Entity(repositoryClass="App\Repository\ProjectRepository")
  34.  * @Vich\Uploadable
  35.  *
  36.  * @author wendell.zheng <wxzheng@ustc.edu.cn>
  37.  */
  38. class Project
  39. {
  40.     use IdTraitNameTraitNumberMethodTraitBatchTraitUserTrait,SubjectTraitCollegeTraitCategoryTraitLevelTrait;
  41.     use YearTraitPropertyTraitUpdatedAtTraitGetColumnValueTrait;
  42.     const NAME '项目';
  43.     const STATUS_NEW '新申请';
  44.     const STATUS_COLLEGE_RECOMMEND '学院已推荐';
  45.     const STATUS_COLLEGE_REJECT '学院不推荐';
  46.     const STATUS_SCHOOL_RECOMMEND '学校已推荐';
  47.     const STATUS_SCHOOL_REJECT '学校不推荐';
  48.     const STATUS_APPROVAL '已立项';
  49.     const STATUSES = [
  50.         self::STATUS_NEW,
  51.         self::STATUS_COLLEGE_RECOMMEND,
  52.         self::STATUS_COLLEGE_REJECT,
  53.         self::STATUS_SCHOOL_RECOMMEND,
  54.         self::STATUS_SCHOOL_REJECT,
  55.         self::STATUS_APPROVAL
  56.     ];
  57.     const PROPERTIES = [
  58.         'name' => '项目名称',
  59.         'category' => '项目类别',
  60.         'level' => '子类别',
  61.         'user' => '申请人姓名',
  62.         'getUserTitle' => '申请人职称',
  63.         // 'schoolProjectNumber' => '校级项目编号',
  64.         'college' => '所在单位',
  65.         'status' => '状态',
  66.         'collegeSort' => '学院推荐排序'
  67.     ];
  68.     const ACTIONS = [
  69.         'doc' => '申请书',
  70.         'attachments' => '附件',
  71.         'action' => '操作'
  72.     ];
  73.     const COLUMNS self::PROPERTIES self::ACTIONS;
  74.     const COLLEGE_PROPERTIES = [
  75.         'name' => '项目名称',
  76.         'category' => '项目类别',
  77.         'level' => '子类别',
  78.         'user' => '申请人姓名',
  79.         'getUserTitle' => '申请人职称',
  80.         // 'schoolProjectNumber' => '校级项目编号',
  81.         'status' => '状态',
  82.         'collegeSort' => '学院推荐排序'
  83.     ];
  84.     const COLLEGE_ACTIONS = [
  85.         'doc' => '申请书',
  86.         // 'collegeDoc' => '学院推荐申请书',
  87.         'attachments' => '附件',
  88.         'action' => '操作'
  89.     ];
  90.     const COLLEGE_COLUMNS self::COLLEGE_PROPERTIES self::COLLEGE_ACTIONS;
  91.     public static function getStatuses(): array
  92.     {
  93.         return self::STATUSES;
  94.     }
  95.     /**
  96.      *
  97.      * @ORM\Column(nullable=true)
  98.      */
  99.     protected $number;
  100.     /**
  101.      * 校级项目编号
  102.      *
  103.      * @ORM\Column(nullable=true)
  104.      */
  105.     protected $schoolProjectNumber;
  106.     /**
  107.      *
  108.      * @ORM\Column
  109.      * @Assert\Choice(callback="getStatuses")
  110.      */
  111.     protected $status self::STATUS_NEW;
  112.     /**
  113.      *
  114.      * @ORM\Column(type="integer")
  115.      */
  116.     protected $collegeSort 0;
  117.     /**
  118.      *
  119.      * @ORM\Column(type="integer")
  120.      */
  121.     protected $schoolSort 0;
  122.     /**
  123.      *
  124.      * @Assert\File(maxSize="200M")
  125.      * @Vich\UploadableField(mapping="attachment", fileNameProperty="docName")
  126.      */
  127.     protected $doc;
  128.     /**
  129.      *
  130.      * @ORM\Column(nullable=true)
  131.      *
  132.      */
  133.     protected $docName;
  134.     /**
  135.      *
  136.      * @Assert\File(maxSize="200M")
  137.      * @Vich\UploadableField(mapping="attachment", fileNameProperty="collegeDocName")
  138.      */
  139.     protected $collegeDoc;
  140.     /**
  141.      *
  142.      * @ORM\Column(nullable=true)
  143.      *
  144.      */
  145.     protected $collegeDocName;
  146.     /**
  147.      *
  148.      * @ORM\OneToMany(targetEntity="ProjectAttachment", mappedBy="project")
  149.      */
  150.     protected $attachments;
  151.     public function __construct()
  152.     {
  153.         $this->attachments = new ArrayCollection();
  154.     }
  155.     /**
  156.      *
  157.      * @return integer
  158.      */
  159.     public function getCollegeSort()
  160.     {
  161.         return $this->collegeSort;
  162.     }
  163.     /**
  164.      *
  165.      * @param integer $collegeSort
  166.      */
  167.     public function setCollegeSort($collegeSort)
  168.     {
  169.         $this->collegeSort $collegeSort;
  170.     }
  171.     /**
  172.      *
  173.      * @return number
  174.      */
  175.     public function getSchoolSort()
  176.     {
  177.         return $this->schoolSort;
  178.     }
  179.     /**
  180.      *
  181.      * @param number $schoolSort
  182.      */
  183.     public function setSchoolSort($schoolSort)
  184.     {
  185.         $this->schoolSort $schoolSort;
  186.     }
  187.     public function getSchoolProjectNumber()
  188.     {
  189.         return $this->schoolProjectNumber;
  190.     }
  191.     public function setSchoolProjectNumber($schoolProjectNumber)
  192.     {
  193.         $this->schoolProjectNumber $schoolProjectNumber;
  194.     }
  195.     /**
  196.      *
  197.      * @return string
  198.      */
  199.     public function getStatus()
  200.     {
  201.         return $this->status;
  202.     }
  203.     /**
  204.      *
  205.      * @param string $status
  206.      */
  207.     public function setStatus($status)
  208.     {
  209.         $this->status $status;
  210.     }
  211.     /**
  212.      *
  213.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $doc
  214.      */
  215.     public function setDoc(?File $doc null): void
  216.     {
  217.         $this->doc $doc;
  218.         if (null !== $doc) {
  219.             $this->updatedAt = new \DateTimeImmutable();
  220.         }
  221.     }
  222.     public function getDoc(): ?File
  223.     {
  224.         return $this->doc;
  225.     }
  226.     /**
  227.      *
  228.      * @return string
  229.      */
  230.     public function getDocName()
  231.     {
  232.         return $this->docName;
  233.     }
  234.     /**
  235.      *
  236.      * @param string $docName
  237.      */
  238.     public function setDocName($docName)
  239.     {
  240.         $this->docName $docName;
  241.     }
  242.     /**
  243.      *
  244.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $collegeDoc
  245.      */
  246.     public function setCollegeDoc(?File $collegeDoc null): void
  247.     {
  248.         $this->collegeDoc $collegeDoc;
  249.         if (null !== $collegeDoc) {
  250.             $this->updatedAt = new \DateTimeImmutable();
  251.         }
  252.     }
  253.     public function getCollegeDoc(): ?File
  254.     {
  255.         return $this->collegeDoc;
  256.     }
  257.     /**
  258.      *
  259.      * @return string
  260.      */
  261.     public function getCollegeDocName()
  262.     {
  263.         return $this->collegeDocName;
  264.     }
  265.     /**
  266.      *
  267.      * @param string $collegeDocName
  268.      */
  269.     public function setCollegeDocName($collegeDocName)
  270.     {
  271.         $this->collegeDocName $collegeDocName;
  272.     }
  273.     /**
  274.      *
  275.      * @return Collection|ProjectAttachment[]
  276.      */
  277.     public function getAttachments(): Collection
  278.     {
  279.         return $this->attachments;
  280.     }
  281.     public function getCollegeName(): string
  282.     {
  283.         return $this->college ?: '--';
  284.     }
  285.     public function getCategoryName(): string
  286.     {
  287.         return $this->category ?: '--';
  288.     }
  289.     public function getLevelName(): string
  290.     {
  291.         return $this->level ?: '--';
  292.     }
  293.     public function getPropertyName(): string
  294.     {
  295.         return $this->property ?: '--';
  296.     }
  297.     public function getSubjectName(): string
  298.     {
  299.         return $this->subject ?: '--';
  300.     }
  301.     public function getYearName(): string
  302.     {
  303.         return $this->year ?: '--';
  304.     }
  305.     public function getUserNumber(): string
  306.     {
  307.         return $this->user->getUsername();
  308.     }
  309.     public function getUserName(): string
  310.     {
  311.         return $this->user->getName();
  312.     }
  313.     public function getUserTitle(): string
  314.     {
  315.         return $this->user->getUserInfo()
  316.             ->getTitle()
  317.             ->getName();
  318.     }
  319.     public function getUserGender(): string
  320.     {
  321.         return $this->user->getUserInfo()->getGender();
  322.     }
  323.     public function getUserMajor(): string
  324.     {
  325.         return $this->user->getUserInfo()->getMajor();
  326.     }
  327.     public function getUserQualification(): string
  328.     {
  329.         return $this->user->getUserInfo()->getQualification();
  330.     }
  331.     public function getUserDegree(): string
  332.     {
  333.         return $this->user->getUserInfo()->getDegree();
  334.     }
  335.     public function getUserIdNumber(): string
  336.     {
  337.         return $this->user->getUserInfo()->getNumber();
  338.     }
  339.     public function getUserPhone(): string
  340.     {
  341.         return $this->user->getUserInfo()->getPhone();
  342.     }
  343.     public function getUserMobile(): string
  344.     {
  345.         return $this->user->getUserInfo()->getMobile();
  346.     }
  347.     public function getUserEmail(): string
  348.     {
  349.         return $this->user->getUserInfo()->getEmail();
  350.     }
  351.     public function getUserAddress(): string
  352.     {
  353.         return $this->user->getUserInfo()->getAddress();
  354.     }
  355.     public function isNew(): bool
  356.     {
  357.         return $this->status == self::STATUS_NEW;
  358.     }
  359.     public function isCollegeRecommend(): bool
  360.     {
  361.         return $this->status == self::STATUS_COLLEGE_RECOMMEND;
  362.     }
  363.     public function getDocDownloadName(): string
  364.     {
  365.         return DownloadUtil::getDownalodName($this->docName$this->name);
  366.     }
  367.     public function getCollegeDocDownloadName(): string
  368.     {
  369.         return DownloadUtil::getDownalodName($this->collegeDocName$this->name "_学院推荐.");
  370.     }
  371.     public function getExportName(array $nameColumns): string
  372.     {
  373.         $data = [];
  374.         foreach ($nameColumns as $column) {
  375.             if ($column[0] == '-') {
  376.                 $data[] = ltrim($column'-');
  377.             } else {
  378.                 $data[] = $this->getColumnValue($column);
  379.             }
  380.         }
  381.         $rel implode('_'$data);
  382.         return str_replace('/''_'$rel);
  383.     }
  384. }