Skip to content

Commit 0371b5f

Browse files
committed
Basic Mail Managment Dashboard
1 parent 6bdd8b5 commit 0371b5f

File tree

10 files changed

+137
-1
lines changed

10 files changed

+137
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/vendor/
22
/.ddev/
3+
/.ddev*/
34
/.idea/
45
**/.env
56
/public/test.php
@@ -9,3 +10,4 @@
910
!/data/cache/.gitkeep
1011
/data/persistent/*
1112
!/data/persistent/.gitkeep
13+
db.sql

config/container.php

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
->addArgument(\App\Service\Authentication\AccountService::class)
102102
->addArgument(\App\Table\Authentication\AccountLevelTable::class);
103103

104+
$container->add(\App\Controller\Administration\MailController::class)
105+
->addArgument(\League\Plates\Engine::class)
106+
->addArgument(\App\Service\MailerService::class);
107+
104108
#
105109
# Services
106110
#

config/routes.php

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
$router->get('/admin/urlshortener', 'App\Controller\Administration\UrlShortener\ShortlinkDashboardController::load')
5858
->lazyMiddlewares([\App\Middleware\AuthenticationMiddleware::class, \App\Middleware\AdminCheckMiddleware::class]);
5959

60+
$router->get('/admin/mails', 'App\Controller\Administration\MailController::load')
61+
->lazyMiddlewares([\App\Middleware\AuthenticationMiddleware::class, \App\Middleware\AdminCheckMiddleware::class]);
62+
6063
$router->get('/overview', 'App\Controller\Login\OverviewController::load')
6164
->lazyMiddlewares([\App\Middleware\AuthenticationMiddleware::class]);
6265

src/App/Controller/Administration/DashboardController.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use App\Http\HtmlResponse;
88
use App\Service\Authentication\AccountService;
9+
use App\Service\MailerService;
910
use League\Plates\Engine;
1011
use Psr\Http\Message\ResponseInterface;
1112
use Psr\Http\Message\ServerRequestInterface;
@@ -24,7 +25,9 @@ public function load(ServerRequestInterface $request): ResponseInterface
2425
return new HtmlResponse(
2526
$this->template->render(
2627
'administration/dashboard',
27-
['accountCount' => $this->accountService->getAllAccountsCount()]
28+
[
29+
'accountCount' => $this->accountService->getAllAccountsCount()
30+
]
2831
)
2932
);
3033
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Controller\Administration;
6+
7+
use App\Http\HtmlResponse;
8+
use App\Service\Authentication\AccountService;
9+
use App\Service\MailerService;
10+
use League\Plates\Engine;
11+
use Psr\Http\Message\ResponseInterface;
12+
use Psr\Http\Message\ServerRequestInterface;
13+
14+
readonly class MailController
15+
{
16+
17+
public function __construct(
18+
private Engine $template,
19+
private MailerService $mailerService
20+
) {
21+
}
22+
23+
public function load(ServerRequestInterface $request): ResponseInterface
24+
{
25+
return new HtmlResponse(
26+
$this->template->render(
27+
'administration/mail',
28+
[
29+
'unsentMailAmount' => $this->mailerService->getUnsentAmount(),
30+
'mailsLastSevenDaysAmount' => $this->mailerService->getSentAmountForLastXDays(7)
31+
]
32+
)
33+
);
34+
}
35+
36+
}

src/App/Service/MailerService.php

+10
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,14 @@ public function fetchMailsAndSend(): void
7474

7575
}
7676

77+
public function getUnsentAmount(): int
78+
{
79+
return (int)$this->mailTable->findAmountBySentNull();
80+
}
81+
82+
public function getSentAmountForLastXDays(int $days): int
83+
{
84+
return (int)$this->mailTable->findAmountByLastDays($days);
85+
}
86+
7787
}

src/App/Table/Mail/MailTable.php

+12
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,16 @@ public function updateMailSentById(int $id): void
3535
$this->query->update($this->getTableName())->set('sent', (new \DateTime())->format(Software::DATABASE_TIME_FORMAT))->where('id',$id)->execute();
3636
}
3737

38+
public function findAmountBySentNull(): int|string
39+
{
40+
return $this->query->from($this->getTableName())->select(null)->select('COUNT(*)')->where('sent', null)->fetchColumn();
41+
}
42+
43+
public function findAmountByLastDays(int $days): int|string
44+
{
45+
return $this->query->from($this->getTableName())->select(null)->select('COUNT(*)')->where(
46+
'created between date_sub(now(),INTERVAL ' . $days . ' day) and now()'
47+
)->fetchColumn();
48+
}
49+
3850
}

template/administration/mail.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php $this->layout('basetemplate') ?>
2+
3+
<?php $this->insert('element/navigation') ?>
4+
5+
<div class="container mt-3">
6+
<div class="row">
7+
8+
<div class="col-12">
9+
<h2><?= $this->e($this->translate($this->timeOfDayGreeting())) ?>, <?= $this->getAccountInformation()['name'] ?></h2>
10+
<small class="text-muted">
11+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-info-circle" viewBox="0 0 16 16">
12+
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/>
13+
<path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/>
14+
</svg>
15+
<?= $this->e($this->translate('administration-information')) ?>
16+
</small>
17+
</div>
18+
19+
<hr class="mt-3 mb-3">
20+
21+
<?= $this->insert('element/adminNavigation') ?>
22+
23+
<div class="col-md-9">
24+
<h4 class="mb-3">
25+
<?= $this->e($this->translate('administration-mail-dashboard-title')) ?>
26+
</h4>
27+
28+
<div class="row">
29+
<div class="col-6">
30+
<div class="card">
31+
<div class="card-body">
32+
<span class="text-start">
33+
<?= $this->e($this->translate('administration-mail-dashboard-unsent-mails-amount-card-title')) ?>
34+
</span>
35+
<span class="text-end">
36+
<h4><?= $unsentMailAmount ?></h4>
37+
</span>
38+
</div>
39+
</div>
40+
</div>
41+
<div class="col-6">
42+
<div class="card">
43+
<div class="card-body">
44+
<span class="text-start">
45+
<?= $this->e($this->translate('administration-mail-dashboard-total-mails-recent-amount-card-title')) ?>
46+
</span>
47+
<span class="text-end">
48+
<h4><?= $mailsLastSevenDaysAmount ?></h4>
49+
</span>
50+
</div>
51+
</div>
52+
</div>
53+
</div>
54+
</div>
55+
56+
</div>
57+
58+
</div>

template/element/adminNavigation.php

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<a href="/admin/apikeys" class="list-group-item list-group-item-action">
1313
<?= $this->e($this->translate('admin-navigation-general-tab-api-key-management-title')) ?>
1414
</a>
15+
<a href="/admin/mails" class="list-group-item list-group-item-action">
16+
<?= $this->e($this->translate('admin-navigation-general-tab-mail-title')) ?>
17+
</a>
1518
<a href="#" class="list-group-item list-group-item-action">
1619
<?= $this->e($this->translate('admin-navigation-general-tab-support-interface-title')) ?>
1720
</a>

translations/de.json

+5
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,16 @@
8989
"admin-navigation-general-tab-user-management-title": "Kontoverwaltung",
9090
"admin-navigation-general-tab-license-management-title": "Lizenzverwaltung",
9191
"admin-navigation-general-tab-api-key-management-title": "API-Key Verwaltung",
92+
"admin-navigation-general-tab-mail-title": "E-Mail Management",
9293
"admin-navigation-general-tab-support-interface-title": "Support Oberfläche",
9394
"admin-navigation-tools-tab-title": "Tools",
9495
"admin-navigation-tools-tab-url-shortener-title": "URL-Kürzer",
9596
"admin-navigation-tools-tab-qrcode-generator-title": "QR-Code Generator",
9697

98+
"administration-mail-dashboard-title": "E-Mail Management",
99+
"administration-mail-dashboard-unsent-mails-amount-card-title": "Ausstehende E-Mails",
100+
"administration-mail-dashboard-total-mails-recent-amount-card-title": "E-Mails letzte 7 Tage",
101+
97102
"admin-apikey-list-title": "API-Keys",
98103
"admin-apikey-list-create-key-button-title": "API-Key Erstellen",
99104
"admin-apikey-list-table-account-heading": "Konto",

0 commit comments

Comments
 (0)