|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\App\Controllers\Donation; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use WMDE\Fundraising\DonationContext\UseCases\ListComments\CommentListingRequest; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
|
12
|
|
|
|
|
13
|
|
|
class ListCommentsController { |
|
14
|
|
|
|
|
15
|
|
|
public function handleJson( FunFunFactory $ffFactory, Request $request ): Response { |
|
16
|
|
|
$response = JsonResponse::create( |
|
17
|
|
|
$ffFactory->newCommentListJsonPresenter()->present( |
|
18
|
|
|
$ffFactory->newListCommentsUseCase()->listComments( |
|
19
|
|
|
new CommentListingRequest( |
|
20
|
|
|
(int)$request->query->get( 'n', '10' ), |
|
21
|
|
|
(int)$request->query->get( 'page', '1' ) |
|
22
|
|
|
) |
|
23
|
|
|
) |
|
24
|
|
|
) |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
if ( $request->query->get( 'f' ) ) { |
|
28
|
|
|
$response->setCallback( $request->query->get( 'f' ) ); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return $response; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function handleRss( FunFunFactory $ffFactory ): Response { |
|
35
|
|
|
$rss = $ffFactory->newCommentListRssPresenter()->present( |
|
36
|
|
|
$ffFactory->newListCommentsUseCase()->listComments( |
|
37
|
|
|
new CommentListingRequest( 100, CommentListingRequest::FIRST_PAGE ) |
|
38
|
|
|
) |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
return new Response( |
|
42
|
|
|
$rss, |
|
43
|
|
|
200, |
|
44
|
|
|
[ |
|
45
|
|
|
'Content-Type' => 'text/xml; charset=utf-8', |
|
46
|
|
|
'X-Moz-Is-Feed' => '1' |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function handleHtml( FunFunFactory $ffFactory, Request $request ): Response { |
|
52
|
|
|
return new Response( |
|
53
|
|
|
$ffFactory->newCommentListHtmlPresenter()->present( |
|
54
|
|
|
$ffFactory->newListCommentsUseCase()->listComments( |
|
55
|
|
|
new CommentListingRequest( |
|
56
|
|
|
10, |
|
57
|
|
|
(int)$request->query->get( 'page', '1' ) |
|
58
|
|
|
) |
|
59
|
|
|
), |
|
60
|
|
|
(int)$request->query->get( 'page', '1' ) |
|
61
|
|
|
) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|