<?php
namespace App\Entity;
use App\Entity\Common\StateInterface;
use App\Entity\Traits\ProjectFileTrait;
use App\Repository\ProjectRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use FOS\ElasticaBundle\Transformer\HighlightableModelInterface;
#[ORM\Entity(repositoryClass: ProjectRepository::class)]
#[ORM\HasLifecycleCallbacks]
class Project implements HighlightableModelInterface
{
use ProjectFileTrait;
public const BINDINGS = [
'[[PROJECT.NAME]]',
'[[PROJECT.CREATOR]]',
'[[PROJECT.ADMIN.REVIEW]]',
'[[PROJECT.DATE.START]]',
'[[PROJECT.PUBLICATION.LIST]]',
];
public const PRIVATE_FOLDER_NAME = 'projects';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'text', nullable: true)]
private $description;
#[ORM\Column(type: 'integer', nullable: true)]
private $state;
#[ORM\Column(type: 'integer', nullable: true)]
private $type;
#[ORM\OneToMany(targetEntity: Workroom::class, mappedBy: 'project', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['position' => 'ASC'])]
private $workrooms;
#[ORM\OneToMany(targetEntity: UserProject::class, mappedBy: 'project', cascade: ['remove'])]
private $userProjects;
#[ORM\OneToMany(targetEntity: SemanticTag::class, mappedBy: 'project', cascade: ['remove'])]
private $semanticTags;
#[ORM\ManyToOne(targetEntity: Citation::class)]
private $citationFormat;
#[ORM\ManyToOne(targetEntity: User::class)]
private $creator;
#[ORM\ManyToMany(targetEntity: Theme::class)]
private $themes;
#[ORM\Column(type: 'string', length: 500, nullable: true)]
private $adminReview;
#[ORM\Column(name: 'scientific_interest', type: 'text', nullable: true)]
private $scientificInterest;
#[ORM\Column(name: 'application_conditions', type: 'boolean', options: ['default' => 0])]
private $applicationConditions;
#[ORM\Column(name: 'ethic_box', type: 'boolean', options: ['default' => 0])]
private $ethicBox;
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
private $labeled = false;
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
private $requestLabeled = false;
#[ORM\Column(type: 'string', length: 255)]
private $requestPublish = '';
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
private $publishLabo = false;
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
private $publishPublic = false;
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
private $publishOpenEdition = false;
#[ORM\Column(type: 'boolean', options: ['default' => 0])]
private $isIndexable;
#[ORM\Column(type: 'datetime_immutable')]
private $createdAt;
#[ORM\Column(type: 'datetime_immutable')]
private $updatedAt;
private $highlights;
private bool $favorite = false;
#[ORM\ManyToOne(targetEntity: Workroom::class)]
#[ORM\JoinColumn(name: "default_workroom_id", referencedColumnName: "id", nullable: true, onDelete: "SET NULL")]
private ?Workroom $defaultWorkroom = null;
public function getDefaultWorkroom(): ?Workroom
{
return $this->defaultWorkroom;
}
public function setDefaultWorkroom(?Workroom $workroom): self
{
$this->defaultWorkroom = $workroom;
return $this;
}
/**
* Project constructor.
*/
public function __construct()
{
$this->workrooms = new ArrayCollection();
$this->userProjects = new ArrayCollection();
$this->themes = new ArrayCollection();
$this->applicationConditions = false;
$this->ethicBox = false;
$this->favorite = false;
}
public function __toString(): string
{
return $this->getName();
}
public function getBindings(): array
{
return [
'PROJECT.NAME' => $this->getName(),
'PROJECT.CREATOR' => $this->getCreator() ? $this->getCreator()->getFullName() : '',
'PROJECT.ADMIN.REVIEW' => $this->getAdminReview(),
'PROJECT.DATE.START' => $this->getCreatedAt()->format('Y-m-d'),
'PROJECT.PUBLICATION.LIST' => $this->getPublicationList(),
];
}
public function getPublicationList(): ?string
{
$html = '';
if ($this->getPublishLabo()) {
$html .= '<b>- le site Labomega</b></br>';
}
if ($this->getPublishPublic()) {
$html .= '<b>- le site Public</b></br>';
}
if ($this->getPublishOpenEdition()) {
$html .= '<b>- la plateforme Open Édition</b></br>';
}
return $html;
}
public function activate()
{
$this->setState(StateInterface::STATE_ON_GOING_INT);
}
public function getId(): ?int
{
return $this->id;
}
// Needs this method for HighlightableModelInterface
public function setElasticHighlights(array $highlights)
{
$this->highlights = $highlights;
return $this;
}
public function getElasticHighlights()
{
return $this->highlights;
}
public function getName(): ?string
{
return $this->name;
}
/**
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
/**
* @return $this
*/
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getState(): ?int
{
return $this->state;
}
/**
* @return $this
*/
public function setState(?int $state): self
{
$this->state = $state;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
/**
* @return $this
*/
public function setType(?int $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection|Workroom[]
*/
public function getWorkrooms(): Collection
{
return $this->workrooms->filter(function (Workroom $workroom) {
return $workroom->getState() === 1;
});
}
public function getWorkroomsIds(): array
{
$workroomsIds = [];
foreach ($this->workrooms as $workroom) {
$workroomsIds[] = $workroom->getId();
}
return $workroomsIds;
}
/**
* @return $this
*/
public function addWorkroom(Workroom $workroom): self
{
if (!$this->workrooms->contains($workroom)) {
$this->workrooms[] = $workroom;
$workroom->setProject($this);
}
return $this;
}
/**
* @return $this
*/
public function removeWorkroom(Workroom $workroom): self
{
if ($this->workrooms->removeElement($workroom)) {
// set the owning side to null (unless already changed)
if ($workroom->getProject() === $this) {
$workroom->setProject(null);
}
}
return $this;
}
/**
* @return Collection|UserProject[]
*/
public function getUserProjects(): Collection
{
return $this->userProjects;
}
/**
* @return $this
*/
public function addUserProject(UserProject $userProject): self
{
if (!$this->userProjects->contains($userProject)) {
$this->userProjects[] = $userProject;
$userProject->setProject($this);
}
return $this;
}
/**
* @return $this
*/
public function removeUserProject(UserProject $userProject): self
{
if ($this->userProjects->removeElement($userProject)) {
// set the owning side to null (unless already changed)
if ($userProject->getProject() === $this) {
$userProject->setProject(null);
}
}
return $this;
}
public function getCitationFormat(): ?Citation
{
return $this->citationFormat;
}
public function setCitationFormat(?Citation $citationFormat): self
{
$this->citationFormat = $citationFormat;
return $this;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): self
{
$this->creator = $creator;
return $this;
}
/**
* @return Collection|Theme[]
*/
public function getThemes(): Collection
{
return $this->themes;
}
public function setThemes(Collection $themes): self
{
if (count(
array_filter($themes->toArray(), function ($item) {
return !($item instanceof Theme);
})
) > 0) {
$this->themes = $themes;
}
return $this;
}
public function addTheme(Theme $theme): self
{
if (!$this->themes->contains($theme)) {
$this->themes[] = $theme;
}
return $this;
}
public function removeTheme(Theme $theme): self
{
$this->themes->removeElement($theme);
return $this;
}
public function getAdminReview(): ?string
{
return $this->adminReview;
}
public function setAdminReview(?string $adminReview): self
{
$this->adminReview = $adminReview;
return $this;
}
public function getScientificInterest(): ?string
{
return $this->scientificInterest;
}
public function setScientificInterest(?string $scientificInterest): self
{
$this->scientificInterest = $scientificInterest;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getApplicationConditions(): ?bool
{
return $this->applicationConditions;
}
public function setApplicationConditions(bool $applicationConditions): self
{
$this->applicationConditions = $applicationConditions;
return $this;
}
public function getEthicBox(): ?bool
{
return $this->ethicBox;
}
public function setEthicBox(bool $ethicBox): self
{
$this->ethicBox = $ethicBox;
return $this;
}
public function getLabeled(): ?bool
{
return $this->labeled;
}
public function setLabeled(bool $labeled): self
{
$this->labeled = $labeled;
return $this;
}
public function getRequestLabeled(): ?bool
{
return $this->requestLabeled;
}
public function setRequestLabeled(bool $requestLabeled): self
{
$this->requestLabeled = $requestLabeled;
return $this;
}
public function getRequestPublish(): ?string
{
return $this->requestPublish;
}
/**
* @return $this
*/
public function setRequestPublish(string $requestPublish): self
{
$this->requestPublish = $requestPublish;
return $this;
}
public function getPublishLabo(): ?bool
{
return $this->publishLabo;
}
public function setPublishLabo(bool $publishLabo): self
{
$this->publishLabo = $publishLabo;
return $this;
}
public function getPublishPublic(): ?bool
{
return $this->publishPublic;
}
public function setPublishPublic(bool $publishPublic): self
{
$this->publishPublic = $publishPublic;
return $this;
}
public function getPublishOpenEdition(): ?bool
{
return $this->publishOpenEdition;
}
public function setPublishOpenEdition(bool $publishOpenEdition): self
{
$this->publishOpenEdition = $publishOpenEdition;
return $this;
}
public function getIsIndexable(): ?bool
{
return $this->isIndexable;
}
public function setIsIndexable(bool $isIndexable): self
{
$this->isIndexable = $isIndexable;
return $this;
}
/**
* Gets triggered only on insert.
* Set dates.
*/
#[ORM\PrePersist]
public function onPrePersistEntity()
{
$this->createdAt = $this->updatedAt = new \DateTimeImmutable('now');
return $this;
}
}