261                                                                                  : array
  262    {
  263        $result = $this->db->query(
  264            '
  265                        SELECT COUNT(tst_pass_result.workingtime) cnt
  266                        FROM object_reference
  267                        INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
  268                        INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
  269                        INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
  270                        INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
  271                                AND tst_pass_result.pass = tst_result_cache.pass
  272                        INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
  273                        WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
  274                        AND tst_active.user_fi != ' . $this->db->quote($a_user_id, 'integer') . '
  275                        AND round(reached_points/max_points*100) >=
  276                        (
  277                                SELECT round(reached_points/max_points*100)
  278                                FROM object_reference
  279                                INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
  280                                INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
  281                                INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
  282                                INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
  283                                        AND tst_pass_result.pass = tst_result_cache.pass
  284                                WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
  285                                AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
  286                        )
  287                '
  288        );
  289        $row = $this->db->fetchAssoc($result);
  290        $better_participants = $row['cnt'];
  291        $own_placement = $better_participants + 1;
  292 
  293        $result = $this->db->query(
  294            '
  295                        SELECT COUNT(tst_pass_result.workingtime) cnt
  296                        FROM object_reference
  297                        INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
  298                        INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
  299                        INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
  300                        INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
  301                                AND tst_pass_result.pass = tst_result_cache.pass
  302                        INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
  303                        WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer')
  304        );
  305        $row = $this->db->fetchAssoc($result);
  306        $number_total = $row['cnt'];
  307 
  308        $result = $this->db->query(
  309            '
  310                SELECT tst_result_cache.*, round(reached_points/max_points*100) as percentage ,
  311                        tst_pass_result.workingtime, usr_id, usr_data.firstname, usr_data.lastname
  312                FROM object_reference
  313                INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
  314                INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
  315                INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
  316                INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
  317                        AND tst_pass_result.pass = tst_result_cache.pass
  318                INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
  319 
  320                WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
  321                AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
  322 
  323                UNION(
  324                        SELECT tst_result_cache.*, round(reached_points/max_points*100) as percentage,
  325                                tst_pass_result.workingtime, usr_id, usr_data.firstname, usr_data.lastname
  326                        FROM object_reference
  327                        INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
  328                        INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
  329                        INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
  330                        INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
  331                                AND tst_pass_result.pass = tst_result_cache.pass
  332                        INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
  333                        WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
  334                        AND tst_active.user_fi != ' . $this->db->quote($a_user_id, 'integer') . '
  335                        AND round(reached_points/max_points*100) >=
  336                        (
  337                                SELECT round(reached_points/max_points*100)
  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                                WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
  345                                AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
  346                        )
  347                        ORDER BY round(reached_points/max_points*100) ASC
  348                        LIMIT 0, ' . $this->db->quote($this->object->getHighscoreTopNum(), 'integer') . '
  349                )
  350                UNION(
  351                        SELECT tst_result_cache.*, round(reached_points/max_points*100) as percentage,
  352                                tst_pass_result.workingtime, usr_id, usr_data.firstname, usr_data.lastname
  353                        FROM object_reference
  354                        INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
  355                        INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
  356                        INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
  357                        INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
  358                                AND tst_pass_result.pass = tst_result_cache.pass
  359                        INNER JOIN usr_data ON usr_data.usr_id = tst_active.user_fi
  360                        WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
  361                        AND tst_active.user_fi != ' . $this->db->quote($a_user_id, 'integer') . '
  362                        AND round(reached_points/max_points*100) <=
  363                        (
  364                                SELECT round(reached_points/max_points*100)
  365                                FROM object_reference
  366                                INNER JOIN tst_tests ON object_reference.obj_id = tst_tests.obj_fi
  367                                INNER JOIN tst_active ON tst_tests.test_id = tst_active.test_fi
  368                                INNER JOIN tst_result_cache ON tst_active.active_id = tst_result_cache.active_fi
  369                                INNER JOIN tst_pass_result ON tst_active.active_id = tst_pass_result.active_fi
  370                                        AND tst_pass_result.pass = tst_result_cache.pass
  371                                WHERE object_reference.ref_id = ' . $this->db->quote($a_test_ref_id, 'integer') . '
  372                                AND tst_active.user_fi = ' . $this->db->quote($a_user_id, 'integer') . '
  373                        )
  374                        ORDER BY round(reached_points/max_points*100) ASC
  375                        LIMIT 0, ' . $this->db->quote($this->object->getHighscoreTopNum(), 'integer') . '
  376                )
  377                ORDER BY round(reached_points/max_points*100) DESC, tstamp ASC
  378                LIMIT 0, ' . $this->db->quote($this->object->getHighscoreTopNum(), 'integer') . '
  379                '
  380        );
  381 
  382        $i = $own_placement - ($better_participants >= $this->
object->getHighscoreTopNum()
 
  383            ? $this->object->getHighscoreTopNum() : $better_participants);
  384 
  386 
  389            $data[] = $item;
  390        }
  391 
  392        while ($row = $this->db->fetchAssoc($result)) {
  396        }
  397 
  398        if ($number_total > 
$i) {
 
  400            $data[] = $item;
  401        }
  402 
  404    }