PluginProbe ʕ •ᴥ•ʔ
FAPI Member / 2.2.26
FAPI Member v2.2.26
2.2.33 2.2.32 trunk 1.9.47 2.1.18 2.2.24 2.2.25 2.2.26 2.2.28 2.2.29 2.2.30 2.2.31
fapi-member / src / Repository / EmailRepository.php
fapi-member / src / Repository Last commit date
EmailRepository.php 8 months ago LevelOrderRepository.php 8 months ago LevelRepository.php 8 months ago MemberActivityRepository.php 8 months ago MembershipChangeRepository.php 8 months ago MembershipRepository.php 8 months ago PageRepository.php 8 months ago Repository.php 8 months ago SettingsRepository.php 8 months ago UserRepository.php 8 months ago
EmailRepository.php
75 lines
1 <?php
2
3 namespace FapiMember\Repository;
4
5 use FapiMember\Container\Container;
6 use FapiMember\Model\Enums\Types\EmailType;
7
8 class EmailRepository extends Repository
9 {
10 private LevelRepository $levelRepository;
11
12 public function __construct()
13 {
14 $this->levelRepository = Container::get(LevelRepository::class);
15 }
16
17 public function remove(int $levelId, string $emailType): void
18 {
19 $this->deleteTermMeta($levelId, $this->getEmailTemplateKey($emailType));
20 }
21
22 public function update(
23 int $levelId,
24 string $emailType,
25 string|null $mailSubject,
26 string|null $mailBody,
27 ): void
28 {
29 $this->updateTermMeta(
30 $levelId,
31 $this->getEmailTemplateKey($emailType),
32 [
33 's' => $mailSubject ?? '',
34 'b' => $mailBody ?? '',
35 ],
36 );
37 }
38
39 public function getTemplatesForLevel(int|null $levelId, bool $useCascade = false): array
40 {
41 if($levelId === null) {
42 return [];
43 }
44
45 $meta = [];
46
47 foreach (EmailType::getAvailableValues() as $type) {
48 $template = $this->getTermMeta($levelId, $this->getEmailTemplateKey($type));
49
50 if (!empty($template)) {
51 $meta[$type] = $template;
52 }
53 }
54
55 if ($useCascade && count($meta) !== count(EmailType::getAvailableValues())){
56 $level = $this->levelRepository->getLevelById($levelId);
57 $parentEmails = $this->getTemplatesForLevel($level->getParentId());
58
59 foreach (EmailType::getAvailableValues() as $type) {
60 if (!isset($meta[$type]) && isset($parentEmails[$type])) {
61 $meta[$type] = $parentEmails[$type];
62 }
63 }
64 }
65
66 return $meta;
67 }
68
69 private function getEmailTemplateKey(string $type): string
70 {
71 return sprintf('fapi_email_%s', $type);
72 }
73
74 }
75