parent
7f23b2c1b9
commit
2580ebb364
@ -1,137 +0,0 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Entity; |
||||
|
||||
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity; |
||||
use Doctrine\Common\Collections\ArrayCollection; |
||||
use Doctrine\Common\Collections\Collection; |
||||
use Doctrine\ORM\Mapping as ORM; |
||||
|
||||
#[ORM\Table(name: 'agenda_event_invitation')] |
||||
#[ORM\Entity()] |
||||
#[ORM\InheritanceType('SINGLE_TABLE')] |
||||
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')] |
||||
#[ORM\DiscriminatorMap([ |
||||
'invitation' => 'Chamilo\CoreBundle\Entity\AgendaEventInvitation', |
||||
'subscription' => 'Chamilo\CoreBundle\Entity\AgendaEventSubscription', |
||||
])] |
||||
class AgendaEventInvitation |
||||
{ |
||||
use TimestampableTypedEntity; |
||||
|
||||
#[ORM\Id] |
||||
#[ORM\Column(type: 'integer')] |
||||
#[ORM\GeneratedValue(strategy: 'AUTO')] |
||||
protected ?int $id = null; |
||||
|
||||
#[ORM\OneToMany( |
||||
mappedBy: 'invitation', |
||||
targetEntity: AgendaEventInvitee::class, |
||||
cascade: ['persist', 'remove'], |
||||
orphanRemoval: true |
||||
)] |
||||
protected Collection $invitees; |
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'resourceNodes')] |
||||
#[ORM\JoinColumn(name: 'creator_id', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')] |
||||
protected User $creator; |
||||
|
||||
public function __construct() |
||||
{ |
||||
$this->invitees = new ArrayCollection(); |
||||
} |
||||
|
||||
public function getId(): ?int |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function getInvitees(): Collection |
||||
{ |
||||
return $this->invitees; |
||||
} |
||||
|
||||
public function setInvitees(Collection $invitees): self |
||||
{ |
||||
$this->invitees = $invitees; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function addInvitee(AgendaEventInvitee $invitee): self |
||||
{ |
||||
$invitee->setInvitation($this); |
||||
$this->invitees->add($invitee); |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function removeInviteeUser(User $user): self |
||||
{ |
||||
/** @var AgendaEventInvitee $invitee */ |
||||
$invitee = $this |
||||
->invitees |
||||
->filter(function (AgendaEventInvitee $invitee) use ($user) { |
||||
return $invitee->getUser() === $user; |
||||
}) |
||||
->first() |
||||
; |
||||
|
||||
if ($invitee) { |
||||
$this->invitees->removeElement($invitee); |
||||
$invitee->setInvitation(null); |
||||
} |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function removeInvitees(): self |
||||
{ |
||||
$this->invitees = new ArrayCollection(); |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getCreator(): User |
||||
{ |
||||
return $this->creator; |
||||
} |
||||
|
||||
public function setCreator(User $creator): self |
||||
{ |
||||
$this->creator = $creator; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function hasUserAsInvitee(User $user): bool |
||||
{ |
||||
return $this->invitees->exists( |
||||
function (int $key, AgendaEventInvitee $invitee) use ($user) { |
||||
return $invitee->getUser() === $user; |
||||
} |
||||
); |
||||
} |
||||
|
||||
public function removeInviteesNotInIdList(array $idList): self |
||||
{ |
||||
$toRemove = []; |
||||
|
||||
/** @var AgendaEventInvitee $invitee */ |
||||
foreach ($this->invitees as $key => $invitee) { |
||||
if (!\in_array($invitee->getUser()->getId(), $idList, true)) { |
||||
$toRemove[] = $key; |
||||
} |
||||
} |
||||
|
||||
foreach ($toRemove as $key) { |
||||
$this->invitees->remove($key); |
||||
} |
||||
|
||||
return $this; |
||||
} |
||||
} |
@ -1,65 +0,0 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Entity; |
||||
|
||||
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity; |
||||
use Doctrine\ORM\Mapping as ORM; |
||||
|
||||
#[ORM\Entity] |
||||
#[ORM\Table(name: 'agenda_event_invitee')] |
||||
#[ORM\InheritanceType('SINGLE_TABLE')] |
||||
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')] |
||||
#[ORM\DiscriminatorMap([ |
||||
'invitee' => AgendaEventInvitee::class, |
||||
'subscriber' => AgendaEventSubscriber::class, |
||||
])] |
||||
class AgendaEventInvitee |
||||
{ |
||||
use TimestampableTypedEntity; |
||||
|
||||
#[ORM\Id] |
||||
#[ORM\Column(type: 'integer')] |
||||
#[ORM\GeneratedValue] |
||||
private int $id; |
||||
|
||||
#[ORM\ManyToOne(targetEntity: AgendaEventInvitation::class, inversedBy: 'invitees')] |
||||
#[ORM\JoinColumn(name: 'invitation_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
||||
private ?AgendaEventInvitation $invitation; |
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class)] |
||||
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')] |
||||
private ?User $user; |
||||
|
||||
public function getId(): int |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
public function getInvitation(): ?AgendaEventInvitation |
||||
{ |
||||
return $this->invitation; |
||||
} |
||||
|
||||
public function setInvitation(?AgendaEventInvitation $invitation): self |
||||
{ |
||||
$this->invitation = $invitation; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
public function getUser(): ?User |
||||
{ |
||||
return $this->user; |
||||
} |
||||
|
||||
public function setUser(?User $user): self |
||||
{ |
||||
$this->user = $user; |
||||
|
||||
return $this; |
||||
} |
||||
} |
@ -1,12 +0,0 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Entity; |
||||
|
||||
use Doctrine\ORM\Mapping as ORM; |
||||
|
||||
#[ORM\Entity] |
||||
class AgendaEventSubscriber extends AgendaEventInvitee {} |
@ -1,32 +0,0 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Entity; |
||||
|
||||
use Doctrine\ORM\Mapping as ORM; |
||||
|
||||
#[ORM\Entity] |
||||
class AgendaEventSubscription extends AgendaEventInvitation |
||||
{ |
||||
public const SUBSCRIPTION_NO = 0; |
||||
public const SUBSCRIPTION_ALL = 1; |
||||
public const SUBSCRIPTION_CLASS = 2; |
||||
|
||||
#[ORM\Column(name: 'max_attendees', type: 'integer', nullable: false, options: ['default' => 0])] |
||||
protected int $maxAttendees = 0; |
||||
|
||||
public function getMaxAttendees(): int |
||||
{ |
||||
return $this->maxAttendees; |
||||
} |
||||
|
||||
public function setMaxAttendees(int $maxAttendees): self |
||||
{ |
||||
$this->maxAttendees = $maxAttendees; |
||||
|
||||
return $this; |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
<?php |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
class Version20230904173401 extends AbstractMigrationChamilo |
||||
{ |
||||
public function getDescription(): string |
||||
{ |
||||
return 'Calendar: Cleanup about invitations/subscriptions'; |
||||
} |
||||
|
||||
/** |
||||
* @inheritDoc |
||||
*/ |
||||
public function up(Schema $schema): void |
||||
{ |
||||
if ($schema->hasTable('agenda_event_invitation')) { |
||||
|
||||
$this->addSql('ALTER TABLE personal_agenda DROP FOREIGN KEY FK_D8612460AF68C6B'); |
||||
$this->addSql("DROP INDEX UNIQ_D8612460AF68C6B ON personal_agenda"); |
||||
|
||||
$this->addSql("ALTER TABLE personal_agenda DROP agenda_event_invitation_id, DROP collective, DROP subscription_visibility, DROP subscription_item_id"); |
||||
|
||||
$this->addSql("ALTER TABLE agenda_event_invitation DROP FOREIGN KEY FK_52A2D5E161220EA6"); |
||||
$this->addSql("DROP TABLE agenda_event_invitation"); |
||||
|
||||
$this->addSql("ALTER TABLE agenda_event_invitee DROP FOREIGN KEY FK_4F5757FEA76ED395"); |
||||
$this->addSql("DROP TABLE agenda_event_invitee"); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue