-
-
Notifications
You must be signed in to change notification settings - Fork 636
Expand file tree
/
Copy pathEmailTemplateRepository.php
More file actions
95 lines (82 loc) · 2.58 KB
/
EmailTemplateRepository.php
File metadata and controls
95 lines (82 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace HiEvents\Repository\Eloquent;
use HiEvents\DomainObjects\EmailTemplateDomainObject;
use HiEvents\DomainObjects\Enums\EmailTemplateType;
use HiEvents\Models\EmailTemplate;
use HiEvents\Repository\Interfaces\EmailTemplateRepositoryInterface;
use Illuminate\Support\Collection;
/**
* @extends BaseRepository<EmailTemplateDomainObject>
*/
class EmailTemplateRepository extends BaseRepository implements EmailTemplateRepositoryInterface
{
protected function getModel(): string
{
return EmailTemplate::class;
}
public function getDomainObject(): string
{
return EmailTemplateDomainObject::class;
}
public function findByTypeWithFallback(
EmailTemplateType $type,
int $accountId,
?int $eventId = null,
?int $organizerId = null
): ?EmailTemplateDomainObject {
// Try event-specific template first
if ($eventId) {
$template = $this->findByTypeAndScope($type, $accountId, $eventId);
if ($template) {
return $template;
}
}
// Try organizer-specific template as fallback
if ($organizerId) {
$template = $this->findByTypeAndScope($type, $accountId, null, $organizerId);
if ($template) {
return $template;
}
}
// No custom template found - AttendeeTicketMail and OrderSummary will use their default templates
return null;
}
public function findByEvent(int $eventId): Collection
{
return $this->findWhere([
'event_id' => $eventId,
'is_active' => true,
]);
}
public function findByOrganizer(int $organizerId): Collection
{
return $this->findWhere([
'organizer_id' => $organizerId,
'event_id' => null,
'is_active' => true,
]);
}
public function findByTypeAndScope(
EmailTemplateType $type,
int $accountId,
?int $eventId = null,
?int $organizerId = null
): ?EmailTemplateDomainObject {
$conditions = [
'account_id' => $accountId,
'template_type' => $type->value,
'is_active' => true,
];
if ($eventId) {
$conditions['event_id'] = $eventId;
} else {
$conditions[] = ['event_id', '=', null];
}
if ($organizerId) {
$conditions['organizer_id'] = $organizerId;
} else {
$conditions[] = ['organizer_id', '=', null];
}
return $this->findFirstWhere($conditions);
}
}