1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Web; |
4
|
|
|
|
5
|
|
|
use App\Entities\Problem; |
6
|
|
|
use App\Http\Controllers\Controller; |
7
|
|
|
use App\Repositories\Criteria\SearchByColumn; |
8
|
|
|
use App\Repositories\Criteria\Where; |
9
|
|
|
use App\Repositories\ProblemRepository; |
10
|
|
|
use App\Services\SummaryService; |
11
|
|
|
|
12
|
|
|
class ProblemController extends Controller |
13
|
|
|
{ |
14
|
|
|
private $repository; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* ProblemController constructor. |
18
|
|
|
* |
19
|
|
|
* @param ProblemRepository $repository |
20
|
|
|
*/ |
21
|
|
|
public function __construct(ProblemRepository $repository) |
22
|
|
|
{ |
23
|
|
|
$this->repository = $repository; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function show($id) |
27
|
|
|
{ |
28
|
|
|
/** @var Problem $problem */ |
29
|
|
|
$problem = $this->repository->findOrFail($id); |
30
|
|
|
if (! $problem->isAvailable()) { |
31
|
|
|
return back()->withErrors('Problem is not found!'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return view('web.problem.show', ['problem' => $problem]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function index() |
38
|
|
|
{ |
39
|
|
|
if (request('text')) { |
40
|
|
|
$searchByColumn = new SearchByColumn(request('text'), request('area')); |
41
|
|
|
$this->repository->pushCriteria($searchByColumn); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->repository->pushCriteria(new Where('status', Problem::ST_NORMAL)); |
45
|
|
|
|
46
|
|
|
$perPage = request('per_page', 100); |
47
|
|
|
$problems = $this->repository->paginate($perPage); |
|
|
|
|
48
|
|
|
|
49
|
|
|
return view('web.problem.index', ['problems' => $problems]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function summary($id) |
53
|
|
|
{ |
54
|
|
|
/** @var Problem $problem */ |
55
|
|
|
$problem = $this->repository->findOrFail($id); |
56
|
|
|
if (! $problem->isAvailable()) { |
57
|
|
|
return back()->withErrors('Problem is not found!'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$summary = new SummaryService($problem); |
61
|
|
|
|
62
|
|
|
return view('web.problem.summary', ['summary' => $summary, 'perPage' => 50, 'problem' => $problem]); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|