src/AtechNet/CoreBundle/Entity/StockPositionGroup.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\AtechNet\CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping\Column;
  6. use Doctrine\ORM\Mapping\Entity;
  7. use Doctrine\ORM\Mapping\OneToMany;
  8. use Doctrine\ORM\Mapping\OrderBy;
  9. use Doctrine\ORM\Mapping\Table as Table;
  10. /**
  11.  * Stock positions
  12.  *
  13.  * @Table(name="stock_position_groups")
  14.  * @Entity
  15.  */
  16. class StockPositionGroup extends AbstractSignedEntity
  17. {
  18.     public const int MAIN_STOCK_GROUP_ID = 1;
  19.     public const int SERVICE_GROUP_ID = 4;
  20.     public const int PARTS_STOCK_GROUP_ID = 2;
  21.     public const int KALODA_STOCK_GROUP_ID = 9;
  22.     public const array FOR_REQUESTS = [
  23.         self::MAIN_STOCK_GROUP_ID,
  24.         self::PARTS_STOCK_GROUP_ID,
  25.     ];
  26.     //    private const array MAIN_STOCK_USERS = [58, 87, 94, 223, 255, 319, 330];
  27.     //    private const array PARTS_STOCK_USERS = [27, 88, 261, 306];
  28.     private const array MAIN_STOCK_USERS = [];
  29.     private const array PARTS_STOCK_USERS = [];
  30.     /**
  31.      * @var string
  32.      *
  33.      * @Column(name="name", type="string", length=24)
  34.      */
  35.     private string $name;
  36.     /**
  37.      * @var ArrayCollection
  38.      *
  39.      * @OneToMany(targetEntity="StockPosition", mappedBy="stockPositionGroup", orphanRemoval=true)
  40.      * @OrderBy({"name" = "ASC"})
  41.      **/
  42.     private $stockPositions;
  43.     public function __construct()
  44.     {
  45.         parent::__construct();
  46.         $this->stockPositions = new ArrayCollection();
  47.     }
  48.     /**
  49.      *  Returns the list of group ids visible for the user of stock request screen.
  50.      *  If the user is not defined in any of *_GROUP_ID list, he can view both.
  51.      */
  52.     public static function listGroupFiltersForUser(int $userId): array
  53.     {
  54.         $return = [];
  55.         if (in_array($userId, static::MAIN_STOCK_USERS)) {
  56.             $return[] = static::MAIN_STOCK_GROUP_ID;
  57.         }
  58.         if (in_array($userId, static::PARTS_STOCK_USERS)) {
  59.             $return[] = static::PARTS_STOCK_GROUP_ID;
  60.         }
  61.         return $return;
  62.     }
  63.     /**
  64.      * @return string
  65.      */
  66.     public function getName(): string
  67.     {
  68.         return $this->name;
  69.     }
  70.     /**
  71.      * @param string $name
  72.      *
  73.      * @return void
  74.      */
  75.     public function setName(string $name): void
  76.     {
  77.         $this->name = $name;
  78.     }
  79.     /**
  80.      * @return Collection
  81.      */
  82.     public function getStockPositions(): Collection
  83.     {
  84.         return $this->stockPositions;
  85.     }
  86.     public function supportsRequests(): bool
  87.     {
  88.         return in_array($this->getId(), self::FOR_REQUESTS);
  89.     }
  90. }