<?php
namespace App\Entity;
use App\Repository\OrganisationRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Overblog\GraphQLBundle\Annotation\Field;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: OrganisationRepository::class)]
#[UniqueEntity(
fields: "uuid",
message: "This uuid is already used."
)]
class Organisation extends BasicEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
#[Field(name: "id", type: "int")]
private $id;
#[ORM\Column(type: "string", length: 50)]
#[Assert\NotBlank]
#[Field(name: "uuid", type: "string")]
private $uuid;
#[ORM\Column(type: "string", length: 255)]
#[Assert\NotBlank]
#[Field(name: "title", type: "string")]
private $title;
#[ORM\Column(type: "string", length: 255)]
#[Field(name: "website", type: "string")]
private $website;
#[ORM\Column(type: "string", length: 50)]
#[Field(name: "country", type: "string")]
private $country;
#[ORM\Column(type: "string", length: 255)]
#[Field(name: "address", type: "string")]
private $address;
#[ORM\Column(type: "string", length: 50)]
#[Field(name: "num_employees", type: "string")]
private $numEmployees;
#[ORM\ManyToOne(targetEntity: Industry::class, cascade: ["persist"])]
#[ORM\JoinColumn(nullable: false)]
#[Field(name: "industry")]
private $industry;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: BankIdentification::class, cascade: ["persist"])]
#[Field(name: "bank_identifications")]
private $bankIdentifications;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: LeakedIp::class, cascade: ["persist"])]
#[Field(name: "leaked_ips")]
private $leakedIps;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: Cryptocurrency::class, cascade: ["persist"])]
#[Field(name: "cyptocurrencys")]
private $cryptocurrencys;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: Domain::class, cascade: ["persist"])]
#[Field(name: "domains")]
private $domains;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: GitDepot::class, cascade: ["persist"])]
#[Field(name: "git_depots")]
private $gitDepots;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: ExposedIp::class)]
#[Field(name: "exposed_ips")]
private $exposedIps;
#[ORM\Column(type: "boolean")]
#[Field(name: "is_added", type: "boolean")]
private $isAdded;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: Subscription::class, cascade: ["persist"], fetch: 'EAGER')]
private $subscriptions;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: LeakedPassword::class)]
private $leakedPasswords;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: UserToNotify::class, cascade: ["persist"], orphanRemoval: true)]
#[Field(name: "users_tonotify")]
private $usersToNotify;
#[ORM\OneToMany(mappedBy: "organisation", targetEntity: CronLog::class)]
private $cronLogs;
#[ORM\Column(type: "boolean", nullable: true, options: ["default" => false])]
#[Field(name: "is_demo", type: "boolean")]
private $isDemo;
#[ORM\Column(type: "string", length: 255, nullable: true)]
#[Field(name: "avatar", type: "string")]
private $avatar;
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: "organisations", cascade: ["persist"])]
#[Field(name: "users")]
private $users;
#[ORM\Column(options: ['default' => 0])]
#[Field(name: "quota", type: "int")]
private ?int $quota = 0;
private ?int $consumedQuota = 0;
#[ORM\OneToMany(mappedBy: 'organisation', targetEntity: InternalSecurityAnswer::class, orphanRemoval: true)]
private Collection $internalSecurityAnswers;
public function __construct()
{
$this->domains = new ArrayCollection();
$this->gitDepots = new ArrayCollection();
$this->exposedSubDomains = new ArrayCollection();
$this->exposedIps = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->leakedPasswords = new ArrayCollection();
$this->usersToNotify = new ArrayCollection();
$this->cronLogs = new ArrayCollection();
$this->users = new ArrayCollection();
$this->internalSecurityAnswers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUuid(): ?string
{
return $this->uuid;
}
public function setUuid(string $uuid): self
{
$this->uuid = $uuid;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(string $website): self
{
$this->website = $website;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getNumEmployees(): ?string
{
return $this->numEmployees;
}
public function setNumEmployees(string $numEmployees): self
{
$this->numEmployees = $numEmployees;
return $this;
}
public function getIndustry(): ?Industry
{
return $this->industry;
}
public function setIndustry(?Industry $industry): self
{
$this->industry = $industry;
return $this;
}
/**
* @return Collection|Domain[]
*/
public function getDomains(): Collection
{
return $this->domains;
}
public function addDomain(Domain $domain): self
{
if (!$this->domains->contains($domain)) {
$this->domains[] = $domain;
$domain->setOrganisation($this);
}
return $this;
}
public function removeDomain(Domain $domain): self
{
if ($this->domains->removeElement($domain)) {
// set the owning side to null (unless already changed)
if ($domain->getOrganisation() === $this) {
$domain->setOrganisation(null);
}
}
return $this;
}
/**
* @return Collection|GitDepot[]
*/
public function getGitDepots(): Collection
{
return $this->gitDepots;
}
public function addGitDepot(GitDepot $gitDepot): self
{
if (!$this->gitDepots->contains($gitDepot)) {
$this->gitDepots[] = $gitDepot;
$gitDepot->setOrganisation($this);
}
return $this;
}
public function removeGitDepot(GitDepot $gitDepot): self
{
if ($this->gitDepots->removeElement($gitDepot)) {
// set the owning side to null (unless already changed)
if ($gitDepot->getOrganisation() === $this) {
$gitDepot->setOrganisation(null);
}
}
return $this;
}
/**
* @return Collection|ExposedIp[]
*/
public function getExposedIps(): Collection
{
return $this->exposedIps;
}
public function addExposedIp(ExposedIp $exposedIp): self
{
if (!$this->exposedIps->contains($exposedIp)) {
$this->exposedIps[] = $exposedIp;
$exposedIp->setOrganisation($this);
}
return $this;
}
public function removeExposedIp(ExposedIp $exposedIp): self
{
if ($this->exposedIps->removeElement($exposedIp)) {
// set the owning side to null (unless already changed)
if ($exposedIp->getOrganisation() === $this) {
$exposedIp->setOrganisation(null);
}
}
return $this;
}
public function getIsAdded(): ?bool
{
return $this->isAdded;
}
public function setIsAdded(bool $isAdded): self
{
$this->isAdded = $isAdded;
return $this;
}
/**
* @return Collection|Subscription[]
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function getSubscription(): ?Subscription
{
$actif = $this->subscriptions
->filter(function (Subscription $s) {
return $s->getIsActif();
});
return $actif->isEmpty() ? null : $actif->first();
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setOrganisation($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getOrganisation() === $this) {
$subscription->setOrganisation(null);
}
}
return $this;
}
public function __toString()
{
return $this->getTitle() ?? '';
}
/**
* @return Collection
*/
public function getLeakedPasswords(): Collection
{
return $this->leakedPasswords;
}
public function addLeakedPassword(LeakedPassword $leakedPassword): self
{
if (!$this->leakedPasswords->contains($leakedPassword)) {
$this->leakedPasswords[] = $leakedPassword;
$leakedPassword->setOrganisation($this);
}
return $this;
}
public function removeLeakedPassword(LeakedPassword $leakedPassword): self
{
if ($this->leakedPasswords->removeElement($leakedPassword)) {
// set the owning side to null (unless already changed)
if ($leakedPassword->getOrganisation() === $this) {
$leakedPassword->setOrganisation(null);
}
}
return $this;
}
/**
* @return Collection|UserToNotify[]
*/
public function getUsersToNotify(): Collection
{
return $this->usersToNotify;
}
public function addUsersToNotify(UserToNotify $usersToNotify): self
{
if (!$this->usersToNotify->contains($usersToNotify)) {
$this->usersToNotify[] = $usersToNotify;
$usersToNotify->setOrganisation($this);
}
return $this;
}
public function removeUsersToNotify(UserToNotify $usersToNotify): self
{
if ($this->usersToNotify->removeElement($usersToNotify)) {
// set the owning side to null (unless already changed)
if ($usersToNotify->getOrganisation() === $this) {
$usersToNotify->setOrganisation(null);
}
}
return $this;
}
/**
* @return Collection|CronLog[]
*/
public function getCronLogs(): Collection
{
return $this->cronLogs;
}
public function addCronLog(CronLog $cronLog): self
{
if (!$this->cronLogs->contains($cronLog)) {
$this->cronLogs[] = $cronLog;
$cronLog->setOrganisation($this);
}
return $this;
}
public function removeCronLog(CronLog $cronLog): self
{
if ($this->cronLogs->removeElement($cronLog)) {
// set the owning side to null (unless already changed)
if ($cronLog->getOrganisation() === $this) {
$cronLog->setOrganisation(null);
}
}
return $this;
}
public function getIsDemo(): ?bool
{
return $this->isDemo;
}
public function setIsDemo(?bool $isDemo): self
{
$this->isDemo = $isDemo;
return $this;
}
// public function getAvatar(): ?string
// {
// return $this->avatar;
// }
public function getAvatar(): ?string
{
$path = __DIR__.'/../../public/uploads/avatar/'.$this->avatar; // Path to the image file
if (!empty($this->avatar) && file_exists($path)) {
$type = pathinfo($path, PATHINFO_EXTENSION); // Get the file extension
$data = file_get_contents($path); // Read the file's contents
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data); // Convert to base64
return $base64; // Return the base64 encoded string
}
return null; // Return null if the file doesn't exist
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->addOrganisation($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
$user->removeOrganisation($this);
}
return $this;
}
public function getQuota(): ?int
{
return $this->quota;
}
public function setQuota(int $quota): static
{
$this->quota = $quota;
return $this;
}
public function setConsumedQuota(?int $consumedQuota): static
{
$this->consumedQuota = $consumedQuota;
return $this;
}
public function getConsumedQuota(): ?int
{
return $this->consumedQuota;
}
/**
* @return Collection<int, InternalSecurityAnswer>
*/
public function getInternalSecurityAnswers(): Collection
{
return $this->internalSecurityAnswers;
}
public function addInternalSecurityAnswer(InternalSecurityAnswer $internalSecurityAnswer): static
{
if (!$this->internalSecurityAnswers->contains($internalSecurityAnswer)) {
$this->internalSecurityAnswers->add($internalSecurityAnswer);
$internalSecurityAnswer->setOrganisation($this);
}
return $this;
}
public function removeInternalSecurityAnswer(InternalSecurityAnswer $internalSecurityAnswer): static
{
if ($this->internalSecurityAnswers->removeElement($internalSecurityAnswer)) {
// set the owning side to null (unless already changed)
if ($internalSecurityAnswer->getOrganisation() === $this) {
$internalSecurityAnswer->setOrganisation(null);
}
}
return $this;
}
}