From 83fe855df4e7d0d8e43a3fa529d9b20449ec1922 Mon Sep 17 00:00:00 2001 From: Tom Udding Date: Sun, 24 Dec 2023 17:57:40 +0100 Subject: [PATCH] [GEWISDB] Move any `Member` association to `SubDecision` itself Changes from GEWISDB upstream, see GEWIS/gewisdb#363. Necessary for GDPR export functionality. --- module/Decision/src/Model/SubDecision.php | 30 +++++++++++++++ .../Model/SubDecision/Board/Installation.php | 38 +++++++------------ .../Decision/src/Model/SubDecision/Budget.php | 29 -------------- .../src/Model/SubDecision/Installation.php | 37 ++++++++---------- .../src/Model/SubDecision/Key/Granting.php | 29 -------------- 5 files changed, 59 insertions(+), 104 deletions(-) diff --git a/module/Decision/src/Model/SubDecision.php b/module/Decision/src/Model/SubDecision.php index 6bb8af9b8a..a8ab2db901 100644 --- a/module/Decision/src/Model/SubDecision.php +++ b/module/Decision/src/Model/SubDecision.php @@ -136,6 +136,20 @@ enumType: MeetingTypes::class, #[Column(type: 'text')] protected string $content; + /** + * The member involved in this sub-decision. + * + * Not all sub-decisions require this, as such it is nullable. However, sub-decisions that need the guarantee that + * this is not null or need to specify an inverse side can do so using an association override. + */ + #[ManyToOne(targetEntity: Member::class)] + #[JoinColumn( + name: 'lidnr', + referencedColumnName: 'lidnr', + nullable: true, + )] + protected ?Member $member = null; + /** * Get the decision. */ @@ -205,6 +219,22 @@ public function setNumber(int $number): void $this->number = $number; } + /** + * Get the member. + */ + public function getMember(): ?Member + { + return $this->member; + } + + /** + * Set the member. + */ + public function setMember(Member $member): void + { + $this->member = $member; + } + /** * Get the content. */ diff --git a/module/Decision/src/Model/SubDecision/Board/Installation.php b/module/Decision/src/Model/SubDecision/Board/Installation.php index 349cf0d6cc..47de57f196 100644 --- a/module/Decision/src/Model/SubDecision/Board/Installation.php +++ b/module/Decision/src/Model/SubDecision/Board/Installation.php @@ -8,16 +8,27 @@ use Decision\Model\BoardMember; use Decision\Model\Member; use Decision\Model\SubDecision; +use Doctrine\ORM\Mapping\AssociationOverride; +use Doctrine\ORM\Mapping\AssociationOverrides; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\JoinColumn; -use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\OneToOne; /** * Installation as board member. */ #[Entity] +#[AssociationOverrides([ + new AssociationOverride( + name: 'member', + joinColumns: new JoinColumn( + name: 'lidnr', + referencedColumnName: 'lidnr', + nullable: false, + ), + ), +])] class Installation extends SubDecision { /** @@ -26,21 +37,6 @@ class Installation extends SubDecision #[Column(type: 'string')] protected string $function; - /** - * Member. - * - * Note that only members that are older than 18 years can be board members. - * Also, honorary, external and extraordinary members cannot be board members. - * (See the Statuten, Art. 13 Lid 2. - */ - // TODO: Inversed relation - #[ManyToOne(targetEntity: Member::class)] - #[JoinColumn( - name: 'lidnr', - referencedColumnName: 'lidnr', - )] - protected Member $member; - /** * The date at which the installation is in effect. */ @@ -92,20 +88,14 @@ public function setFunction(string $function): void /** * Get the member. + * + * @psalm-suppress InvalidNullableReturnType */ public function getMember(): Member { return $this->member; } - /** - * Set the member. - */ - public function setMember(Member $member): void - { - $this->member = $member; - } - /** * Get the date. */ diff --git a/module/Decision/src/Model/SubDecision/Budget.php b/module/Decision/src/Model/SubDecision/Budget.php index 173b5b51f2..9d33bd7814 100644 --- a/module/Decision/src/Model/SubDecision/Budget.php +++ b/module/Decision/src/Model/SubDecision/Budget.php @@ -5,12 +5,9 @@ namespace Decision\Model\SubDecision; use DateTime; -use Decision\Model\Member; use Decision\Model\SubDecision; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; -use Doctrine\ORM\Mapping\JoinColumn; -use Doctrine\ORM\Mapping\ManyToOne; /** * Budget decision. @@ -18,16 +15,6 @@ #[Entity] class Budget extends SubDecision { - /** - * Budget author. - */ - #[ManyToOne(targetEntity: Member::class)] - #[JoinColumn( - name: 'lidnr', - referencedColumnName: 'lidnr', - )] - protected Member $author; - /** * Name of the budget. */ @@ -61,22 +48,6 @@ class Budget extends SubDecision #[Column(type: 'boolean')] protected bool $changes; - /** - * Get the author. - */ - public function getAuthor(): Member - { - return $this->author; - } - - /** - * Set the author. - */ - public function setAuthor(Member $author): void - { - $this->author = $author; - } - /** * Get the name. */ diff --git a/module/Decision/src/Model/SubDecision/Installation.php b/module/Decision/src/Model/SubDecision/Installation.php index 522b6b52c3..1affcdcdc3 100644 --- a/module/Decision/src/Model/SubDecision/Installation.php +++ b/module/Decision/src/Model/SubDecision/Installation.php @@ -8,10 +8,11 @@ use Decision\Model\OrganMember; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\ORM\Mapping\AssociationOverride; +use Doctrine\ORM\Mapping\AssociationOverrides; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\JoinColumn; -use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\OneToMany; use Doctrine\ORM\Mapping\OneToOne; @@ -19,6 +20,17 @@ * Installation into organ. */ #[Entity] +#[AssociationOverrides([ + new AssociationOverride( + name: 'member', + joinColumns: new JoinColumn( + name: 'lidnr', + referencedColumnName: 'lidnr', + nullable: false, + ), + inversedBy: 'installations', + ), +])] class Installation extends FoundationReference { /** @@ -27,19 +39,6 @@ class Installation extends FoundationReference #[Column(type: 'string')] protected string $function; - /** - * Member. - */ - #[ManyToOne( - targetEntity: Member::class, - inversedBy: 'installations', - )] - #[JoinColumn( - name: 'lidnr', - referencedColumnName: 'lidnr', - )] - protected Member $member; - /** * Reappointment subdecisions if this installation was prolonged (can be done multiple times). * @@ -92,20 +91,14 @@ public function setFunction(string $function): void /** * Get the member. + * + * @psalm-suppress InvalidNullableReturnType */ public function getMember(): Member { return $this->member; } - /** - * Set the member. - */ - public function setMember(Member $member): void - { - $this->member = $member; - } - /** * Get the reappointments, if they exist. * diff --git a/module/Decision/src/Model/SubDecision/Key/Granting.php b/module/Decision/src/Model/SubDecision/Key/Granting.php index 4dee5a44c9..7b5bba226a 100644 --- a/module/Decision/src/Model/SubDecision/Key/Granting.php +++ b/module/Decision/src/Model/SubDecision/Key/Granting.php @@ -10,24 +10,11 @@ use Decision\Model\SubDecision; use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; -use Doctrine\ORM\Mapping\JoinColumn; -use Doctrine\ORM\Mapping\ManyToOne; use Doctrine\ORM\Mapping\OneToOne; #[Entity] class Granting extends SubDecision { - /** - * The member who is granted a keycode of GEWIS. - */ - #[ManyToOne(targetEntity: Member::class)] - #[JoinColumn( - name: 'lidnr', - referencedColumnName: 'lidnr', - nullable: true, - )] - protected ?Member $grantee = null; - /** * Till when the keycode is granted. */ @@ -52,22 +39,6 @@ class Granting extends SubDecision )] protected Keyholder $keyholder; - /** - * Get the grantee. - */ - public function getGrantee(): ?Member - { - return $this->grantee; - } - - /** - * Set the grantee. - */ - public function setGrantee(Member $grantee): void - { - $this->grantee = $grantee; - } - /** * Get the date. */