|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Entity; |
|
8
|
|
|
|
|
9
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
10
|
|
|
use DateTime; |
|
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
12
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
13
|
|
|
|
|
14
|
|
|
#[ApiResource( |
|
15
|
|
|
normalizationContext: [ |
|
16
|
|
|
'groups' => ['trackCourseRanking:read'], |
|
17
|
|
|
], |
|
18
|
|
|
denormalizationContext: [ |
|
19
|
|
|
'groups' => ['trackCourseRanking:write'], |
|
20
|
|
|
], |
|
21
|
|
|
security: "is_granted('ROLE_USER')" |
|
22
|
|
|
)] |
|
23
|
|
|
#[ORM\Table(name: 'track_course_ranking')] |
|
24
|
|
|
#[ORM\Index(columns: ['c_id'], name: 'idx_tcc_cid')] |
|
25
|
|
|
#[ORM\Index(columns: ['session_id'], name: 'idx_tcc_sid')] |
|
26
|
|
|
#[ORM\Index(columns: ['url_id'], name: 'idx_tcc_urlid')] |
|
27
|
|
|
#[ORM\Index(columns: ['creation_date'], name: 'idx_tcc_creation_date')] |
|
28
|
|
|
#[ORM\Entity] |
|
29
|
|
|
class TrackCourseRanking |
|
30
|
|
|
{ |
|
31
|
|
|
#[Groups(['course:read', 'trackCourseRanking:read'])] |
|
32
|
|
|
#[ORM\Column(name: 'id', type: 'integer')] |
|
33
|
|
|
#[ORM\Id] |
|
34
|
|
|
#[ORM\GeneratedValue(strategy: 'IDENTITY')] |
|
35
|
|
|
protected ?int $id = null; |
|
36
|
|
|
#[Groups(['course:read', 'trackCourseRanking:read', 'trackCourseRanking:write'])] |
|
37
|
|
|
#[ORM\OneToOne(inversedBy: 'trackCourseRanking', targetEntity: Course::class)] |
|
38
|
|
|
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', nullable: false, onDelete: 'cascade')] |
|
39
|
|
|
protected Course $course; |
|
40
|
|
|
#[Groups(['trackCourseRanking:read', 'trackCourseRanking:write'])] |
|
41
|
|
|
#[ORM\Column(name: 'session_id', type: 'integer', nullable: false)] |
|
42
|
|
|
protected int $sessionId; |
|
43
|
|
|
#[Groups(['trackCourseRanking:read', 'trackCourseRanking:write'])] |
|
44
|
|
|
#[ORM\Column(name: 'url_id', type: 'integer', nullable: false)] |
|
45
|
|
|
protected int $urlId; |
|
46
|
|
|
#[Groups(['course:read', 'trackCourseRanking:read'])] |
|
47
|
|
|
#[ORM\Column(name: 'accesses', type: 'integer', nullable: false)] |
|
48
|
|
|
protected int $accesses; |
|
49
|
|
|
#[Groups(['course:read', 'trackCourseRanking:read', 'trackCourseRanking:write'])] |
|
50
|
|
|
#[ORM\Column(name: 'total_score', type: 'integer', nullable: false)] |
|
51
|
|
|
protected int $totalScore; |
|
52
|
|
|
#[Groups(['course:read'])] |
|
53
|
|
|
#[ORM\Column(name: 'users', type: 'integer', nullable: false)] |
|
54
|
|
|
protected int $users; |
|
55
|
|
|
#[ORM\Column(name: 'creation_date', type: 'datetime', nullable: false)] |
|
56
|
|
|
protected DateTime $creationDate; |
|
57
|
|
|
#[Groups(['course:read', 'trackCourseRanking:read'])] |
|
58
|
|
|
protected ?int $realTotalScore = null; |
|
59
|
|
|
|
|
60
|
|
|
public function __construct() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->urlId = 0; |
|
63
|
|
|
$this->accesses = 0; |
|
64
|
|
|
$this->totalScore = 0; |
|
65
|
|
|
$this->users = 0; |
|
66
|
|
|
$this->creationDate = new DateTime(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getCourse(): Course |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->course; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function setCourse(Course $course): self |
|
75
|
|
|
{ |
|
76
|
|
|
$this->course = $course; |
|
77
|
|
|
|
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get sessionId. |
|
83
|
|
|
* |
|
84
|
|
|
* @return int |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getSessionId() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->sessionId; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Set sessionId. |
|
93
|
|
|
* |
|
94
|
|
|
* @return TrackCourseRanking |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setSessionId(int $sessionId) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->sessionId = $sessionId; |
|
99
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get urlId. |
|
105
|
|
|
* |
|
106
|
|
|
* @return int |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getUrlId() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->urlId; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Set urlId. |
|
115
|
|
|
* |
|
116
|
|
|
* @return TrackCourseRanking |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setUrlId(int $urlId) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->urlId = $urlId; |
|
121
|
|
|
|
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get accesses. |
|
127
|
|
|
* |
|
128
|
|
|
* @return int |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getAccesses() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->accesses; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Set accesses. |
|
137
|
|
|
* |
|
138
|
|
|
* @return TrackCourseRanking |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setAccesses(int $accesses) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->accesses = $accesses; |
|
143
|
|
|
|
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Get totalScore. |
|
149
|
|
|
* |
|
150
|
|
|
* @return int |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getTotalScore() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->totalScore; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Set totalScore. |
|
159
|
|
|
* |
|
160
|
|
|
* @return TrackCourseRanking |
|
161
|
|
|
*/ |
|
162
|
|
|
public function setTotalScore(int $totalScore) |
|
163
|
|
|
{ |
|
164
|
|
|
$this->users++; |
|
165
|
|
|
$this->totalScore += $totalScore; |
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Get users. |
|
172
|
|
|
* |
|
173
|
|
|
* @return int |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getUsers() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->users; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Set users. |
|
182
|
|
|
* |
|
183
|
|
|
* @return TrackCourseRanking |
|
184
|
|
|
*/ |
|
185
|
|
|
public function setUsers(int $users) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->users = $users; |
|
188
|
|
|
|
|
189
|
|
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Get creationDate. |
|
194
|
|
|
* |
|
195
|
|
|
* @return DateTime |
|
196
|
|
|
*/ |
|
197
|
|
|
public function getCreationDate() |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->creationDate; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Set creationDate. |
|
204
|
|
|
* |
|
205
|
|
|
* @return TrackCourseRanking |
|
206
|
|
|
*/ |
|
207
|
|
|
public function setCreationDate(DateTime $creationDate) |
|
208
|
|
|
{ |
|
209
|
|
|
$this->creationDate = $creationDate; |
|
210
|
|
|
|
|
211
|
|
|
return $this; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Get id. |
|
216
|
|
|
* |
|
217
|
|
|
* @return int |
|
218
|
|
|
*/ |
|
219
|
|
|
public function getId() |
|
220
|
|
|
{ |
|
221
|
|
|
return $this->id; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function getRealTotalScore(): int |
|
225
|
|
|
{ |
|
226
|
|
|
if (0 !== $this->totalScore && 0 !== $this->users) { |
|
227
|
|
|
return (int) round($this->totalScore / $this->users); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
return 0; |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|