<?php
namespace App\Entity;
use App\Entity\Traits\BaseDateAtTrait;
use App\Repository\ReadingCardRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ReadingCardRepository::class)]
#[ORM\HasLifecycleCallbacks]
class ReadingCard
{
use BaseDateAtTrait;
public const REFERENCE_TYPE_BOOK = 0;
public const REFERENCE_TYPE_ARTICLE = 1;
public const REFERENCE_TYPE_AUTRE = 2;
public static $allReferencesType = [
self::REFERENCE_TYPE_BOOK => 'reading_card.referencesType.book',
self::REFERENCE_TYPE_ARTICLE => 'reading_card.referencesType.article',
self::REFERENCE_TYPE_AUTRE => 'reading_card.referencesType.autre',
];
public const REQUIRED_BOOK_FIELDS = ['referencePlace', 'referenceEditor', 'referencePublishDate'];
public const REQUIRED_ARTICLE_FIELDS = ['referenceVolume', 'referenceDate', 'referencePage'];
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[Assert\NotBlank]
#[ORM\Column(type: 'integer')]
private $referenceType;
#[Assert\NotBlank]
#[ORM\Column(type: 'string', length: 255)]
private $referenceAuthorLastName;
#[Assert\NotBlank]
#[ORM\Column(type: 'string', length: 255)]
private $referenceAuthorFirstName;
#[Assert\NotBlank]
#[ORM\Column(type: 'string', length: 255)]
private $referenceTitle;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referenceMagazine;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referenceVolume;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referenceDate;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referencePage;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referencePlace;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referenceEditor;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referencePublishDate;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $referenceTranslation;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $doi;
#[Assert\NotBlank]
#[ORM\Column(type: 'text', nullable: true)]
private $relevanceProject;
#[ORM\Column(type: 'text', nullable: true)]
private $resume;
#[ORM\Column(type: 'json', nullable: true)]
private $keywords = [];
#[ORM\Column(type: 'text', nullable: true)]
private $arguments;
#[ORM\Column(type: 'text', nullable: true)]
private $quotes;
#[ORM\Column(type: 'text', nullable: true)]
private $reviews;
#[ORM\Column(type: 'text', nullable: true)]
private $referencesText;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'readingCards')]
private $user;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'lastUserReadingCards')]
private $lastUser;
#[ORM\OneToOne(targetEntity: WorkroomResource::class, mappedBy: 'readingCard', cascade: ['persist', 'remove'])]
#[JoinColumn(onDelete: 'CASCADE')]
private $workroomResource;
#[ORM\OneToOne(targetEntity: PersonalResource::class, mappedBy: 'readingCard', cascade: ['persist', 'remove'])]
#[JoinColumn(onDelete: 'CASCADE')]
private $personalResource;
#[ORM\ManyToMany(targetEntity: SemanticTag::class, inversedBy: 'readingCards')]
private $semanticTag;
public const AI_STATUS_PENDING = 'pending';
public const AI_STATUS_RUNNING = 'running';
public const AI_STATUS_DONE = 'done';
public const AI_STATUS_FAILED = 'failed';
#[ORM\Column(type: 'string', length: 16, nullable: true)]
private ?string $aiStatus = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $aiError = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $aiStartedAt = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $aiFinishedAt = null;
public function __construct()
{
$this->semanticTag = new ArrayCollection();
}
public function getAiStatus(): ?string
{
return $this->aiStatus;
}
public function setAiStatus(?string $aiStatus): self
{
$this->aiStatus = $aiStatus;
return $this;
}
public function getAiError(): ?string
{
return $this->aiError;
}
public function setAiError(?string $aiError): self
{
$this->aiError = $aiError;
return $this;
}
public function getAiStartedAt(): ?\DateTimeInterface
{
return $this->aiStartedAt;
}
public function setAiStartedAt(?\DateTimeInterface $aiStartedAt): self
{
$this->aiStartedAt = $aiStartedAt;
return $this;
}
public function getAiFinishedAt(): ?\DateTimeInterface
{
return $this->aiFinishedAt;
}
public function setAiFinishedAt(?\DateTimeInterface $aiFinishedAt): self
{
$this->aiFinishedAt = $aiFinishedAt;
return $this;
}
public function getId(): ?int
{
return $this->id;
}
public function getReferenceType(): ?string
{
return $this->referenceType;
}
public function getReferenceFromCode(int $referenceType): ?string
{
return self::$allReferencesType[$referenceType];
}
public function setReferenceType(?string $referenceType): self
{
$this->referenceType = $referenceType;
return $this;
}
public function getReferenceAuthorLastName(): ?string
{
return $this->referenceAuthorLastName;
}
public function setReferenceAuthorLastName(?string $referenceAuthorLastName): self
{
$this->referenceAuthorLastName = $referenceAuthorLastName;
return $this;
}
public function getReferenceAuthorFirstName(): ?string
{
return $this->referenceAuthorFirstName;
}
public function setReferenceAuthorFirstName(?string $referenceAuthorFirstName): self
{
$this->referenceAuthorFirstName = $referenceAuthorFirstName;
return $this;
}
public function getReferenceTitle(): ?string
{
return $this->referenceTitle;
}
public function setReferenceTitle(?string $referenceTitle): self
{
$this->referenceTitle = $referenceTitle;
return $this;
}
public function getReferenceMagazine(): ?string
{
return $this->referenceMagazine;
}
public function setReferenceMagazine(?string $referenceMagazine): self
{
$this->referenceMagazine = $referenceMagazine;
return $this;
}
public function getReferenceVolume(): ?string
{
return $this->referenceVolume;
}
public function setReferenceVolume(?string $referenceVolume): self
{
$this->referenceVolume = $referenceVolume;
return $this;
}
public function getReferencePage(): ?string
{
return $this->referencePage;
}
public function setReferencePage(?string $referencePage): self
{
$this->referencePage = $referencePage;
return $this;
}
public function getReferenceDate(): ?string
{
return $this->referenceDate;
}
public function setReferenceDate(?string $referenceDate): self
{
$this->referenceDate = $referenceDate;
return $this;
}
public function getReferencePlace(): ?string
{
return $this->referencePlace;
}
public function setReferencePlace(?string $referencePlace): self
{
$this->referencePlace = $referencePlace;
return $this;
}
public function getReferenceEditor(): ?string
{
return $this->referenceEditor;
}
public function setReferenceEditor(?string $referenceEditor): self
{
$this->referenceEditor = $referenceEditor;
return $this;
}
public function getReferencePublishDate(): ?string
{
return $this->referencePublishDate;
}
public function setReferencePublishDate(?string $referencePublishDate): self
{
$this->referencePublishDate = $referencePublishDate;
return $this;
}
public function getReferenceTranslation(): ?string
{
return $this->referenceTranslation;
}
public function setReferenceTranslation(?string $referenceTranslation): self
{
$this->referenceTranslation = $referenceTranslation;
return $this;
}
public function getDoi(): ?string
{
return $this->doi;
}
public function setDoi(?string $doi): self
{
$this->doi = $doi;
return $this;
}
public function getRelevanceProject(): ?string
{
return $this->relevanceProject;
}
public function setRelevanceProject(?string $relevanceProject): self
{
$this->relevanceProject = $relevanceProject;
return $this;
}
public function getResume(): ?string
{
return $this->resume;
}
public function setResume(?string $resume): self
{
$this->resume = $resume;
return $this;
}
public function getKeywords(): ?array
{
return $this->keywords;
}
public function setKeywords(?array $keywords): self
{
$this->keywords = $keywords;
return $this;
}
public function getArguments(): ?string
{
return $this->arguments;
}
public function setArguments(?string $arguments): self
{
$this->arguments = $arguments;
return $this;
}
public function getQuotes(): ?string
{
return $this->quotes;
}
public function setQuotes(?string $quotes): self
{
$this->quotes = $quotes;
return $this;
}
public function getReviews(): ?string
{
return $this->reviews;
}
public function setReviews(?string $reviews): self
{
$this->reviews = $reviews;
return $this;
}
public function getReferencesText(): ?string
{
return $this->referencesText;
}
public function setReferencesText(?string $referencesText): self
{
$this->referencesText = $referencesText;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getLastUser(): ?User
{
return $this->lastUser;
}
public function setLastUser(?User $lastUser): self
{
$this->lastUser = $lastUser;
return $this;
}
public function getWorkroomResource(): ?WorkroomResource
{
return $this->workroomResource;
}
public function setWorkroomResource(?WorkroomResource $workroomResource): self
{
$this->workroomResource = $workroomResource;
return $this;
}
public function getPersonalResource(): ?PersonalResource
{
return $this->personalResource;
}
public function setPersonalResource(?PersonalResource $personalResource): self
{
$this->personalResource = $personalResource;
return $this;
}
public function setKeywordsString($str)
{
$keywords = explode(',', str_replace(' ', '', $str));
$this->setKeywords($keywords);
return $this;
}
public function getKeywordsString()
{
$keywordsString = '';
foreach ($this->keywords as $keyword) {
$keywordsString .= $keyword.',';
}
return substr($keywordsString, 0, -1);
}
/**
* @return Collection|SemanticTag[]
*/
public function getSemanticTag(): Collection
{
return $this->semanticTag;
}
public function getSementicTagAsString(): ?string
{
$semanticAsString = '';
foreach ($this->semanticTag as $semanticTag) {
$semanticAsString .= $semanticTag->getName().',';
}
return substr($semanticAsString, 0, -1);
}
public function addSemanticTag(SemanticTag $semanticTag): self
{
if (!$this->semanticTag->contains($semanticTag)) {
$this->semanticTag[] = $semanticTag;
}
return $this;
}
public function removeSemanticTag(SemanticTag $semanticTag): self
{
$this->semanticTag->removeElement($semanticTag);
return $this;
}
}