|
1
|
|
|
<?php |
|
2
|
|
|
namespace PhpDraft\Domain\Services; |
|
3
|
|
|
|
|
4
|
|
|
use Silex\Application; |
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use PhpDraft\Domain\Entities\Draft; |
|
7
|
|
|
use PhpDraft\Domain\Models\PhpDraftResponse; |
|
8
|
|
|
use PhpDraft\Domain\Models\DepthChartDisplayModel; |
|
9
|
|
|
|
|
10
|
|
|
class DepthChartPositionService { |
|
11
|
|
|
private $app; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct(Application $app) { |
|
14
|
|
|
$this->app = $app; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function GetManagerDepthChart(Draft $draft, $manager_id) { |
|
18
|
|
|
$response = $this->app['phpdraft.ResponseFactory'](true, array()); |
|
19
|
|
|
|
|
20
|
|
|
try { |
|
21
|
|
|
$depthChartPositions = $this->app['phpdraft.DepthChartPositionRepository']->LoadAll($draft->draft_id); |
|
22
|
|
|
|
|
23
|
|
|
$response->manager_id = $manager_id; |
|
24
|
|
|
$response->depthChartPositions = array(); |
|
25
|
|
|
|
|
26
|
|
|
//Rather than hit the DB with 5 separate queries each depth chart request, hit it once and we cycle |
|
27
|
|
|
//through the PHP array in-memory five times performing either is_null checks or integer equality |
|
28
|
|
|
//checks: |
|
29
|
|
|
$allManagerPicks = $this->app['phpdraft.PickRepository']->LoadManagerPicks($manager_id, $draft, true); |
|
30
|
|
|
|
|
31
|
|
|
$unassignedPicks = array(); |
|
32
|
|
|
|
|
33
|
|
|
foreach ($allManagerPicks as $pick) { |
|
34
|
|
|
if (is_null($pick->depth_chart_position_id)) { |
|
35
|
|
|
$unassignedPicks[] = $pick; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$response->depthChartPositions[] = new DepthChartDisplayModel(null, 'Unassigned', null, $unassignedPicks); |
|
40
|
|
|
|
|
41
|
|
|
foreach ($depthChartPositions as $position) { |
|
42
|
|
|
$picks = array(); |
|
43
|
|
|
|
|
44
|
|
|
foreach ($allManagerPicks as $pick) { |
|
45
|
|
|
if ($pick->depth_chart_position_id == $position->id) { |
|
46
|
|
|
$picks[] = $pick; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$response->depthChartPositions[] = new DepthChartDisplayModel($position->id, $position->position, $position->slots, $picks); |
|
51
|
|
|
} |
|
52
|
|
|
} catch (\Exception $e) { |
|
53
|
|
|
$response->success = false; |
|
54
|
|
|
$response->errors[] = $e->getMessage(); |
|
55
|
|
|
|
|
56
|
|
|
return $response; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $response; |
|
60
|
|
|
} |
|
61
|
|
|
} |