src/Entity/Services.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ServicesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * SERVIS — ERP ile birlikte yasayan, kendi giris yuzeyi olan uygulama.
  11.  *
  12.  * MODUL DEGILDIR: modul (Expense, WorksPlan, TodoBoard...) ERP'nin ICINDE bir parcadir
  13.  * ve yetkisi ModulesAccessMap uzerinden yonetilir. SERVIS ise ERP'nin YANINDA duran
  14.  * ayri bir uygulamadir (ornegin execution.romon-erp.com) — ayni kimlik/veri dunyasini
  15.  * paylasir ama kendi kapisi vardir.
  16.  *
  17.  * ERISIM KURALI (tek cumle): erisim = kullanicinin bu servis icin kaydi VARSA o kaydin
  18.  * granted degeri, kaydi YOKSA servisin is_default degeri. Yani:
  19.  *   - is_default=1 (ERP)  + kayit yok        -> ERISIR   (default acik)
  20.  *   - is_default=1 (ERP)  + granted=false    -> ERISEMEZ (acikca yasaklanmis)
  21.  *   - is_default=0 (TE)   + kayit yok        -> ERISEMEZ (default kapali)
  22.  *   - is_default=0 (TE)   + granted=true     -> ERISIR
  23.  * Bkz. UserServiceAccess.
  24.  *
  25.  * is_system=1 olan kayit (ERP/'self') SILINEMEZ ve service_key'i DEGISTIRILEMEZ —
  26.  * BE guard'i bunu zorlar, FE de sil/duzenle butonunu kapatir.
  27.  *
  28.  * @ORM\Entity(repositoryClass=ServicesRepository::class)
  29.  * @ORM\Table(name="services")
  30.  * @ORM\HasLifecycleCallbacks
  31.  * @UniqueEntity(
  32.  *      fields={"service_key"},
  33.  *      message="Service key already exists|Service with key (%s) already exists"
  34.  * )
  35.  */
  36. class Services
  37. {
  38.     /**
  39.      * @ORM\Id
  40.      * @ORM\GeneratedValue
  41.      * @ORM\Column(type="integer")
  42.      * @Groups({
  43.      *     "service@ref",
  44.      *     "service@base",
  45.      *     "service@core"
  46.      * })
  47.      */
  48.     private $id;
  49.     /**
  50.      * Kodun tanidigi benzersiz anahtar ('self', 'task_execution'...).
  51.      * VARCHAR — gercek ENUM DEGIL, cunku servisler ileride panelden eklenebilecek.
  52.      * Bilinen degerler: App\Enum\ServiceKeyEnum.
  53.      *
  54.      * @ORM\Column(type="string", length=64, unique=true, nullable=false)
  55.      * @Groups({
  56.      *     "service@base",
  57.      *     "service@core"
  58.      * })
  59.      */
  60.     private $service_key;
  61.     /**
  62.      * Kullaniciya gosterilen ad ("ERP", "Task Execution").
  63.      * @ORM\Column(type="string", length=128, nullable=false)
  64.      * @Groups({
  65.      *     "service@base",
  66.      *     "service@core"
  67.      * })
  68.      */
  69.     private $name;
  70.     /**
  71.      * Servisin ne oldugunu anlatan kisa metin — yonetim panelinde gosterilir.
  72.      * @ORM\Column(type="text", nullable=true)
  73.      * @Groups({
  74.      *     "service@core"
  75.      * })
  76.      */
  77.     private $description;
  78.     /**
  79.      * Servisin acilis adresi (ERP icin null, ayri servisler icin subdomain).
  80.      * @ORM\Column(type="string", length=255, nullable=true)
  81.      * @Groups({
  82.      *     "service@core"
  83.      * })
  84.      */
  85.     private $url;
  86.     /**
  87.      * TRUE ise: bu servis icin KAYDI OLMAYAN kullanici otomatik erisir (ERP boyle).
  88.      * FALSE ise: erisim icin acik kayit (granted=true) sart (Task Execution boyle).
  89.      * Default'un TEK kaynagi property default'udur.
  90.      *
  91.      * @ORM\Column(type="boolean", nullable=false, options={"default": false})
  92.      * @Groups({
  93.      *     "service@base",
  94.      *     "service@core"
  95.      * })
  96.      */
  97.     private $is_default = false;
  98.     /**
  99.      * Sistem servisi — silinemez, service_key'i degistirilemez. Yalniz ERP ('self') 1'dir.
  100.      * @ORM\Column(type="boolean", nullable=false, options={"default": false})
  101.      * @Groups({
  102.      *     "service@base",
  103.      *     "service@core"
  104.      * })
  105.      */
  106.     private $is_system = false;
  107.     /**
  108.      * Pasif servis kimseye acilmaz (is_default olsa bile) — servisi topluca kapatma anahtari.
  109.      * @ORM\Column(type="boolean", nullable=false, options={"default": true})
  110.      * @Groups({
  111.      *     "service@base",
  112.      *     "service@core"
  113.      * })
  114.      */
  115.     private $is_active = true;
  116.     /**
  117.      * Listeleme sirasi — ERP her zaman 0.
  118.      * @ORM\Column(type="integer", nullable=false, options={"default": 0})
  119.      * @Groups({
  120.      *     "service@core"
  121.      * })
  122.      */
  123.     private $sort_order = 0;
  124.     /**
  125.      * @ORM\Column(type="datetime_immutable", nullable=true)
  126.      * @Groups({
  127.      *     "service@core"
  128.      * })
  129.      */
  130.     private $created_at;
  131.     /**
  132.      * @ORM\OneToMany(targetEntity=UserServiceAccess::class, mappedBy="service", orphanRemoval=true)
  133.      */
  134.     private $user_accesses;
  135.     public function __construct()
  136.     {
  137.         $this->user_accesses = new ArrayCollection();
  138.     }
  139.     /**
  140.      * @ORM\PrePersist
  141.      */
  142.     public function onPrePersist(): void
  143.     {
  144.         if ($this->created_at === null) {
  145.             $this->created_at = new \DateTimeImmutable();
  146.         }
  147.     }
  148.     public function getId(): ?int
  149.     {
  150.         return $this->id;
  151.     }
  152.     public function getServiceKey(): ?string
  153.     {
  154.         return $this->service_key;
  155.     }
  156.     public function setServiceKey(string $service_key): self
  157.     {
  158.         $this->service_key = $service_key;
  159.         return $this;
  160.     }
  161.     public function getName(): ?string
  162.     {
  163.         return $this->name;
  164.     }
  165.     public function setName(string $name): self
  166.     {
  167.         $this->name = $name;
  168.         return $this;
  169.     }
  170.     public function getDescription(): ?string
  171.     {
  172.         return $this->description;
  173.     }
  174.     public function setDescription(?string $description): self
  175.     {
  176.         $this->description = $description;
  177.         return $this;
  178.     }
  179.     public function getUrl(): ?string
  180.     {
  181.         return $this->url;
  182.     }
  183.     public function setUrl(?string $url): self
  184.     {
  185.         $this->url = $url;
  186.         return $this;
  187.     }
  188.     public function getIsDefault(): ?bool
  189.     {
  190.         return $this->is_default;
  191.     }
  192.     public function setIsDefault(bool $is_default): self
  193.     {
  194.         $this->is_default = $is_default;
  195.         return $this;
  196.     }
  197.     public function getIsSystem(): ?bool
  198.     {
  199.         return $this->is_system;
  200.     }
  201.     public function setIsSystem(bool $is_system): self
  202.     {
  203.         $this->is_system = $is_system;
  204.         return $this;
  205.     }
  206.     public function getIsActive(): ?bool
  207.     {
  208.         return $this->is_active;
  209.     }
  210.     public function setIsActive(bool $is_active): self
  211.     {
  212.         $this->is_active = $is_active;
  213.         return $this;
  214.     }
  215.     public function getSortOrder(): ?int
  216.     {
  217.         return $this->sort_order;
  218.     }
  219.     public function setSortOrder(int $sort_order): self
  220.     {
  221.         $this->sort_order = $sort_order;
  222.         return $this;
  223.     }
  224.     public function getCreatedAt(): ?\DateTimeImmutable
  225.     {
  226.         return $this->created_at;
  227.     }
  228.     public function setCreatedAt(?\DateTimeImmutable $created_at): self
  229.     {
  230.         $this->created_at = $created_at;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return Collection<int, UserServiceAccess>
  235.      */
  236.     public function getUserAccesses(): Collection
  237.     {
  238.         return $this->user_accesses;
  239.     }
  240.     public function addUserAccess(UserServiceAccess $userAccess): self
  241.     {
  242.         if (!$this->user_accesses->contains($userAccess)) {
  243.             $this->user_accesses[] = $userAccess;
  244.             $userAccess->setService($this);
  245.         }
  246.         return $this;
  247.     }
  248.     public function removeUserAccess(UserServiceAccess $userAccess): self
  249.     {
  250.         if ($this->user_accesses->removeElement($userAccess)) {
  251.             if ($userAccess->getService() === $this) {
  252.                 $userAccess->setService(null);
  253.             }
  254.         }
  255.         return $this;
  256.     }
  257. }