vendor/bluue/stocks-bundle/src/Entity/Warehouse.php line 56

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Léo BANNHOLTZER (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\StocksBundle\Entity;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
  11. use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
  12. use App\Entity\User;
  13. use Bluue\StocksBundle\Repository\WarehouseRepository;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Uid\Uuid;
  18. use Gedmo\Mapping\Annotation as Gedmo;
  19. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  20. use Symfony\Component\Serializer\Annotation\Groups;
  21. /**
  22.  * @ApiResource(
  23.  *  formats={"json"},
  24.  *  security="is_granted('ROLE__STOCKS__SMALL_ADMIN')",
  25.  *  normalizationContext={"groups"= {"getWarehouse"}},
  26.  *  denormalizationContext={"groups"={"writeWarehouse"}},
  27.  *  itemOperations={
  28.  *      "get",
  29.  *      "get_locations"={
  30.  *          "method"="GET",
  31.  *          "path"="/warehouse/{id}/locations",
  32.  *          "normalization_context"={"groups"={"getLocations"}}
  33.  *      },
  34.  *      "get_sub_locations"={
  35.  *          "method"="GET",
  36.  *          "path"="/warehouse/{id}/subLocations",
  37.  *          "normalization_context"={"groups"={"getSubLocations"}}
  38.  *      }
  39.  *  }
  40.  * )
  41.  * @ORM\Entity(repositoryClass=WarehouseRepository::class)
  42.  * @ORM\Table(name="stocks_bundle__warehouse",
  43.  *  indexes={
  44.  *    @ORM\Index(name="name", columns={"name"}),
  45.  *    @ORM\Index(name="deleted_at", columns={"deleted_at"}),
  46.  *    @ORM\Index(name="created_at", columns={"created_at"}),
  47.  *    @ORM\Index(name="updated_at", columns={"updated_at"})
  48.  * })
  49.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
  50.  */
  51. class Warehouse
  52. {
  53.     use UserTimestampableEntity;
  54.     use UserSoftDeleteableEntity;
  55.     /**
  56.      * @ORM\Id
  57.      * @ORM\Column(type="uuid")
  58.      * @ORM\GeneratedValue(strategy="CUSTOM")
  59.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  60.      * @Groups({"getWarehouse", "getLocations", "getSubLocations"})
  61.      */
  62.     private ?Uuid $id null;
  63.     /**
  64.      * @ORM\Column(type="string", length=50)
  65.      * @Groups({"getWarehouse", "getLocations", "getSubLocations", "writeWarehouse"})
  66.      */
  67.     private ?string $name;
  68.     /**
  69.      * @ORM\ManyToOne(targetEntity=Location::class, fetch="EXTRA_LAZY")
  70.      */
  71.     private ?Location $defaultLocation null;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity=SubLocation::class, fetch="EXTRA_LAZY")
  74.      */
  75.     private ?SubLocation $defaultSubLocation null;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=Location::class, mappedBy="warehouse", fetch="EXTRA_LAZY")
  78.      * @Groups({"getLocations", "getSubLocations"})
  79.      */
  80.     private Collection $locations;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=StockProduct::class, mappedBy="warehouse", fetch="EXTRA_LAZY")
  83.      */
  84.     private Collection $stockProducts;
  85.     /**
  86.      * @ORM\ManyToMany(targetEntity=User::class, fetch="EXTRA_LAZY")
  87.      * @ORM\JoinTable(
  88.      *     name="stocks_bundle__warehouse_user",
  89.      *     joinColumns={@ORM\JoinColumn(name="warehouse_id", referencedColumnName="id")},
  90.      *     inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
  91.      * )
  92.      */
  93.     private Collection $users;
  94.     public function __construct()
  95.     {
  96.         $this->locations = new ArrayCollection();
  97.         $this->stockProducts = new ArrayCollection();
  98.         $this->users = new ArrayCollection();
  99.     }
  100.     public function getId(): ?Uuid
  101.     {
  102.         return $this->id;
  103.     }
  104.     public function getName(): ?string
  105.     {
  106.         return $this->name;
  107.     }
  108.     public function setName(string $name): self
  109.     {
  110.         $this->name $name;
  111.         return $this;
  112.     }
  113.     public function addLocation(Location $location): self
  114.     {
  115.         if (!$this->locations->contains($location)) {
  116.             $this->locations[] = $location;
  117.             $location->setWarehouse($this);
  118.         }
  119.         return $this;
  120.     }
  121.     /**
  122.      * @return Collection|Location[]
  123.      */
  124.     public function getLocations(): Collection
  125.     {
  126.         return $this->locations;
  127.     }
  128.     public function removeLocation(Location $location): self
  129.     {
  130.         if ($this->locations->removeElement($location)) {
  131.             if ($location->getWarehouse() === $this) {
  132.                 $location->setWarehouse(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function addStockProduct(StockProduct $stockProduct): self
  138.     {
  139.         if (!$this->stockProducts->contains($stockProduct)) {
  140.             $this->stockProducts[] = $stockProduct;
  141.             $stockProduct->setWarehouse($this);
  142.         }
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection|StockProduct[]
  147.      */
  148.     public function getStockProducts(): Collection
  149.     {
  150.         return $this->stockProducts;
  151.     }
  152.     public function removeStockProduct(StockProduct $stockProduct): self
  153.     {
  154.         if ($this->stockProducts->removeElement($stockProduct)) {
  155.             if ($stockProduct->getWarehouse() === $this) {
  156.                 $stockProduct->setWarehouse(null);
  157.             }
  158.         }
  159.         return $this;
  160.     }
  161.     public function getUsers(): Collection
  162.     {
  163.         return $this->users;
  164.     }
  165.     public function addUser(User $user): self
  166.     {
  167.         if (!$this->users->contains($user)) {
  168.             $this->users[] = $user;
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeUser(User $user): self
  173.     {
  174.         $this->users->removeElement($user);
  175.         return $this;
  176.     }
  177.     /**
  178.      * @return Location|null
  179.      */
  180.     public function getDefaultLocation(): ?Location
  181.     {
  182.         return $this->defaultLocation;
  183.     }
  184.     /**
  185.      * @param Location|null $defaultLocation
  186.      * @return Warehouse
  187.      */
  188.     public function setDefaultLocation(?Location $defaultLocation): self
  189.     {
  190.         $this->defaultLocation $defaultLocation;
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return SubLocation|null
  195.      */
  196.     public function getDefaultSubLocation(): ?SubLocation
  197.     {
  198.         return $this->defaultSubLocation;
  199.     }
  200.     /**
  201.      * @param SubLocation|null $defaultSubLocation
  202.      * @return Warehouse
  203.      */
  204.     public function setDefaultSubLocation(?SubLocation $defaultSubLocation): self
  205.     {
  206.         $this->defaultSubLocation $defaultSubLocation;
  207.         return $this;
  208.     }
  209. }