Total Complexity | 5 |
Total Lines | 53 |
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 | $model = new Contest(); |
||
19 | |||
20 | return $this->update($model, $attrs, $startAt, $endAt); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @param Contest $contest |
||
25 | * @param array $attrs |
||
26 | * @param string $startAt |
||
27 | * @param string $endAt |
||
28 | * |
||
29 | * @return \App\Entities\Contest |
||
30 | */ |
||
31 | public function update($contest, $attrs, $startAt, $endAt) { |
||
32 | $contest->fill($attrs); |
||
33 | $contest->start_time = Carbon::parse($startAt); |
||
34 | $contest->end_time = Carbon::parse($endAt); |
||
35 | |||
36 | $contest->save(); |
||
37 | |||
38 | return $contest; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param Contest $contest |
||
43 | * @param array $problemIds |
||
44 | */ |
||
45 | public function syncProblems($contest, $problemIds) { |
||
46 | $relations = []; |
||
47 | $index = 0; |
||
48 | foreach ($problemIds as $id) { |
||
49 | $relations[$id] = ['order' => $index]; |
||
50 | $index++; |
||
51 | } |
||
52 | $contest->problems()->sync($relations); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param Contest $contest |
||
57 | * @param array $userIds |
||
58 | */ |
||
59 | public function syncUser($contest, $userIds) { |
||
61 | } |
||
62 | } |
||
63 |