Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| MentionsWebController | |
88.89% |
16 / 18 |
|
50.00% |
1 / 2 |
3.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| actionIndex | |
88.24% |
15 / 17 |
|
0.00% |
0 / 1 |
2.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Comments\Presentation\Web; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Domain\Model\PermissionContext; |
| 12 | use App\Modules\Comments\Application\Service\CommentMentionsQueryServiceInterface; |
| 13 | use Nyholm\Psr7\Factory\Psr17Factory; |
| 14 | use Psr\Http\Message\ResponseInterface; |
| 15 | use Psr\Http\Message\ServerRequestInterface; |
| 16 | use Twig\Environment as TwigEnvironment; |
| 17 | |
| 18 | /** |
| 19 | * Web Controller rendering the full Mentions Inbox page (/mentions). |
| 20 | * |
| 21 | * @package App\Modules\Comments\Presentation\Web |
| 22 | */ |
| 23 | final readonly class MentionsWebController |
| 24 | { |
| 25 | /** |
| 26 | * MentionsWebController constructor. |
| 27 | */ |
| 28 | public function __construct( |
| 29 | private TwigEnvironment $twig, |
| 30 | private CommentMentionsQueryServiceInterface $mentionsService, |
| 31 | private Psr17Factory $psr17Factory |
| 32 | ) { |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Renders full Mentions Inbox communication center. |
| 37 | */ |
| 38 | public function actionIndex(ServerRequestInterface $request, PermissionContext $ctx): ResponseInterface |
| 39 | { |
| 40 | if ($ctx->actorUserId <= 0) { |
| 41 | $resp = $this->psr17Factory->createResponse(302); |
| 42 | return $resp->withHeader('Location', '/login'); |
| 43 | } |
| 44 | |
| 45 | $params = $request->getQueryParams(); |
| 46 | $scope = (string) ($params['scope'] ?? 'unread'); |
| 47 | $query = (string) ($params['q'] ?? ''); |
| 48 | |
| 49 | $inbox = $this->mentionsService->getInbox($ctx->actorUserId, $scope, $query); |
| 50 | |
| 51 | $html = $this->twig->render('modules/comments/mentions_inbox.twig', [ |
| 52 | 'inbox' => $inbox, |
| 53 | 'active_scope' => $scope, |
| 54 | 'search_query' => $query, |
| 55 | 'pageTitle' => 'Wzmianki w komentarzach', |
| 56 | 'unread_count' => $inbox->unreadCount, |
| 57 | ]); |
| 58 | |
| 59 | $response = $this->psr17Factory->createResponse(200); |
| 60 | $response->getBody()->write($html); |
| 61 | |
| 62 | return $response->withHeader('Content-Type', 'text/html; charset=utf-8'); |
| 63 | } |
| 64 | } |