''])] private string $description = ''; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])] private string $exportAlias; #[ORM\Id] #[ORM\Column(name: 'id', type: 'uuid', unique: true)] #[ORM\GeneratedValue(strategy: 'NONE')] private UuidInterface $id; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]'])] private array $options = []; #[Assert\NotBlank] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])] private string $title = ''; #[ORM\ManyToOne(targetEntity: User::class)] private User $user; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: User::class)] #[ORM\JoinTable(name: 'chill_main_saved_export_users')] private Collection $sharedWithUsers; /** * @var Collection */ #[ORM\ManyToMany(targetEntity: UserGroup::class)] #[ORM\JoinTable(name: 'chill_main_saved_export_usergroups')] private Collection $sharedWithGroups; public function __construct() { $this->id = Uuid::uuid4(); $this->sharedWithUsers = new ArrayCollection(); $this->sharedWithGroups = new ArrayCollection(); } public function getDescription(): string { return $this->description; } public function getExportAlias(): string { return $this->exportAlias; } public function getId(): UuidInterface { return $this->id; } public function getOptions(): array { return $this->options; } public function getTitle(): string { return $this->title; } public function getUser(): User { return $this->user; } public function setDescription(?string $description): SavedExport { $this->description = (string) $description; return $this; } public function setExportAlias(string $exportAlias): SavedExport { $this->exportAlias = $exportAlias; return $this; } public function setOptions(array $options): SavedExport { $this->options = $options; return $this; } public function setTitle(?string $title): SavedExport { $this->title = (string) $title; return $this; } public function setUser(User $user): SavedExport { $this->user = $user; return $this; } public function addShare(User|UserGroup $shareUser): SavedExport { if ($shareUser instanceof User) { if (!$this->sharedWithUsers->contains($shareUser)) { $this->sharedWithUsers->add($shareUser); } } else { if (!$this->sharedWithGroups->contains($shareUser)) { $this->sharedWithGroups->add($shareUser); } } return $this; } public function removeShare(User|UserGroup $shareUser): SavedExport { if ($shareUser instanceof User) { $this->sharedWithUsers->removeElement($shareUser); } else { $this->sharedWithGroups->removeElement($shareUser); } return $this; } /** * @return ReadableCollection */ public function getShare(): ReadableCollection { return new ArrayCollection([ ...$this->sharedWithUsers->toArray(), ...$this->sharedWithGroups->toArray(), ]); } /** * Return true if shared with at least one user or one group. */ public function isShared(): bool { return $this->sharedWithUsers->count() > 0 || $this->sharedWithGroups->count() > 0; } /** * Determines if the user is shared with either directly or through a group. * * @param User $user the user to check * * @return bool returns true if the user is shared with directly or via group, otherwise false */ public function isSharedWithUser(User $user): bool { if ($this->sharedWithUsers->contains($user)) { return true; } foreach ($this->sharedWithGroups as $group) { if ($group->contains($user)) { return true; } } return false; } }