src/Entity/Corpus.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CorpusRepository;
  4. use DateTimeInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. /**
  10.  * @ORM\Entity(repositoryClass=CorpusRepository::class)
  11.  * @ORM\Table(name="corpus", schema="bdnf", options={"comment":"Contient les corpus de l'application"})
  12.  */
  13. class Corpus
  14. {
  15.     public function __construct()
  16.     {
  17.         //$this->images = new ArrayCollection();
  18.         $this->version = new \DateTime();
  19.     }
  20.     public function __toString(){
  21.         return $this->getTitleFr();
  22.     }
  23.     public function toArray()
  24.     {
  25.         return [
  26.             'id' => $this->getId(),
  27.             'title' => $this->getTitleFr(),
  28.             'titleEn' => $this->getTitleEn(),
  29.             'position' => $this->getPosition(),
  30.             'description' => $this->getDescriptionFr(),
  31.             'descriptionEn' => $this->getDescriptionEn(),
  32.             'previewPicture' => $this->getPreviewPicture(),
  33.            // 'images' => $arrImage,
  34.             'active' => $this->getActive(),
  35.             'version' => $this->getVersion()->format("Y-m-d\TH:i:s"),
  36.             'lastUpdate' => $this->getLastUpdate()->format("Y-m-d\TH:i:s"),
  37.             'zip' => 'https://'.$_ENV['BASE_URL'].'/corpus/download/'.$this->getId(),
  38.         ];
  39.     }
  40.     public function toArrayForXmlCluster()
  41.     {
  42.         $images = [];
  43.         foreach($this->images->toArray() as $image){
  44.             $images[] = [
  45.                 'filename' => $image->getThumbnails(),
  46.                 'title' => $image->getTitle(),
  47.                 'author' => $image->getAuthor(),
  48.                 'longName' => $image->getLongName(),
  49.                 'arkLink' => $image->getArkLink(),
  50.             ];
  51.         };
  52.         return [
  53.             'name' => $this->getTitleFr(),
  54.             'nameEn' => $this->getTitleEn(),
  55.             'description' => $this->getDescriptionFr(),
  56.             'descriptionEn' => $this->getDescriptionEn(),
  57.             'preview' => $this->getPreviewPicture(),
  58.             'onlineCluster' => true,
  59.             'version' => $this->version->format("Y-m-d\TH:i:s"),
  60.             'lastUpdate' => $this->lastUpdate->format("Y-m-d\TH:i:s"),
  61.             'Assets' => $images
  62.         ];
  63.     }
  64.     /**
  65.      * @ORM\Id
  66.      * @ORM\GeneratedValue
  67.      * @ORM\Column(type="integer", options={"comment":"Identifiant unique du corpus"})
  68.      */
  69.     private $id;
  70.     /**
  71.      * @ORM\Column(type="boolean", options={"comment":"Indique si le corpus est actif ou non"})
  72.      */
  73.     private $active true;
  74.     /**
  75.      * @ORM\Column(type="boolean", options={"comment":"Indique si le corpus est grand ou non"})
  76.      */
  77.     private $large false;
  78.     /**
  79.      * @ORM\Column(type="integer", options={"comment":"Position du corpus dans la liste"})
  80.      */
  81.     private $position;
  82.     /**
  83.      * @ORM\Column(type="string", options={"comment":"Titre du corpus en français"})
  84.      */
  85.     private $titleFr;
  86.     /**
  87.      * @ORM\Column(type="text", nullable=true, options={"comment":"Description du corpus en français"})
  88.      */
  89.     private $descriptionFr;
  90.     /**
  91.      * @ORM\Column(type="string", nullable=true, options={"comment":"Titre du corpus en anglais"})
  92.      */
  93.     private $titleEn;
  94.     /**
  95.      * @ORM\Column(type="text", nullable=true, options={"comment":"Description du corpus en anglais"})
  96.      */
  97.     private $descriptionEn;
  98.     /**
  99.      * @ORM\Column(type="string", nullable=true, options={"comment":"Nom du fichier de l'image de prévisualisation"})
  100.      */
  101.     private $previewPicture;
  102.     /**
  103.      * @Vich\UploadableField(mapping="corpusPreviewPicture", fileNameProperty="previewPicture")
  104.      * @var File
  105.      */
  106.     private $previewPictureFile;
  107.     /**
  108.      * @ORM\OneToMany(targetEntity=Image::class, cascade={"persist", "remove"}, mappedBy="corpus")
  109.      */
  110.     private $images;
  111.     /**
  112.      * @ORM\Column(type="datetime", nullable=true, options={"comment":"Date de la dernière modification du corpus"})
  113.      */
  114.     private $version;
  115.     /**
  116.      * @ORM\Column(type="datetime", nullable=true, options={"comment":"Date de la dernière modification du corpus"})
  117.      */
  118.     private $lastUpdate;
  119.     /**
  120.      * @return mixed
  121.      */
  122.     public function getLastUpdate()
  123.     {
  124.         return $this->lastUpdate;
  125.     }
  126.     /**
  127.      * @param mixed $lastUpdate
  128.      */
  129.     public function setLastUpdate($lastUpdate): void
  130.     {
  131.         $this->lastUpdate $lastUpdate;
  132.     }
  133.     public function getId(): ?int
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function getActive(): ?bool
  138.     {
  139.         return $this->active;
  140.     }
  141.     public function setActive(bool $active): self
  142.     {
  143.         $this->active $active;
  144.         return $this;
  145.     }
  146.     /**
  147.      * @return mixed
  148.      */
  149.     public function getPosition()
  150.     {
  151.         return $this->position;
  152.     }
  153.     /**
  154.      * @param mixed $position
  155.      */
  156.     public function setPosition($position): void
  157.     {
  158.         $this->position $position;
  159.     }
  160.     /**
  161.      * @return mixed
  162.      */
  163.     public function getTitleFr()
  164.     {
  165.         return $this->titleFr;
  166.     }
  167.     /**
  168.      * @param mixed $titleFr
  169.      */
  170.     public function setTitleFr($titleFr): void
  171.     {
  172.         $this->titleFr $titleFr;
  173.     }
  174.     /**
  175.      * @return mixed
  176.      */
  177.     public function getDescriptionFr()
  178.     {
  179.         return $this->descriptionFr;
  180.     }
  181.     /**
  182.      * @param mixed $descriptionFr
  183.      */
  184.     public function setDescriptionFr($descriptionFr): void
  185.     {
  186.         $this->descriptionFr $descriptionFr;
  187.     }
  188.     /**
  189.      * @return mixed
  190.      */
  191.     public function getTitleEn()
  192.     {
  193.         return $this->titleEn;
  194.     }
  195.     /**
  196.      * @param mixed $titleEn
  197.      */
  198.     public function setTitleEn($titleEn): void
  199.     {
  200.         $this->titleEn $titleEn;
  201.     }
  202.     /**
  203.      * @return mixed
  204.      */
  205.     public function getDescriptionEn()
  206.     {
  207.         return $this->descriptionEn;
  208.     }
  209.     /**
  210.      * @param mixed $descriptionEn
  211.      */
  212.     public function setDescriptionEn($descriptionEn): void
  213.     {
  214.         $this->descriptionEn $descriptionEn;
  215.     }
  216.     /**
  217.      * @return mixed
  218.      */
  219.     public function getPreviewPicture()
  220.     {
  221.         return $this->previewPicture;
  222.     }
  223.     /**
  224.      * @param mixed $previewPicture
  225.      */
  226.     public function setPreviewPicture($previewPicture): void
  227.     {
  228.         $this->previewPicture $previewPicture;
  229.     }
  230.     /**
  231.      * @return File
  232.      */
  233.     public function getPreviewPictureFile(): File
  234.     {
  235.         return $this->previewPictureFile;
  236.     }
  237.     /**
  238.      * @param File $previewPictureFile
  239.      */
  240.     public function setPreviewPictureFile(File $previewPictureFile): void
  241.     {
  242.         $this->previewPictureFile $previewPictureFile;
  243.     }
  244.     /**
  245.      * @return mixed
  246.      */
  247.     public function getImages()
  248.     {
  249.         return $this->images;
  250.     }
  251.     /**
  252.      * @param mixed $images
  253.      */
  254.     public function setImages($images): void
  255.     {
  256.         $this->images $images;
  257.     }
  258.     public function addImage(Image $image){
  259.         $this->images->add($image);
  260.         $image->setCorpus($this);
  261.     }
  262.     /**
  263.      * @return mixed
  264.      */
  265.     public function getLarge()
  266.     {
  267.         return $this->large == null false $this->large;
  268.     }
  269.     /**
  270.      * @param mixed $large
  271.      */
  272.     public function setLarge($large): void
  273.     {
  274.         $this->large $large;
  275.     }
  276.     /**
  277.      * @return mixed
  278.      */
  279.     public function getVersion()
  280.     {
  281.         return $this->version;
  282.     }
  283.     /**
  284.      * @param mixed $version
  285.      */
  286.     public function setVersion($version): void
  287.     {
  288.         $this->version $version;
  289.     }
  290. }