src/Entity/Nav.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\NavRepository;
  5. use ApiPlatform\Core\Annotation\ApiFilter;
  6. use App\Entity\Traits\TimestampableEntity;
  7. use Doctrine\Common\Collections\Collection;
  8. use ApiPlatform\Core\Annotation\ApiProperty;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use App\Entity\Interfaces\OrderMappedInterface;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use App\Entity\Interfaces\ContainerMappedInterface;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  16. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  17. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  18. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  19. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  20. /**
  21.  * @ApiResource(
  22.  *      attributes={"filters"={"translation.groups"}},
  23.  *      normalizationContext={"groups"={"Nav:Read"}, "skip_null_values"=false},
  24.  *      denormalizationContext={"groups"={"Nav:Write"}},
  25.  *      collectionOperations={
  26.  *          "get"={
  27.  *              "pagination_use_output_walkers"=true,
  28.  *              "security"="is_granted('ROLE_OPERATOR')"
  29.  *          },
  30.  *          "get_app_nav"={
  31.  *              "route_name"="api_app_navs_get_app_nav_collection",
  32.  *              "method"="GET",
  33.  *              "pagination_enabled"=false,
  34.  *              "normalization_context"={"groups"={"NavApp:Read"}, "skip_null_values"=false},
  35.  *          },
  36.  *          "post"={
  37.  *              "security"="is_granted('ROLE_OPERATOR')"
  38.  *          },
  39.  *          "post_copy_to_app"={
  40.  *              "route_name"="api_navs_copy_to_app_collection",
  41.  *              "method"="POST",
  42.  *              "denormalization_context"={"groups"={"Nav:CopyToApp"}},
  43.  *              "security"="is_granted('ROLE_OPERATOR')"
  44.  *          },
  45.  *      },
  46.  *      itemOperations={
  47.  *          "get"={"security"="is_granted('IS_CO_OPR', object)"},
  48.  *          "put"={"security"="is_granted('IS_CO_OPR', object)"},
  49.  *          "patch"={"security"="is_granted('IS_CO_OPR', object)"},
  50.  *          "patch_change_ord"={
  51.  *              "path"="/navs/{id}/change-ord",
  52.  *              "method"="PATCH",
  53.  *              "denormalization_context"={"groups"={"Nav:ChangeOrd"}},
  54.  *              "security"="is_granted('IS_CO_OPR', object)"
  55.  *          },
  56.  *          "delete"={"security"="is_granted('IS_CO_OPR', object)"}
  57.  *     }
  58.  * )
  59.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "container.id": "exact", "parent.id": "exact", "type": "exact", "url": "partial", "translations.title": "partial"})
  60.  * @ApiFilter(BooleanFilter::class, properties={"isActive", "isWeb", "isApp"})
  61.  * @ApiFilter(OrderFilter::class, properties={"ord": "ASC", "translations.title", "id"})
  62.  * @ORM\Entity(repositoryClass=NavRepository::class)
  63.  */
  64. class Nav extends AbstractTranslatable implements ContainerMappedInterfaceOrderMappedInterface
  65. {
  66.     /**
  67.      * Hook timestampable behavior
  68.      * updates createdAt, updatedAt fields
  69.      */
  70.     use TimestampableEntity;
  71.     /**
  72.      * @ORM\OneToMany(targetEntity="NavTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
  73.      *
  74.      * @Groups({"Nav:Write", "NavTranslationGroup"})
  75.      * @Assert\Valid()
  76.      */
  77.     protected $translations;
  78.     /**
  79.      * @Groups({"Nav:Read", "NavApp:Read"})
  80.      */
  81.     private $title;
  82.     /**
  83.      * @Groups({"Nav:Read", "NavApp:Read"})
  84.      */
  85.     private $externalUrl;
  86.     /**
  87.      * @ORM\Id
  88.      * @ORM\GeneratedValue
  89.      * @ORM\Column(type="integer")
  90.      * @Groups({"Nav:Read", "NavApp:Read"})
  91.      */
  92.     private $id;
  93.     /**
  94.      * @ORM\Column(type="string", length=32)
  95.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  96.      */
  97.     private $type;
  98.     public const TYPE_INTERNAL "INTERNAL";
  99.     public const TYPE_INFO_PAGE "INFO_PAGE";
  100.     public const TYPE_EXTERNAL "EXTERNAL";
  101.     /**
  102.      * @ORM\Column(type="string", length=255, nullable=true)
  103.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  104.      */
  105.     private $url;
  106.     /**
  107.      * @ORM\Column(type="string", length=32, nullable=true)
  108.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  109.      */
  110.     private $icon;
  111.     /**
  112.      * @ORM\Column(type="array", nullable=true)
  113.      * @Groups({"Nav:Read", "Nav:Write"})
  114.      */
  115.     private $roles = [];
  116.     /**
  117.      * @ORM\Column(type="boolean", nullable=true)
  118.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  119.      */
  120.     private $isOptionInNewWindow;
  121.     /**
  122.      * @ORM\Column(type="boolean", nullable=true)
  123.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  124.      */
  125.     private $isActive;
  126.     /**
  127.      * @ORM\ManyToOne(targetEntity=Container::class)
  128.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  129.      * @Groups({"Nav:Write"})
  130.      */
  131.     private $container;
  132.     /**
  133.      * @ORM\ManyToOne(targetEntity=Nav::class, inversedBy="children")
  134.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  135.      * @ApiProperty(readableLink=false, writableLink=false)
  136.      * @Groups({"Nav:Read", "Nav:Write"})
  137.      */
  138.     private $parent;
  139.     /**
  140.      * @ORM\OneToMany(targetEntity=Nav::class, mappedBy="parent")
  141.      * @Groups({"Nav:Read", "NavApp:Read"})
  142.      */
  143.     private $children;
  144.     /**
  145.      * @ORM\Column(type="integer", nullable=true)
  146.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  147.      */
  148.     private $ord;
  149.     /**
  150.      * @Groups({"Nav:ChangeOrd"})
  151.      */
  152.     private int $newOrd;
  153.     private $ordChangeDirection;
  154.     /**
  155.      * @ORM\Column(type="boolean", nullable=true)
  156.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  157.      */
  158.     private $isWeb;
  159.     /**
  160.      * @ORM\Column(type="boolean", nullable=true)
  161.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  162.      */
  163.     private $isApp;
  164.     /**
  165.      * @ORM\ManyToMany(targetEntity=UserGroup::class, inversedBy="navs")
  166.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  167.      */
  168.     private $userGroups;
  169.     /**
  170.      * @ORM\Column(type="string", length=32, nullable=true)
  171.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  172.      */
  173.     private $newsfeedPostType;
  174.     /**
  175.      * @ORM\ManyToMany(targetEntity=CommonCategory::class)
  176.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  177.      */
  178.     private $newsfeedCategories;
  179.     /**
  180.      * @ORM\ManyToMany(targetEntity=NewsfeedTag::class)
  181.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  182.      */
  183.     private $newsfeedTags;
  184.     /**
  185.      * @ORM\Column(type="boolean", nullable=true)
  186.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  187.      */
  188.     private $isExcludeCategory;
  189.     /**
  190.      * @ORM\Column(type="boolean", nullable=true)
  191.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  192.      */
  193.     private $isExcludeTag;
  194.     /**
  195.      * @ORM\Column(type="array", nullable=true)
  196.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  197.      */
  198.     private $excludeNewsfeedCategories = [];
  199.     /**
  200.      * @ORM\Column(type="array", nullable=true)
  201.      * @Groups({"Nav:Read", "Nav:Write", "NavApp:Read"})
  202.      */
  203.     private $excludeNewsfeedTags = [];
  204.     /**
  205.      * @Groups({"Nav:CopyToApp"})
  206.      */
  207.     private int $copyId;
  208.     protected function createTranslation(): TranslationInterface
  209.     {
  210.         return new NavTranslation();
  211.     }
  212.     public function getTitle(): ?string
  213.     {
  214.         return $this->getTranslation()->getTitle();
  215.     }
  216.     public function setTitle(string $title): self
  217.     {
  218.         $this->getTranslation()->setTitle($title);
  219.         return $this;
  220.     }
  221.     public function getExternalUrl(): ?string
  222.     {
  223.         return $this->getTranslation()->getExternalUrl();
  224.     }
  225.     public function setExternalUrl(string $externalUrl): self
  226.     {
  227.         $this->getTranslation()->setExternalUrl($externalUrl);
  228.         return $this;
  229.     }
  230.     public function __construct()
  231.     {
  232.         parent::__construct();
  233.         $this->children = new ArrayCollection();
  234.         $this->userGroups = new ArrayCollection();
  235.         $this->newsfeedCategories = new ArrayCollection();
  236.         $this->newsfeedTags = new ArrayCollection();
  237.     }
  238.     public function getId(): ?int
  239.     {
  240.         return $this->id;
  241.     }
  242.     public function getType(): ?string
  243.     {
  244.         return $this->type;
  245.     }
  246.     public function setType(string $type): self
  247.     {
  248.         $this->type $type;
  249.         return $this;
  250.     }
  251.     public function getUrl(): ?string
  252.     {
  253.         return $this->url;
  254.     }
  255.     public function setUrl(?string $url): self
  256.     {
  257.         $this->url $url;
  258.         return $this;
  259.     }
  260.     public function getIcon(): ?string
  261.     {
  262.         return $this->icon;
  263.     }
  264.     public function setIcon(?string $icon): self
  265.     {
  266.         $this->icon $icon;
  267.         return $this;
  268.     }
  269.     public function getRoles(): ?array
  270.     {
  271.         return $this->roles;
  272.     }
  273.     public function setRoles(?array $roles): self
  274.     {
  275.         $this->roles $roles;
  276.         return $this;
  277.     }
  278.     public function getIsOptionInNewWindow(): ?bool
  279.     {
  280.         return $this->isOptionInNewWindow;
  281.     }
  282.     public function setIsOptionInNewWindow(?bool $isOptionInNewWindow): self
  283.     {
  284.         $this->isOptionInNewWindow $isOptionInNewWindow;
  285.         return $this;
  286.     }
  287.     public function getIsActive(): ?bool
  288.     {
  289.         return $this->isActive;
  290.     }
  291.     public function setIsActive(?bool $isActive): self
  292.     {
  293.         $this->isActive $isActive;
  294.         return $this;
  295.     }
  296.     public function getContainer(): ?Container
  297.     {
  298.         return $this->container;
  299.     }
  300.     public function setContainer(?Container $container): self
  301.     {
  302.         $this->container $container;
  303.         return $this;
  304.     }
  305.     public function getParent(): ?self
  306.     {
  307.         return $this->parent;
  308.     }
  309.     public function setParent(?self $parent): self
  310.     {
  311.         $this->parent $parent;
  312.         return $this;
  313.     }
  314.     /**
  315.      * @return Collection<int, self>
  316.      */
  317.     public function getChildren(): Collection
  318.     {
  319.         return $this->children;
  320.     }
  321.     public function addChild(self $child): self
  322.     {
  323.         if (!$this->children->contains($child)) {
  324.             $this->children[] = $child;
  325.             $child->setParent($this);
  326.         }
  327.         return $this;
  328.     }
  329.     public function removeChild(self $child): self
  330.     {
  331.         if ($this->children->removeElement($child)) {
  332.             // set the owning side to null (unless already changed)
  333.             if ($child->getParent() === $this) {
  334.                 $child->setParent(null);
  335.             }
  336.         }
  337.         return $this;
  338.     }
  339.     public function getOrd(): ?int
  340.     {
  341.         return $this->ord;
  342.     }
  343.     public function setOrd(?int $ord): self
  344.     {
  345.         $this->ord $ord;
  346.         return $this;
  347.     }
  348.     public function getOrdParents(): array
  349.     {
  350.         return [
  351.             'container' => $this->getContainer(),
  352.             'parent' => $this->getParent(),
  353.             'isWeb' => $this->getIsWeb()
  354.         ];
  355.     }
  356.     public function getOrdChangeDirection()
  357.     {
  358.         return $this->ordChangeDirection;
  359.     }
  360.     public function getNewOrd(): int
  361.     {
  362.         return $this->newOrd ?? 0;
  363.     }
  364.     public function setNewOrd(int $newOrd): self
  365.     {
  366.         $oldOrd $this->ord;
  367.         $this->newOrd $newOrd;
  368.         $this->ord $newOrd;
  369.         $this->ordChangeDirection = ($this->newOrd $oldOrd) ? 'desc' 'asc';
  370.         return $this;
  371.     }
  372.     public function getIsWeb(): ?bool
  373.     {
  374.         return $this->isWeb;
  375.     }
  376.     public function setIsWeb(?bool $isWeb): self
  377.     {
  378.         if ($isWeb) {
  379.             $this->setIsApp(!$isWeb);
  380.         }
  381.         $this->isWeb $isWeb;
  382.         return $this;
  383.     }
  384.     public function getIsApp(): ?bool
  385.     {
  386.         return $this->isApp;
  387.     }
  388.     public function setIsApp(?bool $isApp): self
  389.     {
  390.         if ($isApp) {
  391.             $this->setIsWeb(!$isApp);
  392.         }
  393.         $this->isApp $isApp;
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection<int, UserGroup>
  398.      */
  399.     public function getUserGroups(): Collection
  400.     {
  401.         return $this->userGroups;
  402.     }
  403.     public function addUserGroup(UserGroup $userGroup): self
  404.     {
  405.         if (!$this->userGroups->contains($userGroup)) {
  406.             $this->userGroups[] = $userGroup;
  407.         }
  408.         return $this;
  409.     }
  410.     public function removeUserGroup(UserGroup $userGroup): self
  411.     {
  412.         $this->userGroups->removeElement($userGroup);
  413.         return $this;
  414.     }
  415.     public function removeAllUserGroups(): self
  416.     {
  417.         foreach ($this->userGroups as $userGroup) {
  418.             $this->removeUserGroup($userGroup);
  419.         }
  420.         return $this;
  421.     }
  422.     public function getNewsfeedPostType(): ?string
  423.     {
  424.         return $this->newsfeedPostType;
  425.     }
  426.     public function setNewsfeedPostType(?string $newsfeedPostType): self
  427.     {
  428.         $this->newsfeedPostType $newsfeedPostType;
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return Collection<int, CommonCategory>
  433.      */
  434.     public function getNewsfeedCategories(): Collection
  435.     {
  436.         return $this->newsfeedCategories;
  437.     }
  438.     public function addNewsfeedCategory(CommonCategory $newsfeedCategory): self
  439.     {
  440.         if (!$this->newsfeedCategories->contains($newsfeedCategory)) {
  441.             $this->newsfeedCategories[] = $newsfeedCategory;
  442.         }
  443.         return $this;
  444.     }
  445.     public function removeNewsfeedCategory(CommonCategory $newsfeedCategory): self
  446.     {
  447.         $this->newsfeedCategories->removeElement($newsfeedCategory);
  448.         return $this;
  449.     }
  450.     /**
  451.      * @return Collection<int, NewsfeedTag>
  452.      */
  453.     public function getNewsfeedTags(): Collection
  454.     {
  455.         return $this->newsfeedTags;
  456.     }
  457.     public function addNewsfeedTag(NewsfeedTag $newsfeedTag): self
  458.     {
  459.         if (!$this->newsfeedTags->contains($newsfeedTag)) {
  460.             $this->newsfeedTags[] = $newsfeedTag;
  461.         }
  462.         return $this;
  463.     }
  464.     public function removeNewsfeedTag(NewsfeedTag $newsfeedTag): self
  465.     {
  466.         $this->newsfeedTags->removeElement($newsfeedTag);
  467.         return $this;
  468.     }
  469.     public function getIsExcludeCategory(): ?bool
  470.     {
  471.         return $this->isExcludeCategory;
  472.     }
  473.     public function setIsExcludeCategory(?bool $isExcludeCategory): self
  474.     {
  475.         $this->isExcludeCategory $isExcludeCategory;
  476.         return $this;
  477.     }
  478.     public function getIsExcludeTag(): ?bool
  479.     {
  480.         return $this->isExcludeTag;
  481.     }
  482.     public function setIsExcludeTag(?bool $isExcludeTag): self
  483.     {
  484.         $this->isExcludeTag $isExcludeTag;
  485.         return $this;
  486.     }
  487.     public function getExcludeNewsfeedCategories(): ?array
  488.     {
  489.         return $this->excludeNewsfeedCategories;
  490.     }
  491.     public function setExcludeNewsfeedCategories(?array $excludeNewsfeedCategories): self
  492.     {
  493.         $this->excludeNewsfeedCategories $excludeNewsfeedCategories;
  494.         return $this;
  495.     }
  496.     public function getExcludeNewsfeedTags(): ?array
  497.     {
  498.         return $this->excludeNewsfeedTags;
  499.     }
  500.     public function setExcludeNewsfeedTags(?array $excludeNewsfeedTags): self
  501.     {
  502.         $this->excludeNewsfeedTags $excludeNewsfeedTags;
  503.         return $this;
  504.     }
  505.     /**
  506.      * Get the value of copyId
  507.      */
  508.     public function getCopyId()
  509.     {
  510.         return $this->copyId;
  511.     }
  512.     /**
  513.      * Set the value of copyId
  514.      *
  515.      * @return  self
  516.      */
  517.     public function setCopyId($copyId)
  518.     {
  519.         $this->copyId $copyId;
  520.         return $this;
  521.     }
  522. }