Skip to content

Commit

Permalink
Merge pull request #347 from tomudding/feature/reappointment-decision
Browse files Browse the repository at this point in the history
Add `Reappointment` subdecision for installations in bodies
  • Loading branch information
tomudding committed Oct 12, 2023
2 parents f5995be + 0dc2bdb commit a801370
Show file tree
Hide file tree
Showing 13 changed files with 529 additions and 113 deletions.
12 changes: 12 additions & 0 deletions module/Database/src/Form/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(
private readonly Translator $translator,
MeetingFieldset $meeting,
InstallationFieldset $install,
SubDecisionFieldset $reappointment,
SubDecisionFieldset $discharge,
SubDecisionFieldset $foundation,
) {
Expand All @@ -44,6 +45,17 @@ public function __construct(
],
]);

$this->add([
'name' => 'reappointments',
'type' => Collection::class,
'options' => [
'label' => $this->translator->translate('Reappointments'),
'count' => 1,
'should_create_template' => true,
'target_element' => $reappointment,
],
]);

$this->add([
'name' => 'discharges',
'type' => Collection::class,
Expand Down
19 changes: 15 additions & 4 deletions module/Database/src/Hydrator/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Database\Model\Decision as DecisionModel;
use Database\Model\SubDecision\Discharge as DischargeModel;
use Database\Model\SubDecision\Installation as InstallationModel;
use Database\Model\SubDecision\Reappointment as ReappointmentModel;
use InvalidArgumentException;

class Install extends AbstractDecision
Expand Down Expand Up @@ -34,8 +35,18 @@ public function hydrate(

$num = 1;

// first add discharges
if (isset($data['discharges']) && !empty($data['discharges'])) {
// first do reappointments
if (!empty($data['reappointments'])) {
foreach ($data['reappointments'] as $install) {
$reappointment = new ReappointmentModel();
$reappointment->setInstallation($install);
$reappointment->setNumber($num++);
$reappointment->setDecision($decision);
}
}

// then add discharges
if (!empty($data['discharges'])) {
foreach ($data['discharges'] as $install) {
$discharge = new DischargeModel();
$discharge->setInstallation($install);
Expand All @@ -44,8 +55,8 @@ public function hydrate(
}
}

// then add installations
if (isset($data['installations']) && !empty($data['installations'])) {
// finally add installations
if (!empty($data['installations'])) {
foreach ($data['installations'] as $install) {
$installation = new InstallationModel();
$installation->setNumber($num++);
Expand Down
2 changes: 2 additions & 0 deletions module/Database/src/Model/SubDecision.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Database\Model\SubDecision\Key\Granting as KeyGranting;
use Database\Model\SubDecision\Key\Withdrawal as KeyWithdrawal;
use Database\Model\SubDecision\Other;
use Database\Model\SubDecision\Reappointment;
use Database\Model\SubDecision\Reckoning;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
Expand All @@ -42,6 +43,7 @@
'foundation' => Foundation::class,
'abrogation' => Abrogation::class,
'installation' => Installation::class,
'reappointment' => Reappointment::class,
'discharge' => Discharge::class,
'budget' => Budget::class,
'reckoning' => Reckoning::class,
Expand Down
45 changes: 37 additions & 8 deletions module/Database/src/Model/SubDecision/Installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
namespace Database\Model\SubDecision;

use Database\Model\Member;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
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;

/**
Expand Down Expand Up @@ -36,6 +39,17 @@ class Installation extends FoundationReference
)]
protected Member $member;

/**
* Reappointment subdecisions if this installation was prolonged (can be done multiple times).
*
* @var Collection<array-key, Reappointment>
*/
#[OneToMany(
targetEntity: Reappointment::class,
mappedBy: 'installation',
)]
protected Collection $reappointments;

/**
* Discharges.
*/
Expand All @@ -45,6 +59,11 @@ class Installation extends FoundationReference
)]
protected ?Discharge $discharge = null;

public function __construct()
{
$this->reappointments = new ArrayCollection();
}

/**
* Get the function.
*/
Expand Down Expand Up @@ -78,17 +97,13 @@ public function setMember(Member $member): void
}

/**
* Get the content.
* Get the reappointments, if they exist.
*
* Fixes Bor's greatest frustration
* @return Collection<array-key, Reappointment>
*/
public function getContent(): string
public function getReappointments(): Collection
{
$member = $this->getMember()->getFullName();
$text = $member . ' wordt geïnstalleerd als ' . $this->getFunction();
$text .= ' van ' . $this->getFoundation()->getAbbr() . '.';

return $text;
return $this->reappointments;
}

/**
Expand All @@ -98,4 +113,18 @@ public function getDischarge(): ?Discharge
{
return $this->discharge;
}

/**
* Get the content.
*
* Fixes Bor's greatest frustration
*/
public function getContent(): string
{
$member = $this->getMember()->getFullName();
$text = $member . ' wordt geïnstalleerd als ' . $this->getFunction();
$text .= ' van ' . $this->getFoundation()->getAbbr() . '.';

return $text;
}
}
82 changes: 82 additions & 0 deletions module/Database/src/Model/SubDecision/Reappointment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace Database\Model\SubDecision;

use Database\Model\SubDecision;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;

use function sprintf;

/**
* Reappointment of a previous installation.
*
* To prevent issues with recursive self-references, multiple reappointments can point to the same installation.
*/
#[Entity]
class Reappointment extends SubDecision
{
/**
* Reference to the installation of a member.
*/
#[ManyToOne(
targetEntity: Installation::class,
inversedBy: 'reappointments',
)]
#[JoinColumn(
name: 'r_meeting_type',
referencedColumnName: 'meeting_type',
)]
#[JoinColumn(
name: 'r_meeting_number',
referencedColumnName: 'meeting_number',
)]
#[JoinColumn(
name: 'r_decision_point',
referencedColumnName: 'decision_point',
)]
#[JoinColumn(
name: 'r_decision_number',
referencedColumnName: 'decision_number',
)]
#[JoinColumn(
name: 'r_number',
referencedColumnName: 'number',
)]
protected Installation $installation;

