PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / melograno / usage-tracker / src / Core / ConsentNoticeService.php
ameliabooking / vendor / melograno / usage-tracker / src / Core Last commit date
Anonymizer.php 4 weeks ago ConsentManager.php 4 weeks ago ConsentNoticeService.php 4 weeks ago HttpClient.php 4 weeks ago NoticeManager.php 4 weeks ago UsageTracker.php 4 weeks ago
ConsentNoticeService.php
99 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AmeliaVendor\Melograno\UsageTracker\Core;
6
7 use AmeliaVendor\Melograno\UsageTracker\Collectors\ConsentNoticeCollectorInterface;
8
9 /**
10 * Decides consent/notice policy and owns the admin-notice option.
11 *
12 * This service never mutates consent state or touches cron scheduling; those
13 * side effects belong to UsageTracker. It only answers questions ("should we
14 * migrate?", "what is the default consent?", "should the notice show?") and
15 * arms/dismisses the notice option it owns.
16 */
17 class ConsentNoticeService
18 {
19 private ConsentNoticeCollectorInterface $collector;
20
21 private ConsentManager $consentManager;
22
23 private NoticeManager $noticeManager;
24
25 public function __construct(ConsentNoticeCollectorInterface $collector)
26 {
27 $this->collector = $collector;
28 $this->consentManager = new ConsentManager($collector->getConsentOptionName());
29 $this->noticeManager = new NoticeManager($collector->getNoticeOptionName());
30 }
31
32 public function shouldRunUpgradeMigration(string $savedVersion, string $currentVersion): bool
33 {
34 if (!$this->collector->shouldMigrateConsentOnUpgrade()) {
35 return false;
36 }
37
38 $migrationVersion = $this->collector->getOptInMigrationVersion();
39
40 if ($migrationVersion === null) {
41 return false;
42 }
43
44 return version_compare($savedVersion, $migrationVersion, '<')
45 && version_compare($currentVersion, $migrationVersion, '>=');
46 }
47
48 public function defaultConsent(): bool
49 {
50 return $this->collector->shouldEnableConsentByDefault();
51 }
52
53 public function armNotice(): void
54 {
55 $this->noticeManager->arm();
56 }
57
58 /**
59 * Arms the notice for a fresh install only when telemetry stays off by default
60 * and the collector opts into showing the notice.
61 */
62 public function armNoticeForNewInstallation(bool $consentEnabled): void
63 {
64 if (!$consentEnabled && $this->collector->shouldShowAdminNotice()) {
65 $this->noticeManager->arm();
66 }
67 }
68
69 public function canCurrentUserSeeAdminNotice(): bool
70 {
71 return is_admin() && current_user_can('manage_options');
72 }
73
74 public function shouldShowNotice(): bool
75 {
76 if (!$this->collector->shouldShowAdminNotice()) {
77 return false;
78 }
79
80 if (!$this->noticeManager->isArmed()) {
81 return false;
82 }
83
84 return !$this->consentManager->isEnabled();
85 }
86
87 public function dismissNotice(): void
88 {
89 $this->noticeManager->dismiss();
90 }
91
92 public function dismissNoticeIfArmed(): void
93 {
94 if ($this->noticeManager->isArmed()) {
95 $this->noticeManager->dismiss();
96 }
97 }
98 }
99