Total Complexity | 5 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class ContestManager |
||
9 | { |
||
10 | /** |
||
11 | * @param array $attrs |
||
12 | * @param string $startAt |
||
13 | * @param string $endAt |
||
14 | * |
||
15 | * @return \App\Entities\Contest |
||
16 | */ |
||
17 | public function create($attrs, $startAt, $endAt) |
||
18 | { |
||
19 | $model = new Contest(); |
||
20 | |||
21 | return $this->update($model, $attrs, $startAt, $endAt); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param Contest $contest |
||
26 | * @param array $attrs |
||
27 | * @param string $startAt |
||
28 | * @param string $endAt |
||
29 | * |
||
30 | * @return \App\Entities\Contest |
||
31 | */ |
||
32 | public function update($contest, $attrs, $startAt, $endAt) |
||
33 | { |
||
34 | $contest->fill($attrs); |
||
35 | $contest->start_time = Carbon::parse($startAt); |
||
36 | $contest->end_time = Carbon::parse($endAt); |
||
37 | |||
38 | $contest->save(); |
||
39 | |||
40 | return $contest; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param Contest $contest |
||
45 | * @param array $problemIds |
||
46 | */ |
||
47 | public function syncProblems($contest, $problemIds) |
||
48 | { |
||
49 | $relations = []; |
||
50 | $index = 0; |
||
51 | foreach ($problemIds as $id) { |
||
52 | $relations[$id] = ['order' => $index]; |
||
53 | $index++; |
||
54 | } |
||
55 | $contest->problems()->sync($relations); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param Contest $contest |
||
60 | * @param array $userIds |
||
61 | */ |
||
62 | public function syncUser($contest, $userIds) |
||
65 | } |
||
66 | } |
||
67 |