get('submit');
- $submit->setLabel($submit->getValue());
+ $submit->setLabel($title);
$submit->setAttribute('class', 'btn btn-primary');
?>
= $this->formButton($submit) ?>
diff --git a/module/Database/view/database/settings/delete-list.phtml b/module/Database/view/database/settings/delete-list.phtml
index 410336ab5..b17e32fc4 100644
--- a/module/Database/view/database/settings/delete-list.phtml
+++ b/module/Database/view/database/settings/delete-list.phtml
@@ -15,7 +15,7 @@ if (!isset($form)): ?>
$form->setAttribute(
'action',
- $this->url('settings/list-delete', [
+ $this->url('settings/lists/delete', [
'name' => $name,
]),
);
diff --git a/module/Database/view/database/settings/index.phtml b/module/Database/view/database/settings/index.phtml
index decb56ed8..45b3541cc 100644
--- a/module/Database/view/database/settings/index.phtml
+++ b/module/Database/view/database/settings/index.phtml
@@ -21,7 +21,7 @@ use Laminas\View\Renderer\PhpRenderer;
-
+
= $this->translate('Mailing Lists') ?>
diff --git a/module/Database/view/database/settings/lists.phtml b/module/Database/view/database/settings/lists.phtml
new file mode 100644
index 000000000..77856e943
--- /dev/null
+++ b/module/Database/view/database/settings/lists.phtml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+ = $this->translate('Name (Mailman)') ?> |
+ = $this->translate('Dutch Description') ?> |
+ = $this->translate('English Description') ?> |
+ = $this->translate('On Form') ?> |
+ = $this->translate('Auto-subscription') ?> |
+ = $this->translate('Delete') ?> |
+
+
+
+
+
+ = $this->escapeHtml($list->getName()) ?> (= $this->escapeHtml($list->getMailmanId())?>) |
+ = $this->escapeHtml($list->getNlDescription()) ?> |
+ = $this->escapeHtml($list->getEnDescription()) ?> |
+ |
+ |
+
+
+ = $this->translate('Edit')?>
+
+
+ = $this->translate('Delete')?>
+
+ |
+
+
+
+
+
+
diff --git a/module/Report/src/Listener/DatabaseUpdateListener.php b/module/Report/src/Listener/DatabaseUpdateListener.php
index 53df42c05..056209e41 100644
--- a/module/Report/src/Listener/DatabaseUpdateListener.php
+++ b/module/Report/src/Listener/DatabaseUpdateListener.php
@@ -7,6 +7,7 @@
use Database\Model\Address as DatabaseAddressModel;
use Database\Model\Decision as DatabaseDecisionModel;
use Database\Model\MailingList as DatabaseMailingListModel;
+use Database\Model\MailingListMember as DatabaseMailingListMemberModel;
use Database\Model\Meeting as DatabaseMeetingModel;
use Database\Model\Member as DatabaseMemberModel;
use Database\Model\SubDecision as DatabaseSubDecisionModel;
@@ -96,6 +97,10 @@ public function postUpdate(LifecycleEventArgs $eventArgs): void
$this->miscService->generateList($entity);
break;
+ case $entity instanceof DatabaseMailingListMemberModel:
+ $this->miscService->generateListMembership($entity);
+ break;
+
default:
return;
}
diff --git a/module/Report/src/Model/MailingList.php b/module/Report/src/Model/MailingList.php
index c7c777dbd..5ba60f8fe 100644
--- a/module/Report/src/Model/MailingList.php
+++ b/module/Report/src/Model/MailingList.php
@@ -9,7 +9,7 @@
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
-use Doctrine\ORM\Mapping\ManyToMany;
+use Doctrine\ORM\Mapping\OneToMany;
/**
* Mailing List model.
@@ -36,34 +36,20 @@ class MailingList
#[Column(type: 'text')]
protected string $en_description;
- /**
- * If the mailing list should be on the form.
- */
- #[Column(type: 'boolean')]
- protected bool $onForm;
-
- /**
- * If members should be subscribed by default.
- *
- * (when it is on the form, that means that the checkbox is checked by default)
- */
- #[Column(type: 'boolean')]
- protected bool $defaultSub;
-
/**
* Mailing list members.
*
- * @var Collection
+ * @var Collection
*/
- #[ManyToMany(
- targetEntity: Member::class,
- mappedBy: 'lists',
+ #[OneToMany(
+ targetEntity: MailingListMember::class,
+ mappedBy: 'mailingList',
)]
- protected Collection $members;
+ protected Collection $mailingListMemberships;
public function __construct()
{
- $this->members = new ArrayCollection();
+ $this->mailingListMemberships = new ArrayCollection();
}
/**
@@ -114,77 +100,13 @@ public function setNlDescription(string $description): void
$this->nl_description = $description;
}
- /**
- * Get the description.
- */
- public function getDescription(): string
- {
- return $this->getNlDescription();
- }
-
- /**
- * Set the description.
- */
- public function setDescription(string $description): void
- {
- $this->setNlDescription($description);
- }
-
- /**
- * Get if it should be on the form.
- */
- public function getOnForm(): bool
- {
- return $this->onForm;
- }
-
- /**
- * Set if it should be on the form.
- */
- public function setOnForm(bool $onForm): void
- {
- $this->onForm = $onForm;
- }
-
- /**
- * Get if it is a default list.
- */
- public function getDefaultSub(): bool
- {
- return $this->defaultSub;
- }
-
- /**
- * Set if it is a default list.
- */
- public function setDefaultSub(bool $default): void
- {
- $this->defaultSub = $default;
- }
-
/**
* Get subscribed members.
*
- * @return Collection
- */
- public function getMembers(): Collection
- {
- return $this->members;
- }
-
- /**
- * Add a member.
- */
- public function addMember(Member $member): void
- {
- $this->members[] = $member;
- }
-
- /**
- * Remove a member.
+ * @return Collection
*/
- public function removeMember(Member $member): void
+ public function getMailingListMemberships(): Collection
{
- $this->members->removeElement($member);
+ return $this->mailingListMemberships;
}
}
diff --git a/module/Report/src/Model/MailingListMember.php b/module/Report/src/Model/MailingListMember.php
new file mode 100644
index 000000000..00181992c
--- /dev/null
+++ b/module/Report/src/Model/MailingListMember.php
@@ -0,0 +1,187 @@
+mailingList;
+ }
+
+ /**
+ * Set the mailing list.
+ */
+ public function setMailingList(MailingList $mailingList): void
+ {
+ $this->mailingList = $mailingList;
+ }
+
+ /**
+ * Get the member.
+ */
+ public function getMember(): Member
+ {
+ return $this->member;
+ }
+
+ /**
+ * Set the member.
+ */
+ public function setMember(Member $member): void
+ {
+ $this->member = $member;
+ }
+
+ /**
+ * Get the Mailman `member_id` for this subscription.
+ */
+ public function getMembershipId(): string
+ {
+ return $this->membershipId;
+ }
+
+ /**
+ * Set the Mailman `member_id` for this subscription.
+ */
+ public function setMembershipId(string $membershipId): void
+ {
+ $this->membershipId = $membershipId;
+ }
+
+ /**
+ * Get when the last sync happened.
+ */
+ public function getLastSyncOn(): ?DateTime
+ {
+ return $this->lastSyncOn;
+ }
+
+ /**
+ * Set when the last sync happened.
+ */
+ public function setLastSyncOn(DateTime $lastSyncOn): void
+ {
+ $this->lastSyncOn = $lastSyncOn;
+ }
+
+ /**
+ * Get whether the last sync was successful.
+ */
+ public function isLastSyncSuccess(): bool
+ {
+ return $this->lastSyncSuccess;
+ }
+
+ /**
+ * Set whether the last sync was successful.
+ */
+ public function setLastSyncSuccess(bool $lastSyncSuccess): void
+ {
+ $this->lastSyncSuccess = $lastSyncSuccess;
+ }
+
+ /**
+ * Get whether the entry must still be removed from Mailman.
+ */
+ public function isToBeDeleted(): bool
+ {
+ return $this->toBeDeleted;
+ }
+
+ /**
+ * Set whether the entry must still be removed from Mailman.
+ */
+ public function setToBeDeleted(bool $toBeDeleted): void
+ {
+ $this->toBeDeleted = $toBeDeleted;
+ }
+}
diff --git a/module/Report/src/Model/Member.php b/module/Report/src/Model/Member.php
index bf11e9904..871ced655 100644
--- a/module/Report/src/Model/Member.php
+++ b/module/Report/src/Model/Member.php
@@ -12,10 +12,7 @@
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
-use Doctrine\ORM\Mapping\InverseJoinColumn;
use Doctrine\ORM\Mapping\JoinColumn;
-use Doctrine\ORM\Mapping\JoinTable;
-use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\Mapping\OneToMany;
use Report\Model\SubDecision\Installation;
@@ -187,22 +184,14 @@ enumType: MembershipTypes::class,
/**
* Memberships of mailing lists.
*
- * @var Collection
+ * @var Collection
*/
- #[ManyToMany(
- targetEntity: MailingList::class,
- inversedBy: 'members',
- )]
- #[JoinTable(name: 'members_mailinglists')]
- #[JoinColumn(
- name: 'lidnr',
- referencedColumnName: 'lidnr',
- )]
- #[InverseJoinColumn(
- name: 'name',
- referencedColumnName: 'name',
+ #[OneToMany(
+ targetEntity: MailingListMember::class,
+ mappedBy: 'member',
+ cascade: ['persist'],
)]
- protected Collection $lists;
+ protected Collection $mailingListMemberships;
/**
* Organ memberships.
@@ -263,7 +252,7 @@ public function __construct()
$this->organInstallations = new ArrayCollection();
$this->boardInstallations = new ArrayCollection();
$this->keyGrantings = new ArrayCollection();
- $this->lists = new ArrayCollection();
+ $this->mailingListMemberships = new ArrayCollection();
}
/**
@@ -800,28 +789,30 @@ static function ($c, $kg) {
/**
* Get mailing list subscriptions.
*
- * @return Collection
+ * @return Collection
*/
- public function getLists(): Collection
+ public function getMailingListMemberships(): Collection
{
- return $this->lists;
+ return $this->mailingListMemberships;
}
/**
* Add a mailing list subscription.
- *
- * Note that this is the owning side.
*/
- public function addList(MailingList $list): void
+ public function addList(MailingListMember $list): void
{
- $list->addMember($this);
- $this->lists[] = $list;
+ if ($this->mailingListMemberships->contains($list)) {
+ return;
+ }
+
+ $list->setMember($this);
+ $this->mailingListMemberships->add($list);
}
/**
* Add multiple mailing lists.
*
- * @param MailingList[] $lists
+ * @param MailingListMember[] $lists
*/
public function addLists(array $lists): void
{
@@ -829,23 +820,4 @@ public function addLists(array $lists): void
$this->addList($list);
}
}
-
- /**
- * Remove a mailing list subscription.
- *
- * Note that this is the owning side.
- */
- public function removeList(MailingList $list): void
- {
- $list->removeMember($this);
- $this->lists->removeElement($list);
- }
-
- /**
- * Clear the lists.
- */
- public function clearLists(): void
- {
- $this->lists = new ArrayCollection();
- }
}
diff --git a/module/Report/src/Service/Factory/MiscFactory.php b/module/Report/src/Service/Factory/MiscFactory.php
index 02e80f304..fb7027527 100644
--- a/module/Report/src/Service/Factory/MiscFactory.php
+++ b/module/Report/src/Service/Factory/MiscFactory.php
@@ -5,6 +5,7 @@
namespace Report\Service\Factory;
use Database\Mapper\MailingList as MailingListMapper;
+use Database\Mapper\MailingListMember as MailingListMemberMapper;
use Doctrine\ORM\EntityManager;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;
@@ -22,11 +23,14 @@ public function __invoke(
): MiscService {
/** @var MailingListMapper $mailingListMapper */
$mailingListMapper = $container->get(MailingListMapper::class);
+ /** @var MailingListMemberMapper $mailingListMapper */
+ $mailingListMemberMapper = $container->get(MailingListMemberMapper::class);
/** @var EntityManager $emReport */
$emReport = $container->get('doctrine.entitymanager.orm_report');
return new MiscService(
$mailingListMapper,
+ $mailingListMemberMapper,
$emReport,
);
}
diff --git a/module/Report/src/Service/Member.php b/module/Report/src/Service/Member.php
index 2a156cac2..2b29496af 100644
--- a/module/Report/src/Service/Member.php
+++ b/module/Report/src/Service/Member.php
@@ -100,11 +100,11 @@ public function generateLists(
$reportListRepo = $this->emReport->getRepository(ReportMailingListModel::class);
$reportLists = array_map(static function ($list) {
- return $list->getName();
- }, $reportMember->getLists()->toArray());
+ return $list->getMailingList()->getName();
+ }, $reportMember->getMailingListMemberships()->toArray());
$lists = array_map(static function ($list) {
- return $list->getName();
- }, $member->getLists()->toArray());
+ return $list->getMailingList()->getName();
+ }, $member->getMailingListMemberships()->toArray());
foreach (array_diff($lists, $reportLists) as $list) {
$reportList = $reportListRepo->find($list);
diff --git a/module/Report/src/Service/Misc.php b/module/Report/src/Service/Misc.php
index f74ac2cfe..8b3744b52 100644
--- a/module/Report/src/Service/Misc.php
+++ b/module/Report/src/Service/Misc.php
@@ -5,14 +5,20 @@
namespace Report\Service;
use Database\Mapper\MailingList as MailingListMapper;
+use Database\Mapper\MailingListMember as MailingListMemberMapper;
use Database\Model\MailingList as DatabaseMailingListModel;
+use Database\Model\MailingListMember as DatabaseMailingListMemberModel;
use Doctrine\ORM\EntityManager;
+use LogicException;
use Report\Model\MailingList as ReportMailingListModel;
+use Report\Model\MailingListMember as ReportMailingListMemberModel;
+use Report\Model\Member as ReportMemberModel;
class Misc
{
public function __construct(
private readonly MailingListMapper $mailingListMapper,
+ private readonly MailingListMemberMapper $mailingListMemberMapper,
private readonly EntityManager $emReport,
) {
}
@@ -26,12 +32,17 @@ public function generate(): void
$this->generateList($list);
}
+ foreach ($this->mailingListMemberMapper->findAll() as $listMember) {
+ $this->generateListMembership($listMember);
+ }
+
$this->emReport->flush();
}
public function generateList(DatabaseMailingListModel $list): void
{
$repo = $this->emReport->getRepository(ReportMailingListModel::class);
+ /** @var ReportMailingListModel|null $reportList */
$reportList = $repo->find($list->getName());
if (null === $reportList) {
@@ -41,9 +52,44 @@ public function generateList(DatabaseMailingListModel $list): void
$reportList->setEnDescription($list->getEnDescription());
$reportList->setNlDescription($list->getNlDescription());
- $reportList->setOnForm($list->getOnForm());
- $reportList->setDefaultSub($list->getDefaultSub());
$this->emReport->persist($reportList);
}
+
+ public function generateListMembership(DatabaseMailingListMemberModel $mailingListMember): void
+ {
+ $repo = $this->emReport->getRepository(ReportMailingListMemberModel::class);
+ /** @var ReportMailingListMemberModel|null $reportListMembership */
+ $reportListMembership = $repo->find([
+ 'mailingList' => $mailingListMember->getMailingList()->getName(),
+ 'member' => $mailingListMember->getMember()->getLidnr(),
+ ]);
+
+ if (null === $reportListMembership) {
+ $reportList = $this->emReport->getRepository(ReportMailingListModel::class)
+ ->find($mailingListMember->getMailingList()->getName());
+
+ if (null === $reportList) {
+ throw new LogicException('List membership without list');
+ }
+
+ $reportMember = $this->emReport->getRepository(ReportMemberModel::class)
+ ->find($mailingListMember->getMember()->getLidnr());
+
+ if (null === $reportMember) {
+ throw new LogicException('List membership without member');
+ }
+
+ $reportListMembership = new ReportMailingListMemberModel();
+ $reportListMembership->setMailingList($reportList);
+ $reportListMembership->setMember($reportMember);
+ }
+
+ $reportListMembership->setLastSyncOn($mailingListMember->getLastSyncOn());
+ $reportListMembership->setLastSyncSuccess($mailingListMember->isLastSyncSuccess());
+ $reportListMembership->setToBeDeleted($mailingListMember->isToBeDeleted());
+ $reportListMembership->setMembershipId($mailingListMember->getMembershipId());
+
+ $this->emReport->persist($reportListMembership);
+ }
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 0db90064c..697b37c18 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -64,6 +64,7 @@
module/Database/src/Mapper/Factory/CheckoutSessionFactory.php
module/Database/src/Mapper/Factory/InstallationFunctionFactory.php
module/Database/src/Mapper/Factory/MailingListFactory.php
+ module/Database/src/Mapper/Factory/MailingListMemberFactory.php
module/Database/src/Mapper/Factory/MeetingFactory.php
module/Database/src/Mapper/Factory/MemberFactory.php
module/Database/src/Mapper/Factory/MemberUpdateFactory.php
@@ -74,6 +75,7 @@
module/Database/src/Service/Factory/FrontPageFactory.php
module/Database/src/Service/Factory/InstallationFunctionFactory.php
module/Database/src/Service/Factory/MailingListFactory.php
+ module/Database/src/Service/Factory/MailmanFactory.php
module/Database/src/Service/Factory/MeetingFactory.php
module/Database/src/Service/Factory/MemberFactory.php
module/Database/src/Service/Factory/StripeFactory.php