DraftController::GetAllByCommish()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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, '');
0 ignored issues
show
Bug introduced by
The constant PhpDraft\Controllers\DRAFT_PASSWORD_HEADER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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, '');
0 ignored issues
show
Bug introduced by
The constant PhpDraft\Controllers\DRAFT_PASSWORD_HEADER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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, '');
0 ignored issues
show
Bug introduced by
The constant PhpDraft\Controllers\DRAFT_PASSWORD_HEADER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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