Skip to content

Commit eb4f732

Browse files
committed
feat: promote summit event 2 presentation
Signed-off-by: smarcet@gmail.com <smarcet@gmail.com>
1 parent 3bec98f commit eb4f732

2 files changed

Lines changed: 87 additions & 11 deletions

File tree

app/Models/Foundation/Summit/Events/SummitEvent.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,4 +1673,40 @@ public function setSubmissionSource(string $submission_source): void
16731673
throw new ValidationException(sprintf("%s is not a valid submission source.", $submission_source));
16741674
$this->submission_source = $submission_source;
16751675
}
1676+
1677+
/**
1678+
* @param PresentationType $type
1679+
* @return void
1680+
*/
1681+
public function promote2Presentation(PresentationType $type):void{
1682+
try {
1683+
$sql = <<<SQL
1684+
UPDATE `SummitEvent` SET `ClassName` = 'Presentation', TypeID = :type_id WHERE `SummitEvent`.`ID` = :id;
1685+
SQL;
1686+
1687+
$stmt = $this->prepareRawSQL($sql);
1688+
$stmt->execute(
1689+
[
1690+
'id' => $this->getId(),
1691+
'type_id' => $type->getId(),
1692+
]
1693+
);
1694+
1695+
$sql = <<<SQL
1696+
INSERT INTO `Presentation` (`ID`, `Status`, `OtherTopic`, `Progress`, `Views`, `BeenEmailed`, `ProblemAddressed`, `AttendeesExpectedLearnt`, `Legacy`, `ToRecord`, `AttendingMedia`, `Slug`, `ModeratorID`, `SelectionPlanID`, `WillAllSpeakersAttend`, `DisclaimerAcceptedDate`, `CustomOrder`)
1697+
VALUES (:id, NULL, NULL, '0', '0', '0', NULL, NULL, '0', '0', '0', NULL, NULL, NULL, '0', NULL, '0')
1698+
SQL;
1699+
1700+
$stmt = $this->prepareRawSQL($sql);
1701+
$stmt->execute(
1702+
[
1703+
'id' => $this->getId(),
1704+
]
1705+
);
1706+
1707+
} catch (\Exception $ex) {
1708+
1709+
}
1710+
1711+
}
16761712
}

app/Services/Model/Imp/SummitService.php

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,46 @@ private function canPerformEventTypeTransition(SummitEventType $old_event_type,
642642
private function saveOrUpdateEvent(Summit $summit, array $data, $event_id = null)
643643
{
644644

645+
646+
// check first if there is an upgrade or not
647+
648+
$res = $this->tx_service->transaction(function () use ($summit, $data, $event_id) {
649+
$event_type = null;
650+
if (isset($data['type_id'])) {
651+
$event_type = $summit->getEventType(intval($data['type_id']));
652+
if (is_null($event_type)) {
653+
throw new EntityNotFoundException(sprintf("event type id %s does not exists!", $data['type_id']));
654+
}
655+
}
656+
657+
if (!is_null($event_id) && $event_id > 0) {
658+
$event = $this->event_repository->getByIdRefreshed($event_id);
659+
if (is_null($event))
660+
throw new ValidationException(sprintf("event id %s does not exists!", $event_id));
661+
$old_event_type = $event->getType();
662+
663+
// check event type transition ...
664+
665+
if (!is_null($event_type)) {
666+
667+
if ($old_event_type->getClassName() != $event_type->getClassName() && $event_type instanceof PresentationType) {
668+
Log::debug(sprintf("SummitService::saveOrUpdateEvent promoting event %s 2 presentation ...", $event_id));
669+
$event->promote2Presentation($event_type);
670+
return $event;
671+
}
672+
}
673+
}
674+
return null;
675+
});
676+
677+
// we performed an upgrade, return the event
678+
if(!is_null($res))
679+
{
680+
return $this->tx_service->transaction(function () use ($summit, $data, $event_id) {
681+
return $this->event_repository->getByIdRefreshed($event_id);
682+
});
683+
}
684+
645685
return $this->tx_service->transaction(function () use ($summit, $data, $event_id) {
646686

647687
Log::debug
@@ -689,25 +729,25 @@ private function saveOrUpdateEvent(Summit $summit, array $data, $event_id = null
689729

690730
// existing event
691731

692-
if (!is_null($event_id) && intval($event_id) > 0) {
693-
$event = $this->event_repository->getById($event_id);
732+
if (!is_null($event_id) && $event_id > 0) {
733+
$event = $this->event_repository->getByIdRefreshed($event_id);
694734
if (is_null($event))
695735
throw new ValidationException(sprintf("event id %s does not exists!", $event_id));
696736
$old_event_type = $event->getType();
697737

698738
// check event type transition ...
699739

700740
if (!is_null($event_type) && !$this->canPerformEventTypeTransition($old_event_type, $event_type)) {
701-
throw new ValidationException
702-
(
703-
sprintf
741+
throw new ValidationException
704742
(
705-
"invalid event type transition for event id %s ( from %s to %s)",
706-
$event_id,
707-
$old_event_type->getType(),
708-
$event_type->getType()
709-
)
710-
);
743+
sprintf
744+
(
745+
"invalid event type transition for event id %s ( from %s to %s)",
746+
$event_id,
747+
$old_event_type->getType(),
748+
$event_type->getType()
749+
)
750+
);
711751
}
712752
if (is_null($event_type)) $event_type = $old_event_type;
713753
}

0 commit comments

Comments
 (0)