src/Entity/Project.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Common\StateInterface;
  4. use App\Entity\Traits\ProjectFileTrait;
  5. use App\Repository\ProjectRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use FOS\ElasticaBundle\Transformer\HighlightableModelInterface;
  10. #[ORM\Entity(repositoryClassProjectRepository::class)]
  11. #[ORM\HasLifecycleCallbacks]
  12. class Project implements HighlightableModelInterface
  13. {
  14.     use ProjectFileTrait;
  15.     public const BINDINGS = [
  16.         '[[PROJECT.NAME]]',
  17.         '[[PROJECT.CREATOR]]',
  18.         '[[PROJECT.ADMIN.REVIEW]]',
  19.         '[[PROJECT.DATE.START]]',
  20.         '[[PROJECT.PUBLICATION.LIST]]',
  21.     ];
  22.     public const PRIVATE_FOLDER_NAME 'projects';
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column(type'integer')]
  26.     private $id;
  27.     #[ORM\Column(type'string'length255)]
  28.     private $name;
  29.     #[ORM\Column(type'text'nullabletrue)]
  30.     private $description;
  31.     #[ORM\Column(type'integer'nullabletrue)]
  32.     private $state;
  33.     #[ORM\Column(type'integer'nullabletrue)]
  34.     private $type;
  35.     #[ORM\OneToMany(targetEntityWorkroom::class, mappedBy'project'cascade: ['persist''remove'])]
  36.     #[ORM\OrderBy(['position' => 'ASC'])]
  37.     private $workrooms;
  38.     #[ORM\OneToMany(targetEntityUserProject::class, mappedBy'project'cascade: ['remove'])]
  39.     private $userProjects;
  40.     #[ORM\OneToMany(targetEntitySemanticTag::class, mappedBy'project'cascade: ['remove'])]
  41.     private $semanticTags;
  42.     #[ORM\ManyToOne(targetEntityCitation::class)]
  43.     private $citationFormat;
  44.     #[ORM\ManyToOne(targetEntityUser::class)]
  45.     private $creator;
  46.     #[ORM\ManyToMany(targetEntityTheme::class)]
  47.     private $themes;
  48.     #[ORM\Column(type'string'length500nullabletrue)]
  49.     private $adminReview;
  50.     #[ORM\Column(name'scientific_interest'type'text'nullabletrue)]
  51.     private $scientificInterest;
  52.     #[ORM\Column(name'application_conditions'type'boolean'options: ['default' => 0])]
  53.     private $applicationConditions;
  54.     #[ORM\Column(name'ethic_box'type'boolean'options: ['default' => 0])]
  55.     private $ethicBox;
  56.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  57.     private $labeled false;
  58.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  59.     private $requestLabeled false;
  60.     #[ORM\Column(type'string'length255)]
  61.     private $requestPublish '';
  62.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  63.     private $publishLabo false;
  64.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  65.     private $publishPublic false;
  66.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  67.     private $publishOpenEdition false;
  68.     #[ORM\Column(type'boolean'options: ['default' => 0])]
  69.     private $isIndexable;
  70.     #[ORM\Column(type'datetime_immutable')]
  71.     private $createdAt;
  72.     #[ORM\Column(type'datetime_immutable')]
  73.     private $updatedAt;
  74.     private $highlights;
  75.     private bool $favorite false;
  76.     #[ORM\ManyToOne(targetEntityWorkroom::class)]
  77.     #[ORM\JoinColumn(name"default_workroom_id"referencedColumnName"id"nullabletrueonDelete"SET NULL")]
  78.     private ?Workroom $defaultWorkroom null;
  79.     public function getDefaultWorkroom(): ?Workroom
  80.     {
  81.         return $this->defaultWorkroom;
  82.     }
  83.     public function setDefaultWorkroom(?Workroom $workroom): self
  84.     {
  85.         $this->defaultWorkroom $workroom;
  86.         return $this;
  87.     }
  88.     /**
  89.      * Project constructor.
  90.      */
  91.     public function __construct()
  92.     {
  93.         $this->workrooms = new ArrayCollection();
  94.         $this->userProjects = new ArrayCollection();
  95.         $this->themes = new ArrayCollection();
  96.         $this->applicationConditions false;
  97.         $this->ethicBox false;
  98.         $this->favorite false;
  99.     }
  100.     public function __toString(): string
  101.     {
  102.         return $this->getName();
  103.     }
  104.     public function getBindings(): array
  105.     {
  106.         return [
  107.             'PROJECT.NAME' => $this->getName(),
  108.             'PROJECT.CREATOR' => $this->getCreator() ? $this->getCreator()->getFullName() : '',
  109.             'PROJECT.ADMIN.REVIEW' => $this->getAdminReview(),
  110.             'PROJECT.DATE.START' => $this->getCreatedAt()->format('Y-m-d'),
  111.             'PROJECT.PUBLICATION.LIST' => $this->getPublicationList(),
  112.         ];
  113.     }
  114.     public function getPublicationList(): ?string
  115.     {
  116.         $html '';
  117.         if ($this->getPublishLabo()) {
  118.             $html .= '<b>- le site Labomega</b></br>';
  119.         }
  120.         if ($this->getPublishPublic()) {
  121.             $html .= '<b>- le site Public</b></br>';
  122.         }
  123.         if ($this->getPublishOpenEdition()) {
  124.             $html .= '<b>- la plateforme Open Ă‰dition</b></br>';
  125.         }
  126.         return $html;
  127.     }
  128.     public function activate()
  129.     {
  130.         $this->setState(StateInterface::STATE_ON_GOING_INT);
  131.     }
  132.     public function getId(): ?int
  133.     {
  134.         return $this->id;
  135.     }
  136.     // Needs this method for HighlightableModelInterface
  137.     public function setElasticHighlights(array $highlights)
  138.     {
  139.         $this->highlights $highlights;
  140.         return $this;
  141.     }
  142.     public function getElasticHighlights()
  143.     {
  144.         return $this->highlights;
  145.     }
  146.     public function getName(): ?string
  147.     {
  148.         return $this->name;
  149.     }
  150.     /**
  151.      * @return $this
  152.      */
  153.     public function setName(string $name): self
  154.     {
  155.         $this->name $name;
  156.         return $this;
  157.     }
  158.     public function getDescription(): ?string
  159.     {
  160.         return $this->description;
  161.     }
  162.     /**
  163.      * @return $this
  164.      */
  165.     public function setDescription(?string $description): self
  166.     {
  167.         $this->description $description;
  168.         return $this;
  169.     }
  170.     public function getState(): ?int
  171.     {
  172.         return $this->state;
  173.     }
  174.     /**
  175.      * @return $this
  176.      */
  177.     public function setState(?int $state): self
  178.     {
  179.         $this->state $state;
  180.         return $this;
  181.     }
  182.     public function getType(): ?int
  183.     {
  184.         return $this->type;
  185.     }
  186.     /**
  187.      * @return $this
  188.      */
  189.     public function setType(?int $type): self
  190.     {
  191.         $this->type $type;
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return Collection|Workroom[]
  196.      */
  197.     public function getWorkrooms(): Collection
  198.     {
  199.         return $this->workrooms->filter(function (Workroom $workroom) {
  200.             return $workroom->getState() === 1;
  201.         });
  202.     }
  203.     public function getWorkroomsIds(): array
  204.     {
  205.         $workroomsIds = [];
  206.         foreach ($this->workrooms as $workroom) {
  207.             $workroomsIds[] = $workroom->getId();
  208.         }
  209.         return $workroomsIds;
  210.     }
  211.     /**
  212.      * @return $this
  213.      */
  214.     public function addWorkroom(Workroom $workroom): self
  215.     {
  216.         if (!$this->workrooms->contains($workroom)) {
  217.             $this->workrooms[] = $workroom;
  218.             $workroom->setProject($this);
  219.         }
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return $this
  224.      */
  225.     public function removeWorkroom(Workroom $workroom): self
  226.     {
  227.         if ($this->workrooms->removeElement($workroom)) {
  228.             // set the owning side to null (unless already changed)
  229.             if ($workroom->getProject() === $this) {
  230.                 $workroom->setProject(null);
  231.             }
  232.         }
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return Collection|UserProject[]
  237.      */
  238.     public function getUserProjects(): Collection
  239.     {
  240.         return $this->userProjects;
  241.     }
  242.     /**
  243.      * @return $this
  244.      */
  245.     public function addUserProject(UserProject $userProject): self
  246.     {
  247.         if (!$this->userProjects->contains($userProject)) {
  248.             $this->userProjects[] = $userProject;
  249.             $userProject->setProject($this);
  250.         }
  251.         return $this;
  252.     }
  253.     /**
  254.      * @return $this
  255.      */
  256.     public function removeUserProject(UserProject $userProject): self
  257.     {
  258.         if ($this->userProjects->removeElement($userProject)) {
  259.             // set the owning side to null (unless already changed)
  260.             if ($userProject->getProject() === $this) {
  261.                 $userProject->setProject(null);
  262.             }
  263.         }
  264.         return $this;
  265.     }
  266.     public function getCitationFormat(): ?Citation
  267.     {
  268.         return $this->citationFormat;
  269.     }
  270.     public function setCitationFormat(?Citation $citationFormat): self
  271.     {
  272.         $this->citationFormat $citationFormat;
  273.         return $this;
  274.     }
  275.     public function getCreator(): ?User
  276.     {
  277.         return $this->creator;
  278.     }
  279.     public function setCreator(?User $creator): self
  280.     {
  281.         $this->creator $creator;
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return Collection|Theme[]
  286.      */
  287.     public function getThemes(): Collection
  288.     {
  289.         return $this->themes;
  290.     }
  291.     public function setThemes(Collection $themes): self
  292.     {
  293.         if (count(
  294.             array_filter($themes->toArray(), function ($item) {
  295.                 return !($item instanceof Theme);
  296.             })
  297.         ) > 0) {
  298.             $this->themes $themes;
  299.         }
  300.         return $this;
  301.     }
  302.     public function addTheme(Theme $theme): self
  303.     {
  304.         if (!$this->themes->contains($theme)) {
  305.             $this->themes[] = $theme;
  306.         }
  307.         return $this;
  308.     }
  309.     public function removeTheme(Theme $theme): self
  310.     {
  311.         $this->themes->removeElement($theme);
  312.         return $this;
  313.     }
  314.     public function getAdminReview(): ?string
  315.     {
  316.         return $this->adminReview;
  317.     }
  318.     public function setAdminReview(?string $adminReview): self
  319.     {
  320.         $this->adminReview $adminReview;
  321.         return $this;
  322.     }
  323.     public function getScientificInterest(): ?string
  324.     {
  325.         return $this->scientificInterest;
  326.     }
  327.     public function setScientificInterest(?string $scientificInterest): self
  328.     {
  329.         $this->scientificInterest $scientificInterest;
  330.         return $this;
  331.     }
  332.     public function getCreatedAt(): ?\DateTimeImmutable
  333.     {
  334.         return $this->createdAt;
  335.     }
  336.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  337.     {
  338.         $this->createdAt $createdAt;
  339.         return $this;
  340.     }
  341.     public function getUpdatedAt(): ?\DateTimeImmutable
  342.     {
  343.         return $this->updatedAt;
  344.     }
  345.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  346.     {
  347.         $this->updatedAt $updatedAt;
  348.         return $this;
  349.     }
  350.     public function getApplicationConditions(): ?bool
  351.     {
  352.         return $this->applicationConditions;
  353.     }
  354.     public function setApplicationConditions(bool $applicationConditions): self
  355.     {
  356.         $this->applicationConditions $applicationConditions;
  357.         return $this;
  358.     }
  359.     public function getEthicBox(): ?bool
  360.     {
  361.         return $this->ethicBox;
  362.     }
  363.     public function setEthicBox(bool $ethicBox): self
  364.     {
  365.         $this->ethicBox $ethicBox;
  366.         return $this;
  367.     }
  368.     public function getLabeled(): ?bool
  369.     {
  370.         return $this->labeled;
  371.     }
  372.     public function setLabeled(bool $labeled): self
  373.     {
  374.         $this->labeled $labeled;
  375.         return $this;
  376.     }
  377.     public function getRequestLabeled(): ?bool
  378.     {
  379.         return $this->requestLabeled;
  380.     }
  381.     public function setRequestLabeled(bool $requestLabeled): self
  382.     {
  383.         $this->requestLabeled $requestLabeled;
  384.         return $this;
  385.     }
  386.     public function getRequestPublish(): ?string
  387.     {
  388.         return $this->requestPublish;
  389.     }
  390.     /**
  391.      * @return $this
  392.      */
  393.     public function setRequestPublish(string $requestPublish): self
  394.     {
  395.         $this->requestPublish $requestPublish;
  396.         return $this;
  397.     }
  398.     public function getPublishLabo(): ?bool
  399.     {
  400.         return $this->publishLabo;
  401.     }
  402.     public function setPublishLabo(bool $publishLabo): self
  403.     {
  404.         $this->publishLabo $publishLabo;
  405.         return $this;
  406.     }
  407.     public function getPublishPublic(): ?bool
  408.     {
  409.         return $this->publishPublic;
  410.     }
  411.     public function setPublishPublic(bool $publishPublic): self
  412.     {
  413.         $this->publishPublic $publishPublic;
  414.         return $this;
  415.     }
  416.     public function getPublishOpenEdition(): ?bool
  417.     {
  418.         return $this->publishOpenEdition;
  419.     }
  420.     public function setPublishOpenEdition(bool $publishOpenEdition): self
  421.     {
  422.         $this->publishOpenEdition $publishOpenEdition;
  423.         return $this;
  424.     }
  425.     public function getIsIndexable(): ?bool
  426.     {
  427.         return $this->isIndexable;
  428.     }
  429.     public function setIsIndexable(bool $isIndexable): self
  430.     {
  431.         $this->isIndexable $isIndexable;
  432.         return $this;
  433.     }
  434.     /**
  435.      * Gets triggered only on insert.
  436.      * Set dates.
  437.      */
  438.     #[ORM\PrePersist]
  439.     public function onPrePersistEntity()
  440.     {
  441.         $this->createdAt $this->updatedAt = new \DateTimeImmutable('now');
  442.         return $this;
  443.     }
  444. }