|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\BannerServer\Entity; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @license GPL-2.0-or-later |
|
9
|
|
|
*/ |
|
10
|
|
|
class Visitor { |
|
11
|
|
|
|
|
12
|
|
|
private int $totalImpressionCount = 0; |
|
13
|
|
|
private ?string $bucketIdentifier; |
|
14
|
|
|
private array $activeCategories; |
|
15
|
|
|
private int $displayWidth; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param int $totalImpressionCount How many banners the visitor has seen overall |
|
19
|
|
|
* @param string|null $bucketIdentifier Last bucket identifier of the visitor (to put recurring visitors in the same buckets, but only per-campaign) |
|
20
|
|
|
* @param int $displayWidth Viewport width of the visitor's browser window. |
|
21
|
|
|
* @param string ...$activeCategories |
|
22
|
|
|
*/ |
|
23
|
2 |
|
public function __construct( |
|
24
|
|
|
int $totalImpressionCount, |
|
25
|
|
|
?string $bucketIdentifier, |
|
26
|
|
|
int $displayWidth, |
|
27
|
|
|
string ...$activeCategories ) { |
|
28
|
2 |
|
$this->totalImpressionCount = $totalImpressionCount; |
|
29
|
2 |
|
$this->bucketIdentifier = $bucketIdentifier; |
|
30
|
2 |
|
$this->displayWidth = $displayWidth; |
|
31
|
2 |
|
$this->activeCategories = $activeCategories; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
public function getTotalImpressionCount(): int { |
|
35
|
1 |
|
return $this->totalImpressionCount; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public function getBucketIdentifier(): ?string { |
|
39
|
1 |
|
return $this->bucketIdentifier; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
public function inCategory( string $categoryName ): bool { |
|
43
|
2 |
|
return in_array( $categoryName, $this->activeCategories, true ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getDisplayWidth(): ?int { |
|
47
|
|
|
return $this->displayWidth; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @return string[] |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getCategories(): array { |
|
54
|
|
|
return $this->activeCategories; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|