Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Duplicate per-order questions when tickets aren't being duplicated #309

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 44 additions & 16 deletions backend/app/Services/Domain/Event/DuplicateEventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function duplicateEvent(
cloneEventSettings: $duplicateSettings,
);

if ($duplicateQuestions) {
$this->clonePerOrderQuestions($event, $newEvent->getId());
}

if ($duplicateTickets) {
$this->cloneExistingTickets(
event: $event,
Expand Down Expand Up @@ -153,7 +157,7 @@ private function cloneExistingTickets(
}

if ($duplicateQuestions) {
$this->cloneQuestions($event, $newEventId, $oldTicketToNewTicketMap);
$this->clonePerTicketQuestions($event, $newEventId, $oldTicketToNewTicketMap);
}

if ($duplicatePromoCodes) {
Expand All @@ -174,23 +178,47 @@ private function cloneExistingTickets(
/**
* @throws Throwable
*/
private function cloneQuestions(EventDomainObject $event, int $newEventId, array $oldTicketToNewTicketMap): void
private function clonePerTicketQuestions(EventDomainObject $event, int $newEventId, array $oldTicketToNewTicketMap): void
{
foreach ($event->getQuestions() as $question) {
$this->createQuestionService->createQuestion(
(new QuestionDomainObject())
->setTitle($question->getTitle())
->setEventId($newEventId)
->setBelongsTo($question->getBelongsTo())
->setType($question->getType())
->setRequired($question->getRequired())
->setOptions($question->getOptions())
->setIsHidden($question->getIsHidden()),
array_map(
static fn(TicketDomainObject $ticket) => $oldTicketToNewTicketMap[$ticket->getId()],
$question->getTickets()?->all(),
),
);
if ($question->getBelongsTo() == "TICKET") {
$this->createQuestionService->createQuestion(
(new QuestionDomainObject())
->setTitle($question->getTitle())
->setEventId($newEventId)
->setBelongsTo($question->getBelongsTo())
->setType($question->getType())
->setRequired($question->getRequired())
->setOptions($question->getOptions())
->setIsHidden($question->getIsHidden()),
array_map(
static fn(TicketDomainObject $ticket) => $oldTicketToNewTicketMap[$ticket->getId()],
$question->getTickets()?->all(),
),
);
}
}
}

/**
* @throws Throwable
*/
private function clonePerOrderQuestions(EventDomainObject $event, int $newEventId): void
{
foreach ($event->getQuestions() as $question) {
if ($question->getBelongsTo() == "ORDER") {
$this->createQuestionService->createQuestion(
(new QuestionDomainObject())
->setTitle($question->getTitle())
->setEventId($newEventId)
->setBelongsTo($question->getBelongsTo())
->setType($question->getType())
->setRequired($question->getRequired())
->setOptions($question->getOptions())
->setIsHidden($question->getIsHidden()),
[],
);
}
}
}

Expand Down
Loading