<?php
namespace App\AtechNet\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\ORM\Mapping\OrderBy;
use Doctrine\ORM\Mapping\Table as Table;
/**
* Stock positions
*
* @Table(name="stock_position_groups")
* @Entity
*/
class StockPositionGroup extends AbstractSignedEntity
{
public const int MAIN_STOCK_GROUP_ID = 1;
public const int SERVICE_GROUP_ID = 4;
public const int PARTS_STOCK_GROUP_ID = 2;
public const int KALODA_STOCK_GROUP_ID = 9;
public const array FOR_REQUESTS = [
self::MAIN_STOCK_GROUP_ID,
self::PARTS_STOCK_GROUP_ID,
];
// private const array MAIN_STOCK_USERS = [58, 87, 94, 223, 255, 319, 330];
// private const array PARTS_STOCK_USERS = [27, 88, 261, 306];
private const array MAIN_STOCK_USERS = [];
private const array PARTS_STOCK_USERS = [];
/**
* @var string
*
* @Column(name="name", type="string", length=24)
*/
private string $name;
/**
* @var ArrayCollection
*
* @OneToMany(targetEntity="StockPosition", mappedBy="stockPositionGroup", orphanRemoval=true)
* @OrderBy({"name" = "ASC"})
**/
private $stockPositions;
public function __construct()
{
parent::__construct();
$this->stockPositions = new ArrayCollection();
}
/**
* Returns the list of group ids visible for the user of stock request screen.
* If the user is not defined in any of *_GROUP_ID list, he can view both.
*/
public static function listGroupFiltersForUser(int $userId): array
{
$return = [];
if (in_array($userId, static::MAIN_STOCK_USERS)) {
$return[] = static::MAIN_STOCK_GROUP_ID;
}
if (in_array($userId, static::PARTS_STOCK_USERS)) {
$return[] = static::PARTS_STOCK_GROUP_ID;
}
return $return;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*
* @return void
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return Collection
*/
public function getStockPositions(): Collection
{
return $this->stockPositions;
}
public function supportsRequests(): bool
{
return in_array($this->getId(), self::FOR_REQUESTS);
}
}