|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sausin\Signere\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Sausin\Signere\Statistics; |
|
8
|
|
|
use Sausin\Signere\Http\Controllers\Controller; |
|
9
|
|
|
|
|
10
|
|
|
class StatisticsController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var \Sausin\Signere\Statistics */ |
|
13
|
|
|
protected $statistics; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Create a new controller instance. |
|
17
|
|
|
* |
|
18
|
|
|
* @param \Sausin\Signere\Statistics $statistics |
|
19
|
|
|
*/ |
|
20
|
2 |
|
public function __construct(Statistics $statistics) |
|
21
|
|
|
{ |
|
22
|
2 |
|
parent::__construct(); |
|
23
|
|
|
|
|
24
|
2 |
|
$this->statistics = $statistics; |
|
25
|
2 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Get the statistics contrained by the given parameters. |
|
29
|
|
|
* |
|
30
|
|
|
* @param Request $request |
|
31
|
|
|
* @return \Illuminate\Http\Response |
|
32
|
|
|
*/ |
|
33
|
2 |
|
public function __invoke(Request $request) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$this->validate($request, [ |
|
36
|
2 |
|
'year' => 'sometimes|numeric|nullable|min:2015|max:'.Carbon::now()->year, |
|
37
|
2 |
|
'month' => 'sometimes|numeric|nullable|min:1|max:12', |
|
38
|
2 |
|
'day' => 'sometimes|numeric|nullable|min:1|max:31', |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
2 |
|
$allowedStatus = ['All', 'Canceled', 'Signed', 'Expired', 'Unsigned', 'Changed', 'PartialSigned']; |
|
42
|
2 |
|
$status = in_array($request->status, $allowedStatus, true) ? $request->status : 'All'; |
|
43
|
|
|
|
|
44
|
2 |
|
return $this->statistics->get($request->year, $request->month, $request->day, $status) |
|
45
|
2 |
|
->getBody() |
|
46
|
2 |
|
->getContents(); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|