Skip to content

Commit 5fbb8fb

Browse files
committed
Fix Purchased Ticket title’s not including disabled or non-live status elements
1 parent f461509 commit 5fbb8fb

File tree

6 files changed

+44
-46
lines changed

6 files changed

+44
-46
lines changed

src/elements/PurchasedTicket.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,8 @@ protected static function defineActions(string $source = null): array
227227

228228
public function init(): void
229229
{
230-
// Title is dynamic
231-
if ($eventType = $this->getEvent()?->getType()) {
232-
try {
233-
// Title is dynamic
234-
$this->title = Craft::$app->getView()->renderObjectTemplate($eventType->purchasedTicketTitleFormat, $this);
235-
} catch (Throwable $e) {
236-
}
230+
if ($title = $this->getDynamicTitle()) {
231+
$this->title = $title;
237232
}
238233

239234
parent::init();
@@ -293,14 +288,26 @@ public function getFieldLayout(): ?FieldLayout
293288
return null;
294289
}
295290

291+
public function getDynamicTitle(): ?string
292+
{
293+
if ($eventType = $this->getEvent()?->getType()) {
294+
try {
295+
return Craft::$app->getView()->renderObjectTemplate($eventType->purchasedTicketTitleFormat, $this);
296+
} catch (Throwable $e) {
297+
}
298+
}
299+
300+
return null;
301+
}
302+
296303
public function getEvent(): ?Event
297304
{
298305
if ($this->_event) {
299306
return $this->_event;
300307
}
301308

302309
if ($this->eventId) {
303-
return $this->_event = Event::find()->id($this->eventId)->one();
310+
return $this->_event = Events::$plugin->getEvents()->getEventById($this->eventId);
304311
}
305312

306313
return null;
@@ -318,7 +325,7 @@ public function getSession(): ?Session
318325
}
319326

320327
if ($this->sessionId) {
321-
return $this->_session = Session::find()->id($this->sessionId)->one();
328+
return $this->_session = Events::$plugin->getSessions()->getSessionById($this->sessionId);
322329
}
323330

324331
return null;
@@ -336,7 +343,7 @@ public function getTicket(): ?Ticket
336343
}
337344

338345
if ($this->ticketId) {
339-
return $this->_ticket = Ticket::find()->id($this->ticketId)->one();
346+
return $this->_ticket = Events::$plugin->getTickets()->getTicketById($this->ticketId);
340347
}
341348

342349
return null;
@@ -354,7 +361,7 @@ public function getTicketType(): ?TicketType
354361
}
355362

356363
if ($this->ticketTypeId) {
357-
return $this->_ticketType = TicketType::find()->id($this->ticketTypeId)->one();
364+
return $this->_ticketType = Events::$plugin->getTicketTypes()->getTicketTypeById($this->ticketTypeId);
358365
}
359366

360367
return null;

src/elements/Ticket.php

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,15 @@ public function getDescription(): string
212212

213213
public function getEvent(): ?Event
214214
{
215-
if (!$this->_event) {
216-
if ($this->eventId) {
217-
// Only while in the CP, we often want to get disabled elements
218-
$status = Craft::$app->getRequest()->getIsCpRequest() ? null : self::STATUS_ENABLED;
219-
220-
$this->_event = Event::find()->id($this->eventId)->status($status)->one();
221-
} else {
222-
return null;
223-
}
215+
if ($this->_event) {
216+
return $this->_event;
217+
}
218+
219+
if ($this->eventId) {
220+
return $this->_event = Events::$plugin->getEvents()->getEventById($this->eventId);
224221
}
225222

226-
return $this->_event;
223+
return null;
227224
}
228225

229226
public function setEvent(Event $event): void
@@ -234,18 +231,15 @@ public function setEvent(Event $event): void
234231

235232
public function getSession(): ?Session
236233
{
237-
if (!$this->_session) {
238-
if ($this->sessionId) {
239-
// Only while in the CP, we often want to get disabled elements
240-
$status = Craft::$app->getRequest()->getIsCpRequest() ? null : self::STATUS_ENABLED;
234+
if ($this->_session) {
235+
return $this->_session;
236+
}
241237

242-
$this->_session = Session::find()->id($this->sessionId)->status($status)->one();
243-
} else {
244-
return null;
245-
}
238+
if ($this->sessionId) {
239+
return $this->_session = Events::$plugin->getSessions()->getSessionById($this->sessionId);
246240
}
247241

248-
return $this->_session;
242+
return null;
249243
}
250244

251245
public function setSession(Session $session): void
@@ -256,18 +250,15 @@ public function setSession(Session $session): void
256250

257251
public function getType(): ?TicketType
258252
{
259-
if (!$this->_type) {
260-
if ($this->typeId) {
261-
// Only while in the CP, we often want to get disabled elements
262-
$status = Craft::$app->getRequest()->getIsCpRequest() ? null : self::STATUS_ENABLED;
253+
if ($this->_type) {
254+
return $this->_type;
255+
}
263256

264-
$this->_type = TicketType::find()->id($this->typeId)->status($status)->one();
265-
} else {
266-
return null;
267-
}
257+
if ($this->typeId) {
258+
return $this->_type = Events::$plugin->getTicketTypes()->getTicketTypeById($this->typeId);
268259
}
269260

270-
return $this->_type;
261+
return null;
271262
}
272263

273264
public function setType(TicketType $type): void

src/services/Events.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Events extends Component
1717

1818
public function getEventById(int $id, int $siteId = null): ?Event
1919
{
20-
return Craft::$app->getElements()->getElementById($id, Event::class, $siteId);
20+
return Event::find()->id($id)->site($siteId)->status(null)->one();
2121
}
2222

2323
public function afterSaveSiteHandler(SiteEvent $event): void

src/services/Sessions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public function getAllSessionsByEventId(int $eventId, int $siteId = null, bool $
8383
return $sessionQuery->all();
8484
}
8585

86-
public function getSessionById(int $sessionId, int $siteId = null): ?Session
86+
public function getSessionById(int $id, int $siteId = null): ?Session
8787
{
88-
return Craft::$app->getElements()->getElementById($sessionId, Session::class, $siteId);
88+
return Session::find()->id($id)->site($siteId)->status(null)->one();
8989
}
9090

9191
public function getSessionGqlContentArguments(): array

src/services/TicketTypes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public function getAllTicketTypesByEventId(int $eventId, int $siteId = null, boo
3838
return $ticketTypeQuery->all();
3939
}
4040

41-
public function getTicketTypeById(int $ticketTypeId, int $siteId = null): ?TicketType
41+
public function getTicketTypeById(int $id, int $siteId = null): ?TicketType
4242
{
43-
return Craft::$app->getElements()->getElementById($ticketTypeId, TicketType::class, $siteId);
43+
return TicketType::find()->id($id)->site($siteId)->status(null)->one();
4444
}
4545

4646
public function getTicketTypeGqlContentArguments(): array

src/services/Tickets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class Tickets extends Component
2525
// Public Methods
2626
// =========================================================================
2727

28-
public function getTicketById(int $ticketId, int $siteId = null): ?Ticket
28+
public function getTicketById(int $id, int $siteId = null): ?Ticket
2929
{
30-
return Craft::$app->getElements()->getElementById($ticketId, Ticket::class, $siteId);
30+
return Ticket::find()->id($id)->site($siteId)->status(null)->one();
3131
}
3232

3333
public function onBeforeSendEmail(MailEvent $event): void

0 commit comments

Comments
 (0)