src/Entity/Organisation.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OrganisationRepository;
  4. use DateTimeImmutable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Overblog\GraphQLBundle\Annotation\Field;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. #[ORM\Entity(repositoryClassOrganisationRepository::class)]
  12. #[UniqueEntity(
  13.     fields"uuid",
  14.     message"This uuid is already used."
  15. )]
  16. class Organisation extends BasicEntity
  17. {
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column(type"integer")]
  21.     #[Field(name"id"type"int")]
  22.     private $id;
  23.     #[ORM\Column(type"string"length50)]
  24.     #[Assert\NotBlank]
  25.     #[Field(name"uuid"type"string")]
  26.     private $uuid;
  27.     #[ORM\Column(type"string"length255)]
  28.     #[Assert\NotBlank]
  29.     #[Field(name"title"type"string")]
  30.     private $title;
  31.     #[ORM\Column(type"string"length255)]
  32.     #[Field(name"website"type"string")]
  33.     private $website;
  34.     #[ORM\Column(type"string"length50)]
  35.     #[Field(name"country"type"string")]
  36.     private $country;
  37.     #[ORM\Column(type"string"length255)]
  38.     #[Field(name"address"type"string")]
  39.     private $address;
  40.     #[ORM\Column(type"string"length50)]
  41.     #[Field(name"num_employees"type"string")]
  42.     private $numEmployees;
  43.     #[ORM\ManyToOne(targetEntityIndustry::class, cascade: ["persist"])]
  44.     #[ORM\JoinColumn(nullablefalse)]
  45.     #[Field(name"industry")]
  46.     private $industry;
  47.     #[ORM\OneToMany(mappedBy"organisation"targetEntityBankIdentification::class, cascade: ["persist"])]
  48.     #[Field(name"bank_identifications")]
  49.     private $bankIdentifications;
  50.     #[ORM\OneToMany(mappedBy"organisation"targetEntityLeakedIp::class, cascade: ["persist"])]
  51.     #[Field(name"leaked_ips")]
  52.     private $leakedIps;
  53.     #[ORM\OneToMany(mappedBy"organisation"targetEntityCryptocurrency::class, cascade: ["persist"])]
  54.     #[Field(name"cyptocurrencys")]
  55.     private $cryptocurrencys;
  56.     #[ORM\OneToMany(mappedBy"organisation"targetEntityDomain::class, cascade: ["persist"])]
  57.     #[Field(name"domains")]
  58.     private $domains;
  59.     #[ORM\OneToMany(mappedBy"organisation"targetEntityGitDepot::class, cascade: ["persist"])]
  60.     #[Field(name"git_depots")]
  61.     private $gitDepots;
  62.     #[ORM\OneToMany(mappedBy"organisation"targetEntityExposedIp::class)]
  63.     #[Field(name"exposed_ips")]
  64.     private $exposedIps;
  65.     #[ORM\Column(type"boolean")]
  66.     #[Field(name"is_added"type"boolean")]
  67.     private $isAdded;
  68.     #[ORM\OneToMany(mappedBy"organisation"targetEntitySubscription::class, cascade: ["persist"], fetch'EAGER')]
  69.     private $subscriptions;
  70.     #[ORM\OneToMany(mappedBy"organisation"targetEntityLeakedPassword::class)]
  71.     private $leakedPasswords;
  72.     #[ORM\OneToMany(mappedBy"organisation"targetEntityUserToNotify::class, cascade: ["persist"], orphanRemovaltrue)]
  73.     #[Field(name"users_tonotify")]
  74.     private $usersToNotify;
  75.     #[ORM\OneToMany(mappedBy"organisation"targetEntityCronLog::class)]
  76.     private $cronLogs;
  77.     #[ORM\Column(type"boolean"nullabletrueoptions: ["default" => false])]
  78.     #[Field(name"is_demo"type"boolean")]
  79.     private $isDemo;
  80.     #[ORM\Column(type"string"length255nullabletrue)]
  81.     #[Field(name"avatar"type"string")]
  82.     private $avatar;
  83.     #[ORM\ManyToMany(targetEntityUser::class, mappedBy"organisations"cascade: ["persist"])]
  84.     #[Field(name"users")]
  85.     private $users;
  86.     #[ORM\Column(options: ['default' => 0])]
  87.     #[Field(name"quota"type"int")]
  88.     private ?int $quota 0;
  89.     private ?int $consumedQuota 0;
  90.     #[ORM\OneToMany(mappedBy'organisation'targetEntityInternalSecurityAnswer::class, orphanRemovaltrue)]
  91.     private Collection $internalSecurityAnswers;
  92.     public function __construct()
  93.     {
  94.         $this->domains = new ArrayCollection();
  95.         $this->gitDepots = new ArrayCollection();
  96.         $this->exposedSubDomains = new ArrayCollection();
  97.         $this->exposedIps = new ArrayCollection();
  98.         $this->subscriptions = new ArrayCollection();
  99.         $this->leakedPasswords = new ArrayCollection();
  100.         $this->usersToNotify = new ArrayCollection();
  101.         $this->cronLogs = new ArrayCollection();
  102.         $this->users = new ArrayCollection();
  103.         $this->internalSecurityAnswers = new ArrayCollection();
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function getUuid(): ?string
  110.     {
  111.         return $this->uuid;
  112.     }
  113.     public function setUuid(string $uuid): self
  114.     {
  115.         $this->uuid $uuid;
  116.         return $this;
  117.     }
  118.     public function getTitle(): ?string
  119.     {
  120.         return $this->title;
  121.     }
  122.     public function setTitle(string $title): self
  123.     {
  124.         $this->title $title;
  125.         return $this;
  126.     }
  127.     public function getWebsite(): ?string
  128.     {
  129.         return $this->website;
  130.     }
  131.     public function setWebsite(string $website): self
  132.     {
  133.         $this->website $website;
  134.         return $this;
  135.     }
  136.     public function getCountry(): ?string
  137.     {
  138.         return $this->country;
  139.     }
  140.     public function setCountry(string $country): self
  141.     {
  142.         $this->country $country;
  143.         return $this;
  144.     }
  145.     public function getAddress(): ?string
  146.     {
  147.         return $this->address;
  148.     }
  149.     public function setAddress(string $address): self
  150.     {
  151.         $this->address $address;
  152.         return $this;
  153.     }
  154.     public function getNumEmployees(): ?string
  155.     {
  156.         return $this->numEmployees;
  157.     }
  158.     public function setNumEmployees(string $numEmployees): self
  159.     {
  160.         $this->numEmployees $numEmployees;
  161.         return $this;
  162.     }
  163.     public function getIndustry(): ?Industry
  164.     {
  165.         return $this->industry;
  166.     }
  167.     public function setIndustry(?Industry $industry): self
  168.     {
  169.         $this->industry $industry;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection|Domain[]
  174.      */
  175.     public function getDomains(): Collection
  176.     {
  177.         return $this->domains;
  178.     }
  179.     public function addDomain(Domain $domain): self
  180.     {
  181.         if (!$this->domains->contains($domain)) {
  182.             $this->domains[] = $domain;
  183.             $domain->setOrganisation($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeDomain(Domain $domain): self
  188.     {
  189.         if ($this->domains->removeElement($domain)) {
  190.             // set the owning side to null (unless already changed)
  191.             if ($domain->getOrganisation() === $this) {
  192.                 $domain->setOrganisation(null);
  193.             }
  194.         }
  195.         return $this;
  196.     }
  197.     /**
  198.      * @return Collection|GitDepot[]
  199.      */
  200.     public function getGitDepots(): Collection
  201.     {
  202.         return $this->gitDepots;
  203.     }
  204.     public function addGitDepot(GitDepot $gitDepot): self
  205.     {
  206.         if (!$this->gitDepots->contains($gitDepot)) {
  207.             $this->gitDepots[] = $gitDepot;
  208.             $gitDepot->setOrganisation($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeGitDepot(GitDepot $gitDepot): self
  213.     {
  214.         if ($this->gitDepots->removeElement($gitDepot)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($gitDepot->getOrganisation() === $this) {
  217.                 $gitDepot->setOrganisation(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return Collection|ExposedIp[]
  224.      */
  225.     public function getExposedIps(): Collection
  226.     {
  227.         return $this->exposedIps;
  228.     }
  229.     public function addExposedIp(ExposedIp $exposedIp): self
  230.     {
  231.         if (!$this->exposedIps->contains($exposedIp)) {
  232.             $this->exposedIps[] = $exposedIp;
  233.             $exposedIp->setOrganisation($this);
  234.         }
  235.         return $this;
  236.     }
  237.     public function removeExposedIp(ExposedIp $exposedIp): self
  238.     {
  239.         if ($this->exposedIps->removeElement($exposedIp)) {
  240.             // set the owning side to null (unless already changed)
  241.             if ($exposedIp->getOrganisation() === $this) {
  242.                 $exposedIp->setOrganisation(null);
  243.             }
  244.         }
  245.         return $this;
  246.     }
  247.     public function getIsAdded(): ?bool
  248.     {
  249.         return $this->isAdded;
  250.     }
  251.     public function setIsAdded(bool $isAdded): self
  252.     {
  253.         $this->isAdded $isAdded;
  254.         return $this;
  255.     }
  256.     /**
  257.      * @return Collection|Subscription[]
  258.      */
  259.     public function getSubscriptions(): Collection
  260.     {
  261.         return $this->subscriptions;
  262.     }
  263.     public function getSubscription(): ?Subscription
  264.     {
  265.         $actif $this->subscriptions
  266.             ->filter(function (Subscription $s) {
  267.                 return $s->getIsActif();
  268.             });
  269.         return $actif->isEmpty() ? null $actif->first();
  270.     }
  271.     public function addSubscription(Subscription $subscription): self
  272.     {
  273.         if (!$this->subscriptions->contains($subscription)) {
  274.             $this->subscriptions[] = $subscription;
  275.             $subscription->setOrganisation($this);
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeSubscription(Subscription $subscription): self
  280.     {
  281.         if ($this->subscriptions->removeElement($subscription)) {
  282.             // set the owning side to null (unless already changed)
  283.             if ($subscription->getOrganisation() === $this) {
  284.                 $subscription->setOrganisation(null);
  285.             }
  286.         }
  287.         return $this;
  288.     }
  289.     public function __toString()
  290.     {
  291.         return $this->getTitle() ?? '';
  292.     }
  293.     /**
  294.      * @return Collection
  295.      */
  296.     public function getLeakedPasswords(): Collection
  297.     {
  298.         return $this->leakedPasswords;
  299.     }
  300.     public function addLeakedPassword(LeakedPassword $leakedPassword): self
  301.     {
  302.         if (!$this->leakedPasswords->contains($leakedPassword)) {
  303.             $this->leakedPasswords[] = $leakedPassword;
  304.             $leakedPassword->setOrganisation($this);
  305.         }
  306.         return $this;
  307.     }
  308.     public function removeLeakedPassword(LeakedPassword $leakedPassword): self
  309.     {
  310.         if ($this->leakedPasswords->removeElement($leakedPassword)) {
  311.             // set the owning side to null (unless already changed)
  312.             if ($leakedPassword->getOrganisation() === $this) {
  313.                 $leakedPassword->setOrganisation(null);
  314.             }
  315.         }
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return Collection|UserToNotify[]
  320.      */
  321.     public function getUsersToNotify(): Collection
  322.     {
  323.         return $this->usersToNotify;
  324.     }
  325.     public function addUsersToNotify(UserToNotify $usersToNotify): self
  326.     {
  327.         if (!$this->usersToNotify->contains($usersToNotify)) {
  328.             $this->usersToNotify[] = $usersToNotify;
  329.             $usersToNotify->setOrganisation($this);
  330.         }
  331.         return $this;
  332.     }
  333.     public function removeUsersToNotify(UserToNotify $usersToNotify): self
  334.     {
  335.         if ($this->usersToNotify->removeElement($usersToNotify)) {
  336.             // set the owning side to null (unless already changed)
  337.             if ($usersToNotify->getOrganisation() === $this) {
  338.                 $usersToNotify->setOrganisation(null);
  339.             }
  340.         }
  341.         return $this;
  342.     }
  343.     /**
  344.      * @return Collection|CronLog[]
  345.      */
  346.     public function getCronLogs(): Collection
  347.     {
  348.         return $this->cronLogs;
  349.     }
  350.     public function addCronLog(CronLog $cronLog): self
  351.     {
  352.         if (!$this->cronLogs->contains($cronLog)) {
  353.             $this->cronLogs[] = $cronLog;
  354.             $cronLog->setOrganisation($this);
  355.         }
  356.         return $this;
  357.     }
  358.     public function removeCronLog(CronLog $cronLog): self
  359.     {
  360.         if ($this->cronLogs->removeElement($cronLog)) {
  361.             // set the owning side to null (unless already changed)
  362.             if ($cronLog->getOrganisation() === $this) {
  363.                 $cronLog->setOrganisation(null);
  364.             }
  365.         }
  366.         return $this;
  367.     }
  368.     public function getIsDemo(): ?bool
  369.     {
  370.         return $this->isDemo;
  371.     }
  372.     public function setIsDemo(?bool $isDemo): self
  373.     {
  374.         $this->isDemo $isDemo;
  375.         return $this;
  376.     }
  377.     // public function getAvatar(): ?string
  378.     // {
  379.     //     return $this->avatar;
  380.     // }
  381.     public function getAvatar(): ?string
  382.     {
  383.         $path __DIR__.'/../../public/uploads/avatar/'.$this->avatar// Path to the image file
  384.         if (!empty($this->avatar) && file_exists($path)) {
  385.             $type pathinfo($pathPATHINFO_EXTENSION); // Get the file extension
  386.             $data file_get_contents($path); // Read the file's contents
  387.             $base64 'data:image/' $type ';base64,' base64_encode($data); // Convert to base64
  388.             return $base64// Return the base64 encoded string
  389.         }
  390.         return null// Return null if the file doesn't exist
  391.     }
  392.     public function setAvatar(?string $avatar): self
  393.     {
  394.         $this->avatar $avatar;
  395.         return $this;
  396.     }
  397.     /**
  398.      * @return Collection<int, User>
  399.      */
  400.     public function getUsers(): Collection
  401.     {
  402.         return $this->users;
  403.     }
  404.     public function addUser(User $user): self
  405.     {
  406.         if (!$this->users->contains($user)) {
  407.             $this->users[] = $user;
  408.             $user->addOrganisation($this);
  409.         }
  410.         return $this;
  411.     }
  412.     public function removeUser(User $user): self
  413.     {
  414.         if ($this->users->removeElement($user)) {
  415.             $user->removeOrganisation($this);
  416.         }
  417.         return $this;
  418.     }
  419.     public function getQuota(): ?int
  420.     {
  421.         return $this->quota;
  422.     }
  423.     public function setQuota(int $quota): static
  424.     {
  425.         $this->quota $quota;
  426.         return $this;
  427.     }
  428.     public function setConsumedQuota(?int $consumedQuota): static
  429.     {
  430.         $this->consumedQuota $consumedQuota;
  431.         return $this;
  432.     }
  433.     public function getConsumedQuota(): ?int
  434.     {
  435.         return $this->consumedQuota;
  436.     }
  437.     /**
  438.      * @return Collection<int, InternalSecurityAnswer>
  439.      */
  440.     public function getInternalSecurityAnswers(): Collection
  441.     {
  442.         return $this->internalSecurityAnswers;
  443.     }
  444.     public function addInternalSecurityAnswer(InternalSecurityAnswer $internalSecurityAnswer): static
  445.     {
  446.         if (!$this->internalSecurityAnswers->contains($internalSecurityAnswer)) {
  447.             $this->internalSecurityAnswers->add($internalSecurityAnswer);
  448.             $internalSecurityAnswer->setOrganisation($this);
  449.         }
  450.         return $this;
  451.     }
  452.     public function removeInternalSecurityAnswer(InternalSecurityAnswer $internalSecurityAnswer): static
  453.     {
  454.         if ($this->internalSecurityAnswers->removeElement($internalSecurityAnswer)) {
  455.             // set the owning side to null (unless already changed)
  456.             if ($internalSecurityAnswer->getOrganisation() === $this) {
  457.                 $internalSecurityAnswer->setOrganisation(null);
  458.             }
  459.         }
  460.         return $this;
  461.     }
  462. }