1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: dp |
5
|
|
|
* Date: 16.08.17 |
6
|
|
|
* Time: 13:09 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Lan\Ebs\Sdk; |
10
|
|
|
|
11
|
|
|
use Exception; |
12
|
|
|
|
13
|
|
|
final class Report implements Common |
14
|
|
|
{ |
15
|
|
|
private $client; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Security constructor. |
19
|
|
|
* |
20
|
|
|
* @param Client $client |
21
|
|
|
* @throws Exception |
22
|
|
|
*/ |
23
|
7 |
|
public function __construct(Client $client) |
24
|
|
|
{ |
25
|
7 |
|
if (!$client) { |
26
|
|
|
throw new Exception('Client not defined'); |
27
|
|
|
} |
28
|
|
|
|
29
|
7 |
|
$this->client = $client; |
30
|
7 |
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function getSecretKey($date) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
if (is_string($date) && strlen($date) >= 8) { |
35
|
|
|
$date = substr($date, 0, 8); |
36
|
|
|
|
37
|
|
|
if (!empty($_SESSION[$date])) { |
38
|
|
|
return $_SESSION[$date]; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return $_SESSION[$date] = $this->client->getResponse($this->getUrl(__FUNCTION__), ['date' => $date])['data']; |
43
|
|
|
} |
44
|
|
|
|
45
|
7 |
|
public function getUrl($method, array $params = []) |
46
|
|
|
{ |
47
|
|
|
switch ($method) { |
48
|
7 |
|
case 'getBooksViewsStatistics': |
49
|
|
|
return [ |
50
|
1 |
|
'url' => '/1.0/report/stat/book', |
51
|
1 |
|
'method' => 'GET', |
52
|
|
|
'code' => 200 |
53
|
1 |
|
]; |
54
|
6 |
|
case 'getJournalsViewsStatistics': |
55
|
|
|
return [ |
56
|
1 |
|
'url' => '/1.0/report/stat/journal', |
57
|
1 |
|
'method' => 'GET', |
58
|
|
|
'code' => 200 |
59
|
1 |
|
]; |
60
|
5 |
|
case 'getUsersVisitsSatistics': |
61
|
|
|
return [ |
62
|
1 |
|
'url' => '/1.0/report/stat/visit', |
63
|
1 |
|
'method' => 'GET', |
64
|
|
|
'code' => 200 |
65
|
1 |
|
]; |
66
|
4 |
|
case 'getAvailablePackets': |
67
|
|
|
return [ |
68
|
1 |
|
'url' => '/1.0/report/available/packet', |
69
|
1 |
|
'method' => 'GET', |
70
|
1 |
|
'params' => [], |
71
|
|
|
'code' => 200 |
72
|
1 |
|
]; |
73
|
3 |
|
case 'getAvailableBooks': |
74
|
|
|
return [ |
75
|
1 |
|
'url' => vsprintf('/1.0/report/available/book/%d', $params), |
76
|
1 |
|
'method' => 'GET', |
77
|
|
|
'code' => 200 |
78
|
1 |
|
]; |
79
|
2 |
|
case 'getAvailableJournals': |
80
|
|
|
return [ |
81
|
1 |
|
'url' => '/1.0/report/available/journal', |
82
|
1 |
|
'params' => [], |
83
|
1 |
|
'method' => 'GET', |
84
|
|
|
'code' => 200 |
85
|
1 |
|
]; |
86
|
1 |
|
case 'getFormReportEBooks': |
87
|
|
|
return [ |
88
|
1 |
|
'url' => '/1.0/report/form/eBooks', |
89
|
1 |
|
'params' => [], |
90
|
1 |
|
'method' => 'GET', |
91
|
|
|
'code' => 200 |
92
|
1 |
|
]; |
93
|
|
|
default: |
94
|
|
|
throw new Exception('Route for ' . $method . ' not found'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
View Code Duplication |
public function getBooksViewsStatistics($groupBy = null, $periodFrom = null, $periodTo = null) |
|
|
|
|
99
|
|
|
{ |
100
|
1 |
|
return $this->client->getResponse( |
101
|
1 |
|
$this->getUrl(__FUNCTION__), |
102
|
|
|
[ |
103
|
1 |
|
'group_by' => $groupBy, |
104
|
1 |
|
'period_range_from' => $periodFrom, |
105
|
1 |
|
'period_range_to' => $periodTo, |
106
|
|
|
] |
107
|
1 |
|
)['data']; |
108
|
|
|
} |
109
|
|
|
|
110
|
1 |
View Code Duplication |
public function getJournalsViewsStatistics($groupBy = null, $periodFrom = null, $periodTo = null) |
|
|
|
|
111
|
|
|
{ |
112
|
1 |
|
return $this->client->getResponse( |
113
|
1 |
|
$this->getUrl(__FUNCTION__), |
114
|
|
|
[ |
115
|
1 |
|
'group_by' => $groupBy, |
116
|
1 |
|
'period_range_from' => $periodFrom, |
117
|
1 |
|
'period_range_to' => $periodTo, |
118
|
|
|
] |
119
|
1 |
|
)['data']; |
120
|
|
|
} |
121
|
|
|
|
122
|
1 |
View Code Duplication |
public function getUsersVisitsSatistics($groupBy = null, $periodFrom = null, $periodTo = null) |
|
|
|
|
123
|
|
|
{ |
124
|
1 |
|
return $this->client->getResponse( |
125
|
1 |
|
$this->getUrl(__FUNCTION__), |
126
|
|
|
[ |
127
|
1 |
|
'group_by' => $groupBy, |
128
|
1 |
|
'period_range_from' => $periodFrom, |
129
|
1 |
|
'period_range_to' => $periodTo, |
130
|
|
|
] |
131
|
1 |
|
)['data']; |
132
|
|
|
} |
133
|
|
|
|
134
|
1 |
|
public function getAvailablePackets() |
135
|
|
|
{ |
136
|
1 |
|
return $this->client->getResponse($this->getUrl(__FUNCTION__))['data']; |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
public function getAvailableBooks($pdKey) |
140
|
|
|
{ |
141
|
1 |
|
return $this->client->getResponse($this->getUrl(__FUNCTION__, ['pdKey' => $pdKey]))['data']; |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
public function getAvailableJournals() |
145
|
|
|
{ |
146
|
1 |
|
return $this->client->getResponse($this->getUrl(__FUNCTION__))['data']; |
147
|
|
|
} |
148
|
|
|
|
149
|
1 |
|
public function getFormReportEBooks() |
150
|
|
|
{ |
151
|
1 |
|
return $this->client->getResponse($this->getUrl(__FUNCTION__))['data']; |
152
|
|
|
} |
153
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.