src/Entity/UserServiceAccess.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserServiceAccessRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * KULLANICI <-> SERVIS erisim kaydi.
  10.  *
  11.  * KAYDIN YOKLUGU DA BIR ANLAM TASIR — bu tablonun en kritik ozelligi budur:
  12.  *   kayit yok  -> servisin is_default degeri gecerlidir (ERP: acik, digerleri: kapali)
  13.  *   granted=0  -> ACIKCA YASAK (ERP'ye bile giremez)
  14.  *   granted=1  -> ACIKCA IZINLI
  15.  *
  16.  * Yani "izin = satir varligi" DEGILDIR; bu yuzden granted BOOLEAN tutulur (kullanici
  17.  * karari 2026-08-21). Aksi halde bir kullaniciya ERP'yi KAPATMAK mumkun olmazdi.
  18.  *
  19.  * (user, service) cifti benzersizdir — bir kullanicinin bir servis icin tek karari olur.
  20.  *
  21.  * @ORM\Entity(repositoryClass=UserServiceAccessRepository::class)
  22.  * @ORM\Table(
  23.  *     name="user_service_access",
  24.  *     uniqueConstraints={
  25.  *         @ORM\UniqueConstraint(name="uniq_user_service", columns={"user_id", "service_id"})
  26.  *     }
  27.  * )
  28.  * @ORM\HasLifecycleCallbacks
  29.  */
  30. class UserServiceAccess
  31. {
  32.     /**
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue
  35.      * @ORM\Column(type="integer")
  36.      * @Groups({
  37.      *     "user_service_access@ref",
  38.      *     "user_service_access@base",
  39.      *     "user_service_access@core"
  40.      * })
  41.      */
  42.     private $id;
  43.     /**
  44.      * Kullanici bazli OZELLIK haklari (AI Hub: model_picker, voice_mode ...). Satir yok = hak yok.
  45.      * @ORM\OneToMany(targetEntity=UserServiceFeature::class, mappedBy="user_service_access", cascade={"persist", "remove"}, orphanRemoval=true)
  46.      */
  47.     private $features;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="service_accesses")
  50.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  51.      * @Groups({
  52.      *     "user_service_access@user"
  53.      * })
  54.      */
  55.     private $user;
  56.     /**
  57.      * @ORM\ManyToOne(targetEntity=Services::class, inversedBy="user_accesses")
  58.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  59.      * @Groups({
  60.      *     "user_service_access@base",
  61.      *     "user_service_access@core"
  62.      * })
  63.      */
  64.     private $service;
  65.     /**
  66.      * Acik karar: true = erisir, false = ERISEMEZ (servis default acik olsa bile).
  67.      * @ORM\Column(type="boolean", nullable=false, options={"default": false})
  68.      * @Groups({
  69.      *     "user_service_access@base",
  70.      *     "user_service_access@core"
  71.      * })
  72.      */
  73.     private $granted = false;
  74.     /**
  75.      * @ORM\Column(type="datetime_immutable", nullable=true)
  76.      * @Groups({
  77.      *     "user_service_access@core"
  78.      * })
  79.      */
  80.     private $created_at;
  81.     /**
  82.      * @ORM\Column(type="datetime_immutable", nullable=true)
  83.      * @Groups({
  84.      *     "user_service_access@core"
  85.      * })
  86.      */
  87.     private $updated_at;
  88.     /**
  89.      * @ORM\PrePersist
  90.      */
  91.     public function onPrePersist(): void
  92.     {
  93.         if ($this->created_at === null) {
  94.             $this->created_at = new \DateTimeImmutable();
  95.         }
  96.         $this->updated_at = new \DateTimeImmutable();
  97.     }
  98.     /**
  99.      * @ORM\PreUpdate
  100.      */
  101.     public function onPreUpdate(): void
  102.     {
  103.         $this->updated_at = new \DateTimeImmutable();
  104.     }
  105.     public function __construct()
  106.     {
  107.         $this->features = new ArrayCollection();
  108.     }
  109.     public function getId(): ?int
  110.     {
  111.         return $this->id;
  112.     }
  113.     public function getUser(): ?User
  114.     {
  115.         return $this->user;
  116.     }
  117.     public function setUser(?User $user): self
  118.     {
  119.         $this->user = $user;
  120.         return $this;
  121.     }
  122.     public function getService(): ?Services
  123.     {
  124.         return $this->service;
  125.     }
  126.     public function setService(?Services $service): self
  127.     {
  128.         $this->service = $service;
  129.         return $this;
  130.     }
  131.     public function getGranted(): ?bool
  132.     {
  133.         return $this->granted;
  134.     }
  135.     public function setGranted(bool $granted): self
  136.     {
  137.         $this->granted = $granted;
  138.         return $this;
  139.     }
  140.     public function getCreatedAt(): ?\DateTimeImmutable
  141.     {
  142.         return $this->created_at;
  143.     }
  144.     public function setCreatedAt(?\DateTimeImmutable $created_at): self
  145.     {
  146.         $this->created_at = $created_at;
  147.         return $this;
  148.     }
  149.     public function getUpdatedAt(): ?\DateTimeImmutable
  150.     {
  151.         return $this->updated_at;
  152.     }
  153.     public function setUpdatedAt(?\DateTimeImmutable $updated_at): self
  154.     {
  155.         $this->updated_at = $updated_at;
  156.         return $this;
  157.     }
  158.     /** @return Collection<int, UserServiceFeature> */
  159.     public function getFeatures(): Collection
  160.     {
  161.         return $this->features;
  162.     }
  163.     public function addFeature(UserServiceFeature $feature): self
  164.     {
  165.         if (!$this->features->contains($feature)) {
  166.             $this->features[] = $feature;
  167.             $feature->setUserServiceAccess($this);
  168.         }
  169.         return $this;
  170.     }
  171. }