1
|
|
|
<?php |
2
|
|
|
namespace PhpDraft\Controllers; |
3
|
|
|
|
4
|
|
|
use \Silex\Application; |
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
6
|
|
|
use \PhpDraft\Domain\Entities\Draft; |
7
|
|
|
use \PhpDraft\Domain\Entities\Pick; |
8
|
|
|
|
9
|
|
|
class DraftController { |
10
|
|
|
public function Get(Application $app, Request $request) { |
11
|
|
|
$draft_id = (int)$request->get('id'); |
12
|
|
|
$getDraftData = $request->get('get_draft_data') == 'true'; |
13
|
|
|
|
14
|
|
|
if (empty($draft_id) || $draft_id == 0) { |
15
|
|
|
throw new \Exception("Unable to load draft."); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
//Need to put it in headers so the client can easily add it to all requests (similar to token) |
19
|
|
|
$password = $request->headers->get(DRAFT_PASSWORD_HEADER, ''); |
|
|
|
|
20
|
|
|
|
21
|
|
|
$draft = $app['phpdraft.DraftRepository']->GetPublicDraft($request, $draft_id, $getDraftData, $password); |
22
|
|
|
|
23
|
|
|
return $app->json($draft); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function GetAll(Application $app, Request $request) { |
27
|
|
|
$password = $request->headers->get(DRAFT_PASSWORD_HEADER, ''); |
|
|
|
|
28
|
|
|
$drafts = $app['phpdraft.DraftRepository']->GetPublicDrafts($request, $password); |
29
|
|
|
|
30
|
|
|
return $app->json($drafts); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function GetAllByCommish(Application $app, Request $request) { |
34
|
|
|
$commish_id = $request->get('commish_id'); |
35
|
|
|
$password = $request->headers->get(DRAFT_PASSWORD_HEADER, ''); |
|
|
|
|
36
|
|
|
|
37
|
|
|
$drafts = $app['phpdraft.DraftRepository']->GetPublicDraftsByCommish($request, $commish_id, $password); |
38
|
|
|
|
39
|
|
|
return $app->json($drafts); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function GetStats(Application $app, Request $request) { |
43
|
|
|
$draft_id = $request->get('draft_id'); |
44
|
|
|
$response = $app['phpdraft.DraftService']->GetDraftStats($draft_id); |
45
|
|
|
|
46
|
|
|
return $app->json($response, $response->responseType()); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|