/
DownloadStatistics.php
151 lines (134 loc) · 3.86 KB
/
DownloadStatistics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
namespace Concrete\Core\Entity\File;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(
* name="DownloadStatistics",
* indexes={
* @ORM\Index(name="fID", columns={"fID", "timestamp"}),
* @ORM\Index(name="fvID", columns={"fID", "fvID"}),
* @ORM\Index(name="uID", columns={"uID"}),
* @ORM\Index(name="rcID", columns={"rcID"}),
* @ORM\Index(name="timestamp", columns={"timestamp"})
* },
* options={
* "comment": "List of downloaded files"
* }
* )
*/
class DownloadStatistics
{
/**
* The downloadStatistics record ID.
*
* @ORM\Id
* @ORM\Column(type="integer", name="dsID", nullable=false, options={"unsigned": true, "comment": "DownloadStatistics record ID"})
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var int|null NULL if not yet saved
*/
protected $id;
/**
* The downloaded file.
*
* @ORM\ManyToOne(targetEntity="File")
* @ORM\JoinColumn(name="fID", referencedColumnName="fID", nullable=false, onDelete="CASCADE")
*
* @var \Concrete\Core\Entity\File\File
*/
protected $file;
/**
* The version of the downloaded file.
*
* @ORM\Column(type="integer", name="fvID", nullable=false, options={"unsigned": false, "comment": "Version of the downloaded file"})
*
* @var int
*/
protected $fileVersion;
/**
* The ID of the user that downloaded the file.
*
* @ORM\Column(type="integer", name="uID", nullable=true, options={"unsigned": true, "comment": "ID of the user that downloaded the file"})
*
* @var int|null
*/
protected $downloaderID;
/**
* The ID of the page where the download originated.
*
* @ORM\Column(type="integer", name="rcID", nullable=true, options={"unsigned": true, "comment": "ID of the page where the download originated"})
*
* @var int|null
*/
protected $relatedPageID;
/**
* The date/time when the file has been downloaded.
*
* @ORM\Column(type="datetime_immutable", name="timestamp", nullable=false, columnDefinition="TIMESTAMP DEFAULT current_timestamp", options={"comment": "Date/time when the file has been downloaded"})
*
* @var \DateTimeImmutable
*/
protected $downloadDateTime;
protected function __construct()
{
}
/**
* @return static
*/
public static function create(File $file, int $fileVersion, ?int $downloaderID, ?int $relatedPageID, ?DateTimeImmutable $downloadDateTime = null): self
{
$result = new static();
$result->file = $file;
$result->fileVersion = $fileVersion;
$result->downloaderID = $downloaderID ?: null;
$result->relatedPageID = $relatedPageID ?: null;
$result->downloadDateTime = $downloadDateTime ?: new DateTimeImmutable('now');
return $result;
}
/**
* Get tthe downloadStatistics record ID.
*
* @return int|null NULL if not yet saved
*/
public function getID(): ?int
{
return $this->id;
}
/**
* Get the downloaded file.
*/
public function getFile(): File
{
return $this->file;
}
/**
* Get the version of the downloaded file.
*/
public function getFileVersion(): int
{
return $this->fileVersion;
}
/**
* Get the ID of the user that downloaded the file.
*/
public function getDownloaderID(): ?int
{
return $this->downloaderID;
}
/**
* Get the ID of the user that downloaded the file.
*/
public function getRelatedPageID(): ?int
{
return $this->relatedPageID;
}
/**
* Get the ID of the user that downloaded the file.
*/
public function getDownloadDateTime(): DateTimeImmutable
{
return $this->downloadDateTime;
}
}