Skip to content

Commit 134dc85

Browse files
committed
Registration Invitations
Fix on accepted filter Change-Id: I23387acb68d7af3d52c0ac0e2a877d1ef6d9eb0f
1 parent 41dcc65 commit 134dc85

3 files changed

Lines changed: 42 additions & 29 deletions

File tree

app/Models/Foundation/Summit/Registration/SummitRegistrationInvitation.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function getRemainingAllowedTicketTypes():array {
373373

374374
public function markAsAccepted(): void
375375
{
376-
Log::debug(sprintf("SummitRegistrationInvitation::markAsAccepted %s ", $this->id));
376+
Log::debug(sprintf("SummitRegistrationInvitation::markAsAccepted %s orders count %s", $this->id, $this->orders->count()));
377377
if($this->orders->count() === 0 ) return;
378378

379379
$bought_tickets = $this->getBoughtTicketTypesExcerpt();
@@ -397,14 +397,18 @@ public function markAsAccepted(): void
397397
);
398398

399399
foreach ($invitation_ticket_types as $ticket_type){
400+
Log::debug(sprintf("SummitRegistrationInvitation::markAsAccepted %s checking if ticket type %s is purchased ... ", $this->id, $ticket_type->getId()));
400401
if(!isset($bought_tickets[$ticket_type->getId()])){
401-
Log::debug(sprintf("SummitRegistrationInvitation::markAsAccepted %s ticket type %s is not purchased yet ", $this->id, $ticket_type->getId()));
402+
Log::debug(sprintf("SummitRegistrationInvitation::markAsAccepted %s ticket type %s is not purchased yet, marking invitation as non accepted ... ", $this->id, $ticket_type->getId()));
402403
$this->accepted_date = null;
403404
return;
404405
}
405406
}
407+
406408
// once i bought all meant ticket types ... the invitation is marked as accepted
407409
$this->accepted_date = new \DateTime('now', new \DateTimeZone('UTC'));
410+
411+
Log::debug(sprintf("SummitRegistrationInvitation::markAsAccepted %s marked as accepted", $this->id));
408412
}
409413

410414
public function isAccepted(): bool
@@ -426,6 +430,10 @@ public function getOrders(){
426430
return $this->orders;
427431
}
428432

433+
public function hasTicketType(SummitTicketType $ticketType):bool{
434+
return $this->ticket_types->contains($ticketType);
435+
}
436+
429437
/**
430438
* @param SummitTicketType $ticketType
431439
* @throws ValidationException

app/Repositories/Summit/DoctrineSummitRegistrationInvitationRepository.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function getFilterMappings()
5757
'email' => 'e.email:json_string',
5858
'first_name' => 'e.first_name:json_string',
5959
'last_name' => 'e.last_name:json_string',
60-
'is_completed' => new DoctrineSwitchFilterMapping([
60+
'is_accepted' => new DoctrineSwitchFilterMapping([
6161
'true' => new DoctrineCaseFilterMapping(
6262
'true',
6363
"e.accepted_date is not null"
@@ -68,17 +68,6 @@ protected function getFilterMappings()
6868
),
6969
]
7070
),
71-
'is_accepted' => new DoctrineSwitchFilterMapping([
72-
'true' => new DoctrineCaseFilterMapping(
73-
'true',
74-
"SIZE(e.orders) > 0"
75-
),
76-
'false' => new DoctrineCaseFilterMapping(
77-
'false',
78-
"e.orders IS EMPTY"
79-
),
80-
]
81-
),
8271
'is_sent' => new DoctrineSwitchFilterMapping([
8372
'true' => new DoctrineCaseFilterMapping(
8473
'true',

app/Services/Model/Imp/SummitRegistrationInvitationService.php

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,28 +357,44 @@ public function update(Summit $summit, int $invitation_id, array $payload): Summ
357357
$email = trim($payload['email']);
358358
try {
359359
$invitation = $this->setInvitationMember($invitation, $email);
360-
}
361-
catch (\Exception $ex){
360+
} catch (\Exception $ex) {
362361
Log::warning($ex);
363362
}
364363
}
365364

365+
$is_formerly_accepted = $invitation->isAccepted();
366366
$allowed_ticket_types = $payload['allowed_ticket_types'] ?? [];
367-
$invitation->clearTicketTypes();
368-
foreach ($allowed_ticket_types as $ticket_type_id) {
369-
$ticket_type = $summit->getTicketTypeById(intval($ticket_type_id));
370-
if (is_null($ticket_type)) {
371-
throw new ValidationException
372-
(
373-
sprintf
367+
if (count($allowed_ticket_types) > 0) {
368+
foreach ($allowed_ticket_types as $ticket_type_id) {
369+
$ticket_type = $summit->getTicketTypeById(intval($ticket_type_id));
370+
if (is_null($ticket_type)) {
371+
throw new ValidationException
374372
(
375-
"SummitRegistrationInvitationService::add ticket type %s does not exists on summit %s.",
376-
$ticket_type_id,
377-
$summit->getId()
378-
)
379-
);
373+
sprintf
374+
(
375+
"SummitRegistrationInvitationService::add ticket type %s does not exists on summit %s.",
376+
$ticket_type_id,
377+
$summit->getId()
378+
)
379+
);
380+
}
381+
$invitation->addTicketType($ticket_type);
380382
}
381-
$invitation->addTicketType($ticket_type);
383+
// remove missing ones
384+
$to_remove = [];
385+
foreach ($invitation->getTicketTypes() as $invitation_ticket_type){
386+
if(!in_array($invitation_ticket_type->getId(), $allowed_ticket_types)){
387+
$to_remove[] = $invitation_ticket_type;
388+
}
389+
}
390+
foreach ($to_remove as $ticket_type_to_remove){
391+
$invitation->removeTicketType($ticket_type_to_remove);
392+
}
393+
}
394+
395+
if($invitation->isAccepted() != $is_formerly_accepted){
396+
// it changed its state bc the ticket types update
397+
$payload['is_accepted'] = $invitation->isAccepted();
382398
}
383399

384400
// tags

0 commit comments

Comments
 (0)