246 : array
247 {
249 '
250 SELECT COUNT(tst_pass_result.workingtime) cnt
251 FROM object_reference
252 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
253 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
254 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
255 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
256 AND tst_pass_result.pass = tst_result_cache.pass
257 INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
258 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
259 AND tst_active.user_fi != ' . $this->db->quote($a_user_id, 'integer') . '
260 AND round(reached_points/max_points*100) >=
261 (
262 SELECT round(reached_points/max_points*100)
263 FROM object_reference
264 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
265 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
266 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
267 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
268 AND tst_pass_result.pass = tst_result_cache.pass
269 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
270 AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
271 )
272 '
273 );
274 $row = $this->db->fetchAssoc(
$result);
275 $better_participants = $row['cnt'];
276 $own_placement = $better_participants + 1;
277
279 '
280 SELECT COUNT(tst_pass_result.workingtime) cnt
281 FROM object_reference
282 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
283 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
284 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
285 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
286 AND tst_pass_result.pass = tst_result_cache.pass
287 INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
288 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer')
289 );
290 $row = $this->db->fetchAssoc(
$result);
291 $number_total = $row['cnt'];
292
294 '
295 SELECT tst_result_cache.*, round(reached_points/max_points*100) as percentage ,
296 tst_pass_result.workingtime, usr_id, usr_data.firstname, usr_data.lastname
297 FROM object_reference
298 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
299 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
300 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
301 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
302 AND tst_pass_result.pass = tst_result_cache.pass
303 INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
304
305 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
306 AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
307
308 UNION(
309 SELECT tst_result_cache.*, round(reached_points/max_points*100) as percentage,
310 tst_pass_result.workingtime, usr_id, usr_data.firstname, usr_data.lastname
311 FROM object_reference
312 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
313 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
314 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
315 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
316 AND tst_pass_result.pass = tst_result_cache.pass
317 INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
318 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
319 AND tst_active.user_fi != ' . $this->db->quote($a_user_id, 'integer') . '
320 AND round(reached_points/max_points*100) >=
321 (
322 SELECT round(reached_points/max_points*100)
323 FROM object_reference
324 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
325 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
326 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
327 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
328 AND tst_pass_result.pass = tst_result_cache.pass
329 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
330 AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
331 )
332 ORDER BY round(reached_points/max_points*100) ASC
333 LIMIT 0,3
334 )
335 UNION(
336 SELECT tst_result_cache.*, round(reached_points/max_points*100) as percentage,
337 tst_pass_result.workingtime, usr_id, usr_data.firstname, usr_data.lastname
338 FROM object_reference
339 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
340 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
341 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
342 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
343 AND tst_pass_result.pass = tst_result_cache.pass
344 INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
345 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
346 AND tst_active.user_fi != ' . $this->db->quote($a_user_id, 'integer') . '
347 AND round(reached_points/max_points*100) <=
348 (
349 SELECT round(reached_points/max_points*100)
350 FROM object_reference
351 INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
352 INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
353 INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
354 INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
355 AND tst_pass_result.pass = tst_result_cache.pass
356 WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
357 AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
358 )
359 ORDER BY round(reached_points/max_points*100) ASC
360 LIMIT 0,3
361 )
362 ORDER BY round(reached_points/max_points*100) DESC, tstamp ASC
363 LIMIT 0, 7
364 '
365 );
366
367 $i = $own_placement - (($better_participants >= 3) ? 3 : $better_participants);
368
370
372 $item = ['Rank' => '...'];
374 }
375
376 while ($row = $this->db->fetchAssoc(
$result)) {
380 }
381
382 if ($number_total >
$i) {
383 $item = ['Rank' => '...'];
385 }
386
388 }