@@ -14,6 +14,8 @@ class AttendanceLink extends AbstractLink
14
14
{
15
15
private $ attendance_table = null ;
16
16
17
+ private $ attendance_data = array ();
18
+
17
19
public function __construct ()
18
20
{
19
21
parent ::__construct ();
@@ -23,15 +25,15 @@ public function __construct()
23
25
/**
24
26
* @return string
25
27
*/
26
- public function get_type_name ()
28
+ public function get_type_name (): string
27
29
{
28
30
return get_lang ('Attendance ' );
29
31
}
30
32
31
33
/**
32
34
* @return bool
33
35
*/
34
- public function is_allowed_to_change_name ()
36
+ public function is_allowed_to_change_name (): bool
35
37
{
36
38
return false ;
37
39
}
@@ -76,8 +78,9 @@ public function get_all_links(): array
76
78
77
79
/**
78
80
* Has anyone done this exercise yet ?
81
+ * @throws Exception
79
82
*/
80
- public function has_results ()
83
+ public function has_results (): bool
81
84
{
82
85
$ tbl_attendance_result = Database::get_course_table (TABLE_ATTENDANCE_RESULT );
83
86
$ sessionId = $ this ->get_session_id ();
@@ -93,11 +96,12 @@ public function has_results()
93
96
}
94
97
95
98
/**
96
- * @param int $studentId
97
- *
98
- * @return array|null
99
+ * @param ?int $studentId
100
+ * @param ?string $type
101
+ * @return array
102
+ * @throws Exception
99
103
*/
100
- public function calc_score ($ studentId = null , $ type = null )
104
+ public function calc_score (? int $ studentId = null , ? string $ type = null ): array
101
105
{
102
106
$ tbl_attendance_result = Database::get_course_table (TABLE_ATTENDANCE_RESULT );
103
107
$ sessionId = $ this ->get_session_id ();
@@ -133,7 +137,7 @@ public function calc_score($studentId = null, $type = null)
133
137
// all students -> get average
134
138
$ students = []; // user list, needed to make sure we only
135
139
// take first attempts into account
136
- $ rescount = 0 ;
140
+ $ resultCount = 0 ;
137
141
$ sum = 0 ;
138
142
$ sumResult = 0 ;
139
143
$ bestResult = 0 ;
@@ -142,7 +146,7 @@ public function calc_score($studentId = null, $type = null)
142
146
if (!(array_key_exists ($ data ['user_id ' ], $ students ))) {
143
147
if (0 != $ attendance ['attendance_qualify_max ' ]) {
144
148
$ students [$ data ['user_id ' ]] = $ data ['score ' ];
145
- $ rescount ++;
149
+ $ resultCount ++;
146
150
$ sum += $ data ['score ' ] / $ attendance ['attendance_qualify_max ' ];
147
151
$ sumResult += $ data ['score ' ];
148
152
if ($ data ['score ' ] > $ bestResult ) {
@@ -153,51 +157,52 @@ public function calc_score($studentId = null, $type = null)
153
157
}
154
158
}
155
159
156
- if (0 == $ rescount ) {
160
+ if (0 == $ resultCount ) {
157
161
return [null , null ];
158
162
} else {
159
163
switch ($ type ) {
160
164
case 'best ' :
161
165
return [$ bestResult , $ weight ];
162
166
break ;
163
167
case 'average ' :
164
- return [$ sumResult / $ rescount , $ weight ];
168
+ return [$ sumResult / $ resultCount , $ weight ];
165
169
break ;
166
170
case 'ranking ' :
167
171
return AbstractLink::getCurrentUserRanking ($ studentId , $ students );
168
172
break ;
169
173
default :
170
- return [$ sum , $ rescount ];
174
+ return [$ sum , $ resultCount ];
171
175
break ;
172
176
}
173
177
}
174
178
}
175
179
}
176
180
177
- public function needs_name_and_description ()
181
+ public function needs_name_and_description (): bool
178
182
{
179
183
return false ;
180
184
}
181
185
182
- public function needs_max ()
186
+ public function needs_max (): bool
183
187
{
184
188
return false ;
185
189
}
186
190
187
- public function needs_results ()
191
+ public function needs_results (): bool
188
192
{
189
193
return false ;
190
194
}
191
195
192
196
/**
193
197
* @return string
198
+ * @throws \Doctrine\DBAL\Exception
194
199
*/
195
- public function get_name ()
200
+ public function get_name (): string
196
201
{
197
202
$ this ->get_attendance_data ();
198
- $ attendance_title = isset ( $ this ->attendance_data ['name ' ]) ? $ this -> attendance_data [ ' name ' ] : '' ;
199
- $ attendance_qualify_title = isset ( $ this ->attendance_data ['attendance_qualify_title ' ]) ? $ this -> attendance_data [ ' attendance_qualify_title ' ] : '' ;
200
- if (isset ( $ attendance_qualify_title ) && '' != $ attendance_qualify_title ) {
203
+ $ attendance_title = $ this ->attendance_data ['name ' ] ?? '' ;
204
+ $ attendance_qualify_title = $ this ->attendance_data ['attendance_qualify_title ' ] ?? '' ;
205
+ if ('' != $ attendance_qualify_title ) {
201
206
return $ this ->attendance_data ['attendance_qualify_title ' ];
202
207
} else {
203
208
return $ attendance_title ;
@@ -207,15 +212,16 @@ public function get_name()
207
212
/**
208
213
* @return string
209
214
*/
210
- public function get_description ()
215
+ public function get_description (): string
211
216
{
212
217
return '' ;
213
218
}
214
219
215
220
/**
216
221
* Check if this still links to an exercise.
222
+ * @throws Exception
217
223
*/
218
- public function is_valid_link ()
224
+ public function is_valid_link (): bool
219
225
{
220
226
$ sql = 'SELECT count(iid) FROM ' .$ this ->get_attendance_table ().'
221
227
WHERE iid = ' .$ this ->get_ref_id ();
@@ -225,7 +231,10 @@ public function is_valid_link()
225
231
return 0 != $ number [0 ];
226
232
}
227
233
228
- public function get_link ()
234
+ /**
235
+ * @throws Exception
236
+ */
237
+ public function get_link (): string
229
238
{
230
239
// it was extracts the attendance id
231
240
$ sessionId = $ this ->get_session_id ();
@@ -243,25 +252,26 @@ public function get_link()
243
252
/**
244
253
* @return string
245
254
*/
246
- public function get_icon_name ()
255
+ public function get_icon_name (): string
247
256
{
248
257
return 'attendance ' ;
249
258
}
250
259
251
260
/**
252
261
* Lazy load function to get the database table of the student publications.
253
262
*/
254
- private function get_attendance_table ()
263
+ private function get_attendance_table (): string
255
264
{
256
265
$ this ->attendance_table = Database::get_course_table (TABLE_ATTENDANCE );
257
266
258
267
return $ this ->attendance_table ;
259
268
}
260
269
261
270
/**
262
- * @return array|bool
271
+ * @return array
272
+ * @throws \Doctrine\DBAL\Exception
263
273
*/
264
- private function get_attendance_data ()
274
+ private function get_attendance_data (): array
265
275
{
266
276
if (!isset ($ this ->attendance_data )) {
267
277
$ sql = 'SELECT * FROM ' .$ this ->get_attendance_table ().' att
0 commit comments