/**
* Get the original installation for this reappointment.
*/
public function getInstallation(): Installation
{
return $this->installation;
}

/**
* Set the original installation for this reappointment.
*/
public function setInstallation(Installation $installation): void
{
$this->installation = $installation;
}

/**
* Get the textual content of this subdecision.
*/
public function getContent(): string
{
$installation = $this->getInstallation();
$memberFullName = $installation->getMember()->getFullName();

return sprintf(
'%s wordt herbenoemd als %s van %s.',
$memberFullName,
$installation->getFunction(),
$installation->getFoundation()->getAbbr(),
);
}
}
13 changes: 11 additions & 2 deletions module/Database/src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@
use Database\Model\Meeting as MeetingModel;
use Database\Model\Member as MemberModel;
use Database\Model\SubDecision\Board\Installation as BoardInstallationModel;
use Database\Model\SubDecision\Discharge as DischargeModel;
use Database\Model\SubDecision\Foundation as FoundationModel;
use Database\Model\SubDecision\Installation as InstallationModel;
use Database\Model\SubDecision\Key\Granting as KeyGrantingModel;
use Database\Model\SubDecision\Reappointment as ReappointmentModel;
use Database\Service\Api as ApiService;
use Database\Service\Factory\ApiFactory as ApiServiceFactory;
use Database\Service\Factory\InstallationFunctionFactory as InstallationFunctionServiceFactory;
Expand Down Expand Up @@ -245,6 +246,7 @@ public function getServiceConfig(): array
$container->get(MvcTranslator::class),
$container->get(MeetingFieldset::class),
$container->get(InstallationFieldset::class),
$container->get('database_form_fieldset_subdecision_reappointment'),
$container->get('database_form_fieldset_subdecision_discharge'),
$container->get('database_form_fieldset_subdecision_foundation'),
);
Expand Down Expand Up @@ -358,10 +360,17 @@ public function getServiceConfig(): array

return $fieldset;
},
'database_form_fieldset_subdecision_reappointment' => static function (ContainerInterface $container) {
$fieldset = new SubDecisionFieldset();
$fieldset->setHydrator($container->get('database_hydrator_subdecision'));
$fieldset->setObject(new ReappointmentModel());

return $fieldset;
},
'database_form_fieldset_subdecision_discharge' => static function (ContainerInterface $container) {
$fieldset = new SubDecisionFieldset();
$fieldset->setHydrator($container->get('database_hydrator_subdecision'));
$fieldset->setObject(new InstallationModel());
$fieldset->setObject(new DischargeModel());

return $fieldset;
},
Expand Down
52 changes: 27 additions & 25 deletions module/Database/src/Service/Meeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,14 @@ public function installDecision(array $data): array
$decision = $form->getData();
$meeting = $this->getMeeting(
MeetingTypes::from($decision['meeting']['type']),
(int) $decision['meeting']['number'],
intval($decision['meeting']['number']),
);
$subdecision = $this->getOrganMapper()->findSimple(
MeetingTypes::from($decision['subdecision']['meeting_type']),
(int) $decision['subdecision']['meeting_number'],
(int) $decision['subdecision']['decision_point'],
(int) $decision['subdecision']['decision_number'],
(int) $decision['subdecision']['number'],
intval($decision['subdecision']['meeting_number']),
intval($decision['subdecision']['decision_point']),
intval($decision['subdecision']['decision_number']),
intval($decision['subdecision']['number']),
);

if (
Expand All @@ -573,9 +573,10 @@ public function installDecision(array $data): array
$decision['meeting'] = $meeting;
$decision['subdecision'] = $subdecision;

// Prepare installations.
$installations = [];
array_walk($decision['installations'], function ($value) use (&$installations): void {
$member = $this->memberMapper->findSimple((int) $value['member']['lidnr']);
$member = $this->memberMapper->findSimple(intval($value['member']['lidnr']));

if (null === $member) {
return;
Expand All @@ -586,27 +587,28 @@ public function installDecision(array $data): array
'function' => $value['function'],
];
});

$decision['installations'] = $installations;

$discharges = [];
array_walk($decision['discharges'], function ($value) use (&$discharges): void {
$decision = $this->getOrganMapper()->findInstallationDecision(
MeetingTypes::from($value['meeting_type']),
(int) $value['meeting_number'],
(int) $value['decision_point'],
(int) $value['decision_number'],
(int) $value['number'],
);

if (null === $decision) {
return;
}

$discharges[] = $decision;
});

$decision['discharges'] = $discharges;
// Prepare reappointments and discharges.
foreach (['reappointments', 'discharges'] as $subDecisionType) {
$subDecisions = [];
array_walk($decision[$subDecisionType], function ($value) use (&$subDecisions): void {
$decision = $this->getOrganMapper()->findInstallationDecision(
MeetingTypes::from($value['meeting_type']),
intval($value['meeting_number']),
intval($value['decision_point']),
intval($value['decision_number']),
intval($value['number']),
);

if (null === $decision) {
return;
}

$subDecisions[] = $decision;
});
$decision[$subDecisionType] = $subDecisions;
}

$decision = (new InstallHydrator())->hydrate($decision, new DecisionModel());

Expand Down
Loading

0 comments on commit a801370

Please sign in to comment.