src/Admin/Entity/StdPages.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Admin\Entity;
  3. use App\Entity\StdPagesTracking;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\Criteria;
  8. /**
  9.  * StdPages
  10.  */
  11. #[ORM\Table(name'std_pages')]
  12. #[ORM\Index(name'fk_std_pages_std_users'columns: ['created_by'])]
  13. #[ORM\Index(name'fk_std_pages_std_users_0'columns: ['updated_by'])]
  14. #[ORM\Index(name'fk_std_pages_std_templates'columns: ['template_id'])]
  15. #[ORM\Index(name'fk_std_pages_std_content_types'columns: ['content_type'])]
  16. #[ORM\Index(name'idx_machine_name'columns: ['machine_name'])]
  17. #[ORM\Entity(repositoryClass'App\Admin\Repository\StdPagesRepository')]
  18. #[ORM\HasLifecycleCallbacks]
  19. class StdPages
  20. {
  21.     /**
  22.      * @var int
  23.      */
  24.     #[ORM\Column(name'id'type'integer'nullablefalseoptions: ['unsigned' => true'comment' => 'Page unique identifier'])]
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  27.     private $id;
  28.     /**
  29.      * @var string
  30.      */
  31.     #[ORM\Column(name'name'type'string'length100nullabletrueoptions: ['comment' => 'Page name'])]
  32.     private $name;
  33.     /**
  34.      * @var \StdContentTypes
  35.      */
  36.     #[ORM\JoinColumn(name'content_type'referencedColumnName'id')]
  37.     #[ORM\ManyToOne(targetEntity'StdContentTypes')]
  38.     private $contentType;
  39.     /**
  40.      * @var \StdTemplates|null
  41.      */
  42.     #[ORM\JoinColumn(name'template_id'referencedColumnName'id')]
  43.     #[ORM\ManyToOne(targetEntity'StdTemplates')]
  44.     private $templateId;
  45.     /**
  46.      * @var bool
  47.      */
  48.     #[ORM\Column(name'is_active'type'boolean'nullablefalseoptions: ['default' => 1'comment' => 'Flag that indicates if the page is active'])]
  49.     private $isActive '1';
  50.     #[ORM\OneToOne(mappedBy'page'targetEntityStdPagesApprovalStatus::class, cascade: ['persist''remove'])]
  51.     private ?StdPagesApprovalStatus $approvalStatus null;
  52.     /**
  53.      * @var \StdUsers
  54.      */
  55.     #[ORM\JoinColumn(name'created_by'referencedColumnName'id')]
  56.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  57.     private $createdBy;
  58.     /**
  59.      * @var \DateTime
  60.      */
  61.     #[ORM\Column(name'created_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time of the record creation'])]
  62.     private $createdDate;
  63.     /**
  64.      * @var \StdUsers
  65.      */
  66.     #[ORM\JoinColumn(name'updated_by'referencedColumnName'id')]
  67.     #[ORM\ManyToOne(targetEntity'StdUsers')]
  68.     private $updatedBy;
  69.     /**
  70.      * @var \DateTime
  71.      */
  72.     #[ORM\Column(name'updated_date'type'datetime'nullablefalseoptions: ['comment' => 'Date and time the record was last updated'])]
  73.     private $updatedDate;
  74.     /**
  75.      * @var int
  76.      */
  77.     #[ORM\Column(name'order_value'type'integer'nullabletrueoptions: ['comment' => 'Page order'])]
  78.     private $orderValue;
  79.     /**
  80.      * @var \DateTime|null
  81.      */
  82.     #[ORM\Column(name'publish_date'type'datetime'nullabletrueoptions: ['comment' => 'Date/hour when to publish page'])]
  83.     private $publishDate;
  84.     /**
  85.      * @var \DateTime|null
  86.      */
  87.     #[ORM\Column(name'expire_date'type'datetime'nullabletrueoptions: ['comment' => 'Date/time when to expire (unpublish) page'])]
  88.     private $expireDate;
  89.       /**
  90.      * @var Doctrine\Common\Collections\ArrayCollection|null
  91.      */
  92.     #[ORM\OneToMany(targetEntity'StdFavoritePagesUsers'mappedBy'pageId'cascade: ['persist''remove'], orphanRemovaltruefetch'EXTRA_LAZY')]
  93.     private $favoriteUsers;
  94.     #[ORM\JoinTable(name'std_page_web_role')]
  95.     #[ORM\JoinColumn(name'page_id'referencedColumnName'id')]
  96.     #[ORM\InverseJoinColumn(name'webrole_id'referencedColumnName'id')]
  97.     #[ORM\ManyToMany(targetEntity'StdWebRoles'inversedBy'pages'cascade: ['persist'])]
  98.     private $webroles;
  99.     /**
  100.      * @var string
  101.      */
  102.     #[ORM\Column(name'layout'type'string'length100nullabletrueoptions: ['comment' => 'Page layout'])]
  103.     private $layout;
  104.      /**
  105.      * @var Doctrine\Common\Collections\ArrayCollection|null
  106.      */
  107.     #[ORM\OneToMany(targetEntity'StdPagesContent'mappedBy'pageId'cascade: ['persist''remove'], orphanRemovaltrue)]
  108.     private $pagesContent;
  109.     #[ORM\OneToMany(mappedBy'page'targetEntityStdPagesTag::class, cascade: ['persist''remove'], orphanRemovaltruefetch'EAGER')]
  110.     private Collection $tags;
  111.     #[ORM\Column(name:'machine_name'type:'string'length255nullabletrue)]
  112.     private ?string $machineName null;
  113.     /**
  114.      * @var bool
  115.      */
  116.     #[ORM\Column(name'include_sitemap'type'boolean'nullablefalseoptions: ['default' => 1'comment' => 'Flag that indicates if the page is to be included in Sitemap'])]
  117.     private $includeSitemap '1';
  118.     #[ORM\OneToMany(mappedBy'pageId'targetEntityStdPagesPages::class)]
  119.     private Collection $relations;
  120.     #[ORM\OneToMany(mappedBy'page'targetEntityStdPagesTracking::class, cascade: ['persist''remove'])]
  121.     private Collection $trackings;
  122.     /**
  123.      * @var Collection<int, StdUsers>
  124.      */
  125.     #[ORM\ManyToMany(targetEntityStdUsers::class, inversedBy'authoredPages')]
  126.     #[ORM\JoinTable(name'std_pages_authors')]
  127.     private Collection $pageAuthors;
  128.     public function __construct()
  129.     {
  130.         $this->webroles = new ArrayCollection();
  131.         $this->pagesContent = new ArrayCollection();
  132.         $this->trackings = new ArrayCollection();
  133.         $this->relations = new ArrayCollection();
  134.         $this->tags = new ArrayCollection();
  135.         $this->pageAuthors = new ArrayCollection();
  136.     }
  137.     public function getId(): ?int
  138.     {
  139.         return $this->id;
  140.     }
  141.     public function getName(): ?string
  142.     {
  143.         return $this->name;
  144.     }
  145.     public function setName(string $name): self
  146.     {
  147.         $this->name $name;
  148.         return $this;
  149.     }
  150.     public function getContentType(): ?StdContentTypes
  151.     {
  152.         return $this->contentType;
  153.     }
  154.     public function setContentType(StdContentTypes $contentType): self
  155.     {
  156.         $this->contentType $contentType;
  157.         return $this;
  158.     }
  159.     public function getTemplateId(): ?StdTemplates
  160.     {
  161.         return $this->templateId;
  162.     }
  163.     public function setTemplateId(?StdTemplates $templateId): self
  164.     {
  165.         $this->templateId $templateId;
  166.         return $this;
  167.     }
  168.     public function getIsActive(): ?bool
  169.     {
  170.         return $this->isActive;
  171.     }
  172.     public function setIsActive(bool $isActive): self
  173.     {
  174.         $this->isActive $isActive;
  175.         return $this;
  176.     }
  177.     public function getCreatedDate(): ?\DateTimeInterface
  178.     {
  179.         return $this->createdDate;
  180.     }
  181.     public function setCreatedDate(\DateTimeInterface $createdDate): self
  182.     {
  183.         $this->createdDate $createdDate;
  184.         return $this;
  185.     }
  186.     public function getUpdatedDate(): ?\DateTimeInterface
  187.     {
  188.         return $this->updatedDate;
  189.     }
  190.     public function setUpdatedDate(\DateTimeInterface $updatedDate): self
  191.     {
  192.         $this->updatedDate $updatedDate;
  193.         return $this;
  194.     }
  195.     public function getCreatedBy(): ?StdUsers
  196.     {
  197.         return $this->createdBy;
  198.     }
  199.     public function setCreatedBy(?StdUsers $createdBy): self
  200.     {
  201.         $this->createdBy $createdBy;
  202.         return $this;
  203.     }
  204.     public function getUpdatedBy(): ?StdUsers
  205.     {
  206.         return $this->updatedBy;
  207.     }
  208.     public function setUpdatedBy(?StdUsers $updatedBy): self
  209.     {
  210.         $this->updatedBy $updatedBy;
  211.         return $this;
  212.     }
  213.     public function getOrderValue(): ?int
  214.     {
  215.         return $this->orderValue;
  216.     }
  217.     public function setOrderValue(?int $orderValue): self
  218.     {
  219.         $this->orderValue $orderValue;
  220.         return $this;
  221.     }
  222.     public function getPublishDate(): ?\DateTimeInterface
  223.     {
  224.         return $this->publishDate;
  225.     }
  226.     public function setPublishDate(\DateTimeInterface $publishDate): self
  227.     {
  228.         $this->publishDate $publishDate;
  229.         return $this;
  230.     }
  231.     public function getLayout(): ?string
  232.     {
  233.         return $this->layout;
  234.     }
  235.     public function setLayout(?string $layout): self
  236.     {
  237.         $this->layout $layout;
  238.         return $this;
  239.     }
  240.     public function getExpireDate(): ?\DateTimeInterface
  241.     {
  242.         return $this->expireDate;
  243.     }
  244.     public function setExpireDate(?\DateTimeInterface $expireDate): self
  245.     {
  246.         $this->expireDate $expireDate;
  247.         return $this;
  248.     }
  249.     public function addRole(StdWebRoles $webroles): self
  250.     {
  251.         $this->webroles[] = $webroles;
  252.  
  253.         return $this;
  254.     }
  255.  
  256.     public function removeRole(StdWebRoles $webroles): bool
  257.     {
  258.         return $this->webroles->removeElement($webroles);
  259.     }
  260.  
  261.     public function getRoles(): Collection
  262.     {
  263.         return $this->webroles;
  264.     }
  265.     public function getRolesByNames(array $names): ?Collection
  266.     {
  267.         $criteria Criteria::create()
  268.             ->where(Criteria::expr()->in("name"$names));
  269.         return $this->getRoles()->matching($criteria);
  270.     }
  271.     #[ORM\PreUpdate]
  272.     public function setUpdated()
  273.     {
  274.         $this->setUpdatedDate(new \DateTime());
  275.     }
  276.     
  277.     #[ORM\PrePersist]
  278.     public function setCreated()
  279.     {
  280.         $this->setUpdatedDate(new \DateTime());
  281.         $this->setCreatedDate(new \DateTime());
  282.     }
  283.     public function __toString() {
  284.         return $this->name;
  285.     }
  286.     /**
  287.      * @return Collection|StdPagesContent[]
  288.      */
  289.     public function getPagesContent(): ?Collection
  290.     {
  291.         return $this->pagesContent;
  292.     }
  293.     public function removePagesContent(StdPagesContent $pagescontent): self
  294.     {
  295.         if ($this->pagesContent->contains($pagescontent)) {
  296.             $this->pagesContent->removeElement($pagescontent);
  297.             // set the owning side to null (unless already changed)
  298.             if ($pagescontent->getPageId() === $this) {
  299.                 $pagescontent->setPageId(null);
  300.             }
  301.         }
  302.         return $this;
  303.     }
  304.     public function addPagesContent(StdPagesContent $pagescontent): self
  305.     {
  306.         if (!$this->pagesContent->contains($pagescontent)) {
  307.             $this->pagesContent[] = $pagescontent;
  308.             $pagescontent->setPageId($this);
  309.         }
  310.         return $this;
  311.     }
  312.     /**
  313.      * @return StdPagesContent
  314.      */
  315.     public function getLocalizedContents(StdLanguages $locale): ?StdPagesContent
  316.     {
  317.         $criteria Criteria::create()
  318.         ->where(Criteria::expr()->eq("languageCode"$locale))
  319.         ->setMaxResults(1);
  320.         if($this->getPagesContent()){
  321.             $contents $this->getPagesContent()->matching($criteria);
  322.             if(count($contents)){
  323.                 $contents array_values($contents->toArray());
  324.                 return $contents[0];
  325.             }else{
  326.                 return null;
  327.             }
  328.         }else{
  329.             return null;
  330.         }
  331.     }
  332.     public function getMachineName(): ?string
  333.     {
  334.         return $this->machineName;
  335.     }
  336.     public function setMachineName(?string $machineName): self
  337.     {
  338.         $this->machineName $machineName;
  339.         return $this;
  340.     }
  341.     public function getIncludeSitemap(): ?bool
  342.     {
  343.         return $this->includeSitemap;
  344.     }
  345.     public function setIncludeSitemap(bool $includeSitemap): self
  346.     {
  347.         $this->includeSitemap $includeSitemap;
  348.         return $this;
  349.     }
  350.     public function addTag(StdPagesTag $tag): self
  351.     {
  352.         if (!$this->tags->contains($tag)) {
  353.             $this->tags[] = $tag;
  354.             $tag->setPage($this);
  355.         }
  356.         return $this;
  357.     }
  358.     public function removeTag(StdPagesTag $tag): self
  359.     {
  360.         if ($this->tags->removeElement($tag)) {
  361.             if ($tag->getDomainValue() === $this) {
  362.                 $tag->setDomainValue(null);
  363.             }
  364.         }
  365.         return $this;
  366.     }
  367.     public function getTags(): Collection {
  368.         return $this->tags;
  369.     }
  370.     public function addTracking(StdPagesTracking $tracking): static
  371.     {
  372.         if (!$this->trackings->contains($tracking)) {
  373.             $this->trackings[] = $tracking;
  374.             $tracking->setPage($this);
  375.         }
  376.         return $this;
  377.     }
  378.     public function removeTracking(StdPagesTracking $tracking): static
  379.     {
  380.         if ($this->trackings->removeElement($tracking)) {
  381.             if ($tracking->getPage() === $this) {
  382.                 $tracking->setPage(null);
  383.             }
  384.         }
  385.         return $this;
  386.     }
  387.     public function getApprovalStatus(): ?StdPagesApprovalStatus
  388.     {
  389.         return $this->approvalStatus;
  390.     }
  391.     public function setApprovalStatus(?StdPagesApprovalStatus $approvalStatus): void
  392.     {
  393.         $this->approvalStatus $approvalStatus;
  394.         if ($approvalStatus !== null && $approvalStatus->getPage() !== $this) {
  395.             $approvalStatus->setPage($this);
  396.         }
  397.     }
  398.     public function getRelations(): Collection
  399.     {
  400.         return $this->relations;
  401.     }
  402.     public function setRelations(Collection $relations): void
  403.     {
  404.         $this->relations $relations;
  405.     }
  406.     /**
  407.      * @return Collection<int, StdUsers>
  408.      */
  409.     public function getPageAuthors(): Collection
  410.     {
  411.         return $this->pageAuthors;
  412.     }
  413.     public function addPageAuthors(array $users) {
  414.         foreach ($users as $user) {
  415.             if ($user instanceof StdUsers && !$this->pageAuthors->contains($user)) {
  416.                 $this->pageAuthors->add($user);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     public function addPageAuthor(StdUsers $user): self
  422.     {
  423.         if (!$this->pageAuthors->contains($user)) {
  424.             $this->pageAuthors->add($user);
  425.         }
  426.         return $this;
  427.     }
  428.     public function removePageAuthor(StdUsers $user): self
  429.     {
  430.         $this->pageAuthors->removeElement($user);
  431.         return $this;
  432.     }
  433. }