1e381f98dSGreg Roach<?php 2e381f98dSGreg Roach 3e381f98dSGreg Roach/** 4e381f98dSGreg Roach * webtrees: online genealogy 5e381f98dSGreg Roach * Copyright (C) 2019 webtrees development team 6e381f98dSGreg Roach * This program is free software: you can redistribute it and/or modify 7e381f98dSGreg Roach * it under the terms of the GNU General Public License as published by 8e381f98dSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9e381f98dSGreg Roach * (at your option) any later version. 10e381f98dSGreg Roach * This program is distributed in the hope that it will be useful, 11e381f98dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12e381f98dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13e381f98dSGreg Roach * GNU General Public License for more details. 14e381f98dSGreg Roach * You should have received a copy of the GNU General Public License 15e381f98dSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16e381f98dSGreg Roach */ 17e381f98dSGreg Roach 18e381f98dSGreg Roachdeclare(strict_types=1); 19e381f98dSGreg Roach 20e381f98dSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21e381f98dSGreg Roach 22e381f98dSGreg Roachuse Fisharebest\Webtrees\Contracts\UserInterface; 23e381f98dSGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 24e381f98dSGreg Roachuse Fisharebest\Webtrees\Services\MessageService; 25e381f98dSGreg Roachuse Psr\Http\Message\ResponseInterface; 26e381f98dSGreg Roachuse Psr\Http\Message\ServerRequestInterface; 27e381f98dSGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 28e381f98dSGreg Roach 29e381f98dSGreg Roach/** 30e381f98dSGreg Roach * Compose messages from an administrator. 31e381f98dSGreg Roach */ 32e381f98dSGreg Roachclass BroadcastPage implements RequestHandlerInterface 33e381f98dSGreg Roach{ 34e381f98dSGreg Roach use ViewResponseTrait; 35e381f98dSGreg Roach 36e381f98dSGreg Roach /** @var MessageService */ 37e381f98dSGreg Roach private $message_service; 38e381f98dSGreg Roach 39e381f98dSGreg Roach /** 40e381f98dSGreg Roach * MessagePage constructor. 41e381f98dSGreg Roach * 42e381f98dSGreg Roach * @param MessageService $message_service 43e381f98dSGreg Roach */ 44*3d51159aSGreg Roach public function __construct(MessageService $message_service) 45e381f98dSGreg Roach { 46e381f98dSGreg Roach $this->message_service = $message_service; 47e381f98dSGreg Roach } 48e381f98dSGreg Roach 49e381f98dSGreg Roach /** 50e381f98dSGreg Roach * @param ServerRequestInterface $request 51e381f98dSGreg Roach * 52e381f98dSGreg Roach * @return ResponseInterface 53e381f98dSGreg Roach */ 54e381f98dSGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 55e381f98dSGreg Roach { 56e381f98dSGreg Roach $user = $request->getAttribute('user'); 57e381f98dSGreg Roach $referer = $request->getHeaderLine('referer'); 58e381f98dSGreg Roach $params = $request->getQueryParams(); 59e381f98dSGreg Roach $body = $params['body'] ?? ''; 60e381f98dSGreg Roach $subject = $params['subject'] ?? ''; 61e381f98dSGreg Roach $to = $params['to']; 62e381f98dSGreg Roach $url = $params['url'] ?? $referer; 63e381f98dSGreg Roach 64e381f98dSGreg Roach $to_names = $this->message_service->recipientUsers($to) 65e381f98dSGreg Roach ->map(static function (UserInterface $user): string { 66e381f98dSGreg Roach return $user->realName(); 67e381f98dSGreg Roach }); 68e381f98dSGreg Roach 69e381f98dSGreg Roach $title = $this->message_service->recipientDescription($to); 70e381f98dSGreg Roach 71e381f98dSGreg Roach $this->layout = 'layouts/administration'; 72e381f98dSGreg Roach 73e381f98dSGreg Roach return $this->viewResponse('admin/broadcast', [ 74e381f98dSGreg Roach 'body' => $body, 75e381f98dSGreg Roach 'from' => $user, 76e381f98dSGreg Roach 'subject' => $subject, 77e381f98dSGreg Roach 'title' => $title, 78e381f98dSGreg Roach 'to' => $to, 79e381f98dSGreg Roach 'to_names' => $to_names, 80e381f98dSGreg Roach 'url' => $url, 81e381f98dSGreg Roach ]); 82e381f98dSGreg Roach } 83e381f98dSGreg Roach} 84