|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Application\Model; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Enum\UserType; |
|
8
|
|
|
use Application\Repository\StatisticRepository; |
|
9
|
|
|
use Application\Traits\HasSite; |
|
10
|
|
|
use Application\Traits\HasSiteInterface; |
|
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
12
|
|
|
use InvalidArgumentException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* A statistic to record activity per month. |
|
16
|
|
|
* |
|
17
|
|
|
* - "Page" is any visited pages |
|
18
|
|
|
* - "Detail" is the detail page of a card |
|
19
|
|
|
* - "Search" is a search submission for cards |
|
20
|
|
|
* - "Login" is when a user logs in, possibly multiple times |
|
21
|
|
|
* - "UniqueLogin" is a when a unique user logs in (so only one time per user) |
|
22
|
|
|
*/ |
|
23
|
|
|
#[ORM\UniqueConstraint(name: 'unique_date', columns: ['date', 'site'])] |
|
24
|
|
|
#[ORM\Entity(StatisticRepository::class)] |
|
25
|
|
|
class Statistic extends AbstractModel implements HasSiteInterface |
|
26
|
|
|
{ |
|
27
|
|
|
use HasSite; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* A year and month, eg: '2019-02'. |
|
31
|
|
|
*/ |
|
32
|
|
|
#[ORM\Column(type: 'string', length: 7)] |
|
33
|
|
|
private string $date; |
|
34
|
|
|
|
|
35
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
36
|
|
|
private int $anonymousPageCount = 0; |
|
37
|
|
|
|
|
38
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
39
|
|
|
private int $defaultPageCount = 0; |
|
40
|
|
|
|
|
41
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
42
|
|
|
private int $aaiPageCount = 0; |
|
43
|
|
|
|
|
44
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
45
|
|
|
private int $anonymousDetailCount = 0; |
|
46
|
|
|
|
|
47
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
48
|
|
|
private int $defaultDetailCount = 0; |
|
49
|
|
|
|
|
50
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
51
|
|
|
private int $aaiDetailCount = 0; |
|
52
|
|
|
|
|
53
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
54
|
|
|
private int $anonymousSearchCount = 0; |
|
55
|
|
|
|
|
56
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
57
|
|
|
private int $defaultSearchCount = 0; |
|
58
|
|
|
|
|
59
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
60
|
|
|
private int $aaiSearchCount = 0; |
|
61
|
|
|
|
|
62
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
63
|
|
|
private int $defaultLoginCount = 0; |
|
64
|
|
|
|
|
65
|
|
|
#[ORM\Column(type: 'integer', options: ['default' => 0, 'unsigned' => true])] |
|
66
|
|
|
private int $aaiLoginCount = 0; |
|
67
|
|
|
|
|
68
|
|
|
#[ORM\Column(type: 'json')] |
|
69
|
|
|
private array $defaultLogins = []; |
|
70
|
|
|
|
|
71
|
|
|
#[ORM\Column(type: 'json')] |
|
72
|
|
|
private array $aaiLogins = []; |
|
73
|
|
|
|
|
74
|
|
|
public function getDate(): string |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->date; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
public function setDate(string $date): void |
|
80
|
|
|
{ |
|
81
|
1 |
|
$this->date = $date; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getAnonymousPageCount(): int |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->anonymousPageCount; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function getDefaultPageCount(): int |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->defaultPageCount; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getAaiPageCount(): int |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->aaiPageCount; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function getAnonymousDetailCount(): int |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->anonymousDetailCount; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function getDefaultDetailCount(): int |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->defaultDetailCount; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getAaiDetailCount(): int |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->aaiDetailCount; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getAnonymousSearchCount(): int |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->anonymousSearchCount; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getDefaultSearchCount(): int |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->defaultSearchCount; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function getAaiSearchCount(): int |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->aaiSearchCount; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function getDefaultLoginCount(): int |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->defaultLoginCount; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function getAaiLoginCount(): int |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->aaiLoginCount; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function getDefaultUniqueLoginCount(): int |
|
140
|
|
|
{ |
|
141
|
|
|
return count($this->defaultLogins); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function getAaiUniqueLoginCount(): int |
|
145
|
|
|
{ |
|
146
|
|
|
return count($this->aaiLogins); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function recordPage(): void |
|
150
|
|
|
{ |
|
151
|
|
|
$user = User::getCurrent(); |
|
152
|
|
|
if (!$user) { |
|
153
|
|
|
++$this->anonymousPageCount; |
|
154
|
|
|
} elseif ($user->getType() === UserType::Default) { |
|
155
|
|
|
++$this->defaultPageCount; |
|
156
|
|
|
} elseif ($user->getType() === UserType::Aai) { |
|
157
|
|
|
++$this->aaiPageCount; |
|
158
|
|
|
} else { |
|
159
|
|
|
throw new InvalidArgumentException('User type not supported: ' . $user->getType()->value); |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function recordDetail(): void |
|
164
|
|
|
{ |
|
165
|
|
|
$user = User::getCurrent(); |
|
166
|
|
|
if (!$user) { |
|
167
|
|
|
++$this->anonymousDetailCount; |
|
168
|
|
|
} elseif ($user->getType() === UserType::Default) { |
|
169
|
|
|
++$this->defaultDetailCount; |
|
170
|
|
|
} elseif ($user->getType() === UserType::Aai) { |
|
171
|
|
|
++$this->aaiDetailCount; |
|
172
|
|
|
} else { |
|
173
|
|
|
throw new InvalidArgumentException('User type not supported: ' . $user->getType()->value); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function recordSearch(): void |
|
178
|
|
|
{ |
|
179
|
|
|
$user = User::getCurrent(); |
|
180
|
|
|
if (!$user) { |
|
181
|
|
|
++$this->anonymousSearchCount; |
|
182
|
|
|
} elseif ($user->getType() === UserType::Default) { |
|
183
|
|
|
++$this->defaultSearchCount; |
|
184
|
|
|
} elseif ($user->getType() === UserType::Aai) { |
|
185
|
|
|
++$this->aaiSearchCount; |
|
186
|
|
|
} else { |
|
187
|
|
|
throw new InvalidArgumentException('User type not supported: ' . $user->getType()->value); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
1 |
|
public function recordLogin(): void |
|
192
|
|
|
{ |
|
193
|
1 |
|
$user = User::getCurrent(); |
|
194
|
1 |
|
if ($user->getType() === UserType::Default) { |
|
195
|
1 |
|
++$this->defaultLoginCount; |
|
196
|
|
|
|
|
197
|
1 |
|
if (!in_array($user->getId(), $this->defaultLogins, true)) { |
|
198
|
1 |
|
$this->defaultLogins[] = $user->getId(); |
|
199
|
|
|
} |
|
200
|
|
|
} elseif ($user->getType() === UserType::Aai) { |
|
201
|
|
|
++$this->aaiLoginCount; |
|
202
|
|
|
|
|
203
|
|
|
if (!in_array($user->getId(), $this->aaiLogins, true)) { |
|
204
|
|
|
$this->aaiLogins[] = $user->getId(); |
|
205
|
|
|
} |
|
206
|
|
|
} else { |
|
207
|
|
|
throw new InvalidArgumentException('User type not supported: ' . $user->getType()->value); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|