Skip to content

Commit

Permalink
If Participant name is updated, and this participant is linked in a r…
Browse files Browse the repository at this point in the history
…elated participant field, the name is also updated at link
  • Loading branch information
theoboldt committed Jul 30, 2023
1 parent 29f09c6 commit 0bbd502
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use AppBundle\Entity\CustomField\CustomFieldValueContainer;
use AppBundle\Entity\CustomField\ParticipantDetectingCustomFieldValue;
use AppBundle\Entity\Event;
use AppBundle\Entity\Participant;
use AppBundle\Manager\RelatedParticipantsLocker;
use Doctrine\ORM\EntityManager;

Expand All @@ -24,13 +25,15 @@ abstract class AbstractRelatedParticipantResetListener extends RelatedParticipan
/**
* Reset proposed participants for an complete event
*
* @param EntityManager $em Entity manage
* @param Event $event Related event
* @param int $maxWait If defined, specifies maximum time to wait for lock
* @throws \Doctrine\DBAL\ConnectionException
* @throws \Doctrine\DBAL\DBALException
* @param EntityManager $em Entity manage
* @param Event $event Related event
* @param int $maxWait If defined, specifies maximum time to wait for lock
* @param Participant|null $updateParticipant If defined, all participant links relating to this participant are
* updated; Bad interface, should be improved later
*/
protected function resetProposedParticipantsForEvent(EntityManager $em, Event $event, int $maxWait = 30)
protected function resetProposedParticipantsForEvent(
EntityManager $em, Event $event, int $maxWait = 30, ?Participant $updateParticipant = null
): void
{
$lockHandle = $this->lock($event);
if ($lockHandle !== false && flock($lockHandle, LOCK_EX)) {
Expand Down Expand Up @@ -85,6 +88,12 @@ protected function resetProposedParticipantsForEvent(EntityManager $em, Event $e
if ($customFieldValue instanceof ParticipantDetectingCustomFieldValue) {
$customFieldValue->setProposedParticipants(null);
$collectionModified = true;

if ($updateParticipant !== null
&& $customFieldValue->getParticipantAid() === $updateParticipant->getAid()) {
$customFieldValue->setParticipantFirstName($updateParticipant->getNameFirst());
$customFieldValue->setParticipantLastName($updateParticipant->getNameLast());
}
}
}
if ($collectionModified) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function preUpdate(Participant $participant, PreUpdateEventArgs $event)
{
if ($event->hasChangedField('nameLast') || $event->hasChangedField('nameFirst')) {
$this->resetProposedParticipantsForEvent(
$event->getEntityManager(), $participant->getParticipation()->getEvent()
$event->getEntityManager(), $participant->getParticipation()->getEvent(), 30, $participant
);
}
}
Expand Down

0 comments on commit 0bbd502

Please sign in to comment.