vendor/score/cms/src/Entity/Document/Document.php line 23

Open in your IDE?
  1. <?php
  2. namespace Score\CmsBundle\Entity\Document;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Score\BaseBundle\Entity\BaseEntity;
  7. use Score\CmsBundle\Entity\Access\Access;
  8. use Score\CmsBundle\Entity\Access\AccessDocument;
  9. use Score\CmsBundle\Entity\Block\BlockJoint;
  10. use Score\CmsBundle\Entity\Block\BlockJointDocument;
  11. use Score\CmsBundle\Entity\Metatag\MetatagDocument;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. /**
  14.  * @UniqueEntity("seoId",message="document.seoId.unique")
  15.  * @ORM\Entity()
  16.  * @ORM\Table(name="cms_document")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  */
  19. class Document extends BaseEntity {
  20.     /**
  21.      * @ORM\Column(name="d_name", type="string", length=1000)
  22.      */
  23.     protected $name;
  24.     /**
  25.      * @ORM\Column(name="d_full_name", type="string", length=2000)
  26.      */
  27.     protected $fullName;
  28.     /**
  29.      * @ORM\Column(name="d_teaser", type="string", length=2000, nullable=true)
  30.      */
  31.     protected $teaser;
  32.     /**
  33.      * @ORM\Column(name="d_description", type="text", nullable=true)
  34.      */
  35.     protected $description;
  36.     /**
  37.      * @ORM\Column(name="d_has_detail", type="boolean")
  38.      */
  39.     protected $hasDetail = true;
  40.     /**
  41.      * @ORM\Column(name="d_public", type="boolean", nullable=true)
  42.      */
  43.     protected $public = true;
  44.     /**
  45.      * @ORM\Column(name="d_search", type="text", nullable=true)
  46.      */
  47.     protected $search;
  48.     /**
  49.      * @ORM\Column(name="d_version", type="integer", nullable=true)
  50.      */
  51.     protected $version;
  52.     /**
  53.      * @ORM\Column(name="d_code", type="string", length=255, nullable=true, unique=true)
  54.      */
  55.     protected $code;
  56.     /**
  57.      * @ORM\Column(name="d_seoId", type="string", length=500, unique=true)
  58.      */
  59.     protected $seoId;
  60.     /**
  61.      * @ORM\Column(name="d_year", type="string", length=250, nullable=true)
  62.      */
  63.     protected $year;
  64.     /**
  65.      * @ORM\Column(name="d_icon", type="string", length=1000, nullable=true)
  66.      */
  67.     protected $icon;
  68.     /**
  69.      * @ORM\Column(name="d_params", type="string", length=2000, nullable=true)
  70.      */
  71.     protected $params;
  72.     /**
  73.      * @ORM\ManyToMany(targetEntity=DocumentLevel::class, inversedBy="documents", cascade={"persist", "remove"})
  74.      * @ORM\JoinTable(name="cms_conn_document_level",
  75.      *      joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
  76.      *      inverseJoinColumns={@ORM\JoinColumn(name="Level_id", referencedColumnName="id")}
  77.      *      )
  78.      * @ORM\OrderBy({"name" = "ASC"})
  79.      */
  80.     protected $documentLevels;
  81.     /**
  82.      * @ORM\ManyToMany(targetEntity=DocumentCategory::class, inversedBy="documents", cascade={"persist", "remove"})
  83.      * @ORM\JoinTable(name="cms_conn_document_category",
  84.      *      joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
  85.      *      inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")}
  86.      *      )
  87.      * @ORM\OrderBy({"name" = "ASC"})
  88.      */
  89.     protected $documentCategories;
  90.     /**
  91.      * @ORM\OneToMany(targetEntity=DocumentDescription::class, mappedBy="document", cascade={"persist", "remove"})
  92.      * @ORM\OrderBy({"sortOrder" = "ASC"})
  93.      */
  94.     protected $documentDescriptions;
  95.     /**
  96.      * @ORM\OneToMany(targetEntity=DocumentFile::class, mappedBy="document", cascade={"persist", "remove"})
  97.      * @ORM\OrderBy({"createdAt" = "ASC"})
  98.      */
  99.     protected $documentFiles;
  100.     /**
  101.      * Many Documents have Many Documents. // vracia len jednu cast spolocnych
  102.      * @ORM\ManyToMany(targetEntity="Document", mappedBy="myRelevants")
  103.      */
  104.     protected $relevantsWithMe;
  105.     /**
  106.      * Many Documents have many Documents. // vracia vsetky spolocne obojstranne
  107.      * @ORM\ManyToMany(targetEntity="Document", inversedBy="relevantsWithMe")
  108.      * @ORM\JoinTable(name="cms_conn_document_document",
  109.      *      joinColumns={@ORM\JoinColumn(name="document_id", referencedColumnName="id")},
  110.      *      inverseJoinColumns={@ORM\JoinColumn(name="relevant_document_id", referencedColumnName="id")}
  111.      *      )
  112.      * @ORM\OrderBy({"name" = "ASC"})
  113.      */
  114.     protected $myRelevants;
  115.     /**
  116.      * @ORM\OneToMany(targetEntity=AccessDocument::class, mappedBy="document", cascade={"persist", "remove"}, orphanRemoval=true)
  117.      */
  118.     protected $accesses;
  119.     /**
  120.      * @ORM\OneToMany(targetEntity=BlockJointDocument::class, mappedBy="document", cascade={"persist", "remove"}, orphanRemoval=true)
  121.      * @ORM\OrderBy({"sortOrder"="ASC", "place"="ASC"})
  122.      */
  123.     protected $blockJoints;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity=MetatagDocument::class, mappedBy="document", cascade={"persist", "remove"}, orphanRemoval=true)
  126.      */
  127.     protected $metatags;
  128.     public function __construct() {
  129.         $this->accesses = new ArrayCollection();
  130.         $this->blockJoints = new ArrayCollection();
  131.         $this->metatags = new ArrayCollection();
  132.         $this->documentCategories = new ArrayCollection();
  133.         $this->documentLevels = new ArrayCollection();
  134.         $this->documentDescriptions = new ArrayCollection();
  135.         $this->documentFiles = new ArrayCollection();
  136.         $this->relevantsWithMe = new ArrayCollection();
  137.         $this->myRelevants = new ArrayCollection();
  138.     }
  139.     public function __toString() {
  140. //        return $this->fullName;
  141.         return $this->getName();
  142.     }
  143.     protected $actualFile = null;
  144.     public function getActualFile(): ?DocumentFile {
  145.         if (!$this->actualFile) {
  146.             $file = $this->getDocumentFiles()->filter(function ($f) {
  147.                 return $f->getIsCurrent() === true;
  148.             })->last(); // najde file alebo false
  149.             $this->actualFile = $file ?: null;
  150.         }
  151.         return $this->actualFile;
  152.     }
  153.     public function iconThumb($width = 100, $height = 100) {
  154.         if (!$this->getIcon()) {
  155.             return '';
  156. //            return 'default_' . $width . 'x' . $height . '.png';
  157.         }
  158.         $parts = explode('.', $this->getIcon());
  159.         $extension = end($parts);
  160.         return str_replace('.' . $extension, '', $this->getIcon()) . '_thumb_' . $width . 'x' . $height . '.' . $extension;
  161.     }
  162.     public function getName(): ?string {
  163.         return $this->name;
  164.     }
  165.     public function setName(string $name): self {
  166.         $this->name = $name;
  167.         return $this;
  168.     }
  169.     public function getFullName(): ?string {
  170.         return $this->fullName;
  171.     }
  172.     public function setFullName(string $fullName): self {
  173.         $this->fullName = $fullName;
  174.         return $this;
  175.     }
  176.     public function getTeaser(): ?string {
  177.         return $this->teaser;
  178.     }
  179.     public function setTeaser(?string $teaser): self {
  180.         $this->teaser = $teaser;
  181.         return $this;
  182.     }
  183.     public function getDescription(): ?string {
  184.         return $this->description;
  185.     }
  186.     public function setDescription(?string $description): self {
  187.         $this->description = $description;
  188.         return $this;
  189.     }
  190.     public function getHasDetail(): ?bool {
  191.         return $this->hasDetail;
  192.     }
  193.     public function setHasDetail(bool $hasDetail): self {
  194.         $this->hasDetail = $hasDetail;
  195.         return $this;
  196.     }
  197.     public function getPublic(): ?bool {
  198.         return $this->public;
  199.     }
  200.     public function setPublic(?bool $public): self {
  201.         $this->public = $public;
  202.         return $this;
  203.     }
  204.     public function getSearch(): ?string {
  205.         return $this->search;
  206.     }
  207.     public function setSearch(?string $search): self {
  208.         $this->search = $search;
  209.         return $this;
  210.     }
  211.     public function getVersion(): ?int {
  212.         return $this->version;
  213.     }
  214.     public function setVersion(?int $version): self {
  215.         $this->version = $version;
  216.         return $this;
  217.     }
  218.     public function getCode(): ?string {
  219.         return $this->code;
  220.     }
  221.     public function setCode(?string $code): self {
  222.         $this->code = $code;
  223.         return $this;
  224.     }
  225.     public function getSeoId(): ?string {
  226.         return $this->seoId;
  227.     }
  228.     public function setSeoId(string $seoId): self {
  229.         $this->seoId = $seoId;
  230.         return $this;
  231.     }
  232.     public function getYear(): ?string {
  233.         return $this->year;
  234.     }
  235.     public function setYear(?string $year): self {
  236.         $this->year = $year;
  237.         return $this;
  238.     }
  239.     public function getIcon(): ?string {
  240.         return $this->icon;
  241.     }
  242.     public function setIcon(?string $icon): self {
  243.         $this->icon = $icon;
  244.         return $this;
  245.     }
  246.     public function getParams(): ?string {
  247.         return $this->params;
  248.     }
  249.     public function setParams(?string $params): self {
  250.         $this->params = $params;
  251.         return $this;
  252.     }
  253.     public function setParamsArr(?array $params): self {
  254.         $this->params = json_encode($params);
  255.         return $this;
  256.     }
  257.     public function getParamsArr(): ?array {
  258.         return json_decode($this->params, true);
  259.     }
  260.     public function getParamByKey($key, $defaultValue = null) {
  261.         $arr = $this->getParamsArr();
  262.         if (is_array($arr) && array_key_exists($key, $arr)) {
  263.             return $arr[$key];
  264.         }
  265.         return $defaultValue;
  266.     }
  267.     public function setParamByKey($key, $value): self {
  268.         $arr = $this->getParamsArr();
  269.         if (is_array($arr)) {
  270.             $arr[$key] = $value;
  271.         } else {
  272.             $arr = [$key => $value];
  273.         }
  274.         return $this->setParamsArr($arr);
  275.     }
  276.     /**
  277.      * @return Collection<int, DocumentLevel>
  278.      */
  279.     public function getDocumentLevels(): Collection {
  280.         return $this->documentLevels;
  281.     }
  282.     public function addDocumentLevel(DocumentLevel $documentLevel): self {
  283.         if (!$this->documentLevels->contains($documentLevel)) {
  284.             $this->documentLevels[] = $documentLevel;
  285.             $documentLevel->addDocument($this);
  286.         }
  287.         return $this;
  288.     }
  289.     public function removeDocumentLevel(DocumentLevel $documentLevel): self {
  290.         if ($this->documentLevels->removeElement($documentLevel)) {
  291.             $documentLevel->removeDocument($this);
  292.         }
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection<int, DocumentCategory>
  297.      */
  298.     public function getDocumentCategories(): Collection {
  299.         return $this->documentCategories;
  300.     }
  301.     public function addDocumentCategory(DocumentCategory $documentCategory): self {
  302.         if (!$this->documentCategories->contains($documentCategory)) {
  303.             $this->documentCategories[] = $documentCategory;
  304.             $documentCategory->addDocument($this);
  305.         }
  306.         return $this;
  307.     }
  308.     public function removeDocumentCategory(DocumentCategory $documentCategory): self {
  309.         if ($this->documentCategories->removeElement($documentCategory)) {
  310.             $documentCategory->removeDocument($this);
  311.         }
  312.         return $this;
  313.     }
  314.     /**
  315.      * @return Collection<int, DocumentFile>
  316.      */
  317.     public function getDocumentFiles(): Collection {
  318.         return $this->documentFiles;
  319.     }
  320.     public function addDocumentFile(DocumentFile $documentFile): self {
  321.         if (!$this->documentFiles->contains($documentFile)) {
  322.             $this->documentFiles[] = $documentFile;
  323.             $documentFile->setDocument($this);
  324.         }
  325.         return $this;
  326.     }
  327.     public function removeDocumentFile(DocumentFile $documentFile): self {
  328.         if ($this->documentFiles->removeElement($documentFile)) {
  329.             // set the owning side to null (unless already changed)
  330.             if ($documentFile->getDocument() === $this) {
  331.                 $documentFile->setDocument(null);
  332.             }
  333.         }
  334.         return $this;
  335.     }
  336.     /**
  337.      * @return Collection<int, DocumentDescription>
  338.      */
  339.     public function getDocumentDescriptions(): Collection {
  340.         return $this->documentDescriptions;
  341.     }
  342.     public function addDocumentDescription(DocumentDescription $documentDescription): self {
  343.         if (!$this->documentDescriptions->contains($documentDescription)) {
  344.             $this->documentDescriptions[] = $documentDescription;
  345.             $documentDescription->setDocument($this);
  346.         }
  347.         return $this;
  348.     }
  349.     public function removeDocumentDescription(DocumentDescription $documentDescription): self {
  350.         if ($this->documentDescriptions->removeElement($documentDescription)) {
  351.             // set the owning side to null (unless already changed)
  352.             if ($documentDescription->getDocument() === $this) {
  353.                 $documentDescription->setDocument(null);
  354.             }
  355.         }
  356.         return $this;
  357.     }
  358.     /**
  359.      * @return Collection<int, Document>
  360.      */
  361.     public function getRelevantsWithMe(): Collection {
  362.         return $this->relevantsWithMe;
  363.     }
  364.     public function addRelevantsWithMe(Document $relevantWithMe): self {
  365.         if (!$this->relevantsWithMe->contains($relevantWithMe)) {
  366.             //$this->relevantsWithMe[] = $relevantWithMe;
  367.             $relevantWithMe->addMyRelevant($this);
  368.         }
  369.         return $this;
  370.     }
  371.     public function removeRelevantsWithMe(Document $relevantWithMe): self {
  372.         if ($this->relevantsWithMe->removeElement($relevantWithMe)) {
  373.             $relevantWithMe->removeMyRelevant($this);
  374.         }
  375.         return $this;
  376.     }
  377.     /**
  378.      * @return Collection<int, Document>
  379.      */
  380.     public function getMyRelevants(): Collection {
  381.         // return $this->myRelevants;
  382.         return new ArrayCollection(
  383.             array_merge($this->myRelevants->toArray(), $this->relevantsWithMe->toArray())
  384.         );
  385.     }
  386.     public function addMyRelevant(Document $myRelevant): self {
  387.         if (!$this->myRelevants->contains($myRelevant)) {
  388.             $this->myRelevants[] = $myRelevant;
  389.             //$myRelevant->addRelevantsWithMe($this);
  390.         }
  391.         return $this;
  392.     }
  393.     public function removeMyRelevant(Document $myRelevant): self {
  394.         $this->myRelevants->removeElement($myRelevant);
  395.         $this->removeRelevantsWithMe($myRelevant);
  396.         return $this;
  397.     }
  398.     public function getExtension(): ?string {
  399.         return $this->getActualFile() && !$this->getActualFile()->getIsExternal()
  400.             ? ("." . $this->getActualFile()->getExtension())
  401.             : "";
  402.     }
  403.     public function getInfo(): ?string {
  404.         return $this->getActualFile()
  405.             ? (" (" . $this->getActualFile()->getInfo() . ")")
  406.             : "";
  407.     }
  408.     /**
  409.      * @return Collection<int, Access>
  410.      */
  411.     public function getAccesses(): Collection {
  412.         return $this->accesses;
  413.     }
  414.     public function addAccess(AccessDocument $access): self {
  415.         if (!$this->accesses->contains($access)) {
  416.             $this->accesses[] = $access;
  417.             $access->setDocument($this);
  418.         }
  419.         return $this;
  420.     }
  421.     public function removeAccess(Access $access): self {
  422.         $this->accesses->removeElement($access);
  423.         return $this;
  424.     }
  425.     /**
  426.      * @return Collection<int, BlockJointDocument>
  427.      */
  428.     public function getBlockJoints(): Collection {
  429.         return $this->blockJoints;
  430.     }
  431.     public function addBlockJoint(BlockJointDocument $blockJoint): self {
  432.         if (!$this->blockJoints->contains($blockJoint)) {
  433.             $this->blockJoints[] = $blockJoint;
  434.             $blockJoint->setDocument($this);
  435.         }
  436.         return $this;
  437.     }
  438.     public function removeBlockJoint(BlockJoint $blockJoint): self {
  439.         $this->blockJoints->removeElement($blockJoint);
  440.         return $this;
  441.     }
  442.     /**
  443.      * @return Collection<int, MetatagDocument >
  444.      */
  445.     public function getMetatags(): Collection {
  446.         return $this->metatags;
  447.     }
  448.     public function addMetatag(MetatagDocument $metatag): self {
  449.         if (!$this->metatags->contains($metatag)) {
  450.             $this->metatags[] = $metatag;
  451.             $metatag->setDocument($this);
  452.         }
  453.         return $this;
  454.     }
  455.     public function removeMetatag(MetatagDocument $metatag): self {
  456.         $this->metatags->removeElement($metatag);
  457.         return $this;
  458.     }
  459. }