Skip to content

Commit 4e07054

Browse files
committed
fix: Attendee Ticket Serializer
1 parent 6e5dc66 commit 4e07054

3 files changed

Lines changed: 38 additions & 17 deletions

File tree

.gitmessage.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@
2323
# BREAKING CHANGE: <describe the breaking change and migration path>
2424
# Closes #123
2525
# Relates-to #456
26+
<<<<<<< HEAD
2627
# Co-authored-by: Name <email>
28+
=======
29+
# Co-authored-by: Name <email>
30+
>>>>>>> cab387aa (fix: Attendee Ticket Serializer)

app/ModelSerializers/Summit/Registration/SummitAttendeeTicketCSVSerializer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function serialize($expand = null, array $fields = [], array $relations =
8282
$values[$question_label] = '';
8383
if (!is_null($ticket_owner)) {
8484
$value = $ticket_owner->getExtraQuestionAnswerValueByQuestion($question);
85-
Log::debug(sprintf("SummitAttendeeTicketCSVSerializer::serialize question %s value %s", $question->getId(), $value));
8685
if(is_null($value)) continue;
8786
$values[$question_label] = $question->getNiceValue($value);
8887
}

app/Models/Foundation/Summit/Registration/Attendees/SummitAttendee.php

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -729,35 +729,53 @@ public function getExtraQuestionAnswerByQuestion(SummitOrderExtraQuestionType $q
729729
return $answer ? $answer : null;
730730
}
731731

732+
733+
734+
private ?array $extraQuestionAnswersCache = null;
735+
private function warmExtraQuestionAnswersCache():void{
736+
try {
737+
if ($this->extraQuestionAnswersCache !== null) {
738+
return;
739+
}
740+
741+
$sql = <<<SQL
742+
SELECT ExtraQuestionAnswer.QuestionID, ExtraQuestionAnswer.Value FROM `SummitOrderExtraQuestionAnswer`
743+
INNER JOIN ExtraQuestionAnswer ON ExtraQuestionAnswer.ID = SummitOrderExtraQuestionAnswer.ID
744+
WHERE SummitOrderExtraQuestionAnswer.SummitAttendeeID = :owner_id
745+
SQL;
746+
747+
$stmt = $this->prepareRawSQL($sql, ['owner_id' => $this->getId()]);
748+
$rows = $stmt->executeQuery()->fetchAllAssociative();
749+
750+
$map = [];
751+
foreach ($rows as $row) {
752+
// QuestionID es int; Value es string (para multiselect puede ser CSV/JSON según tu modelo)
753+
$map[(int)$row['QuestionID']] = $row['Value'];
754+
}
755+
$this->extraQuestionAnswersCache = $map;
756+
}
757+
catch (\PDOException $e) {
758+
Log::error($e->getMessage());
759+
}
760+
}
732761
/**
733762
* @param SummitOrderExtraQuestionType $question
734763
* @return string|null
735764
*/
736765
public function getExtraQuestionAnswerValueByQuestion(SummitOrderExtraQuestionType $question): ?string
737766
{
738767
try {
739-
$sql = <<<SQL
740-
SELECT ExtraQuestionAnswer.Value FROM `SummitOrderExtraQuestionAnswer`
741-
INNER JOIN ExtraQuestionAnswer ON ExtraQuestionAnswer.ID = SummitOrderExtraQuestionAnswer.ID
742-
WHERE SummitOrderExtraQuestionAnswer.SummitAttendeeID = :owner_id AND ExtraQuestionAnswer.QuestionID = :question_id
743-
SQL;
744-
$stmt = $this->prepareRawSQL($sql, [
745-
'owner_id' => $this->getId(),
746-
'question_id' => $question->getId()
747-
]);
748-
$res = $stmt->executeQuery();
749-
$res = $res->fetchFirstColumn();
750-
$res = count($res) > 0 ? $res[0] : null;
751-
return !is_null($res) ? $res : null;
768+
$this->warmExtraQuestionAnswersCache();
769+
$qid = $question->getId();
770+
return $this->extraQuestionAnswersCache[$qid] ?? null;
752771
} catch (\Exception $ex) {
753-
Log::debug($ex);
772+
\Log::debug($ex);
773+
return null;
754774
}
755-
return null;
756775
}
757776

758777
public function clearExtraQuestionAnswers(): void
759778
{
760-
Log::debug(sprintf("SummitAttendee::clearExtraQuestionAnswers for attendee %s", $this->getId()));
761779
$this->extra_question_answers->clear();
762780
}
763781

0 commit comments

Comments
 (0)