public static function isParticipantsLastPassActive($testObjId, $userId)
 {
     global $ilDB, $lng, $ilPluginAdmin;
     /* @var ilObjTest $testOBJ */
     $testOBJ = ilObjectFactory::getInstanceByRefId($testObjId, false);
     $activeId = $testOBJ->getActiveIdOfUser($userId);
     require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
     $testSessionFactory = new ilTestSessionFactory($testOBJ);
     // Added temporarily bugfix smeyer
     $testSessionFactory->reset();
     require_once 'Modules/Test/classes/class.ilTestSequenceFactory.php';
     $testSequenceFactory = new ilTestSequenceFactory($ilDB, $lng, $ilPluginAdmin, $testOBJ);
     $testSession = $testSessionFactory->getSession($activeId);
     $testSequence = $testSequenceFactory->getSequenceByPass($testSession, $testSession->getPass());
     $testSequence->loadFromDb();
     return $testSequence->hasSequence();
 }
 /**
  * Calculates the results of a test for a given user
  * and returns an array with all test results
  *
  * @return array An array containing the test results for the given user
  * @access public
  */
 function &getTestResult($active_id, $pass = NULL, $ordered_sequence = FALSE)
 {
     global $tree, $ilDB, $lng, $ilPluginAdmin;
     $results = $this->getResultsForActiveId($active_id);
     if (is_null($pass)) {
         $pass = $results['pass'];
     }
     require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
     $testSessionFactory = new ilTestSessionFactory($this);
     $testSession = $testSessionFactory->getSession($active_id);
     require_once 'Modules/Test/classes/class.ilTestSequenceFactory.php';
     $testSequenceFactory = new ilTestSequenceFactory($ilDB, $lng, $ilPluginAdmin, $this);
     $testSequence = $testSequenceFactory->getSequenceByPass($testSession, $pass);
     if ($this->isDynamicTest()) {
         require_once 'Modules/Test/classes/class.ilObjTestDynamicQuestionSetConfig.php';
         $dynamicQuestionSetConfig = new ilObjTestDynamicQuestionSetConfig($tree, $ilDB, $ilPluginAdmin, $this);
         $dynamicQuestionSetConfig->loadFromDb();
         $testSequence->loadFromDb($dynamicQuestionSetConfig);
         $testSequence->loadQuestions($dynamicQuestionSetConfig, array());
         $sequence = $testSequence->getUserSequenceQuestions();
     } else {
         $testSequence->loadFromDb();
         $testSequence->loadQuestions();
         if ($ordered_sequence) {
             $sequence = $testSequence->getOrderedSequenceQuestions();
         } else {
             $sequence = $testSequence->getUserSequenceQuestions();
         }
     }
     $arrResults = array();
     $query = "\n\t\t\tSELECT\t\ttst_test_result.question_fi,\n\t\t\t\t\t\ttst_test_result.points reached,\n\t\t\t\t\t\ttst_test_result.hint_count requested_hints,\n\t\t\t\t\t\ttst_test_result.hint_points hint_points,\n\t\t\t\t\t\ttst_test_result.answered answered,\n\t\t\t\t\t\ttst_solutions.solution_id workedthru\n\t\t\t\n\t\t\tFROM\t\ttst_test_result\n\t\t\t\n\t\t\tLEFT JOIN\ttst_solutions\n\t\t\tON\t\t\ttst_solutions.active_fi = tst_test_result.active_fi\n\t\t\tAND\t\t\ttst_solutions.question_fi = tst_test_result.question_fi\n\t\t\t\n\t\t\tWHERE\t\ttst_test_result.active_fi = %s\n\t\t\tAND\t\t\ttst_test_result.pass = %s\n\t\t";
     $solutionresult = $ilDB->queryF($query, array('integer', 'integer'), array($active_id, $pass));
     while ($row = $ilDB->fetchAssoc($solutionresult)) {
         $arrResults[$row['question_fi']] = $row;
     }
     require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
     $IN_question_ids = $ilDB->in('qpl_questions.question_id', $sequence, false, 'integer');
     $query = "\n\t\t\tSELECT\t\tqpl_questions.*,\n\t\t\t\t\t\tqpl_qst_type.type_tag,\n\t\t\t\t\t\tqpl_sol_sug.question_fi has_sug_sol\n\t\t\t\n\t\t\tFROM\t\tqpl_qst_type,\n\t\t\t\t\t\tqpl_questions\n\t\t\t\n\t\t\tLEFT JOIN\tqpl_sol_sug\n\t\t\tON\t\t\tqpl_sol_sug.question_fi = qpl_questions.question_id\n\t\t\t\n\t\t\tWHERE\t\tqpl_qst_type.question_type_id = qpl_questions.question_type_fi\n\t\t\tAND\t\t\t{$IN_question_ids}\n\t\t";
     $result = $ilDB->query($query);
     $unordered = array();
     $key = 1;
     $obligationsAnswered = true;
     while ($row = $ilDB->fetchAssoc($result)) {
         $percentvalue = $row['points'] ? $arrResults[$row['question_id']]['reached'] / $row['points'] : 0;
         if ($percentvalue < 0) {
             $percentvalue = 0.0;
         }
         $data = array("nr" => "{$key}", "title" => ilUtil::prepareFormOutput($row['title']), "max" => round($row['points'], 2), "reached" => round($arrResults[$row['question_id']]['reached'], 2), 'requested_hints' => $arrResults[$row['question_id']]['requested_hints'], 'hint_points' => $arrResults[$row['question_id']]['hint_points'], "percent" => sprintf("%2.2f ", $percentvalue * 100) . "%", "solution" => $row['has_sug_sol'] ? assQuestion::_getSuggestedSolutionOutput($row['question_id']) : '', "type" => $row["type_tag"], "qid" => $row['question_id'], "original_id" => $row["original_id"], "workedthrough" => $arrResults[$row['question_id']]['workedthru'] ? 1 : 0, 'answered' => $arrResults[$row['question_id']]['answered']);
         if (!$arrResults[$row['question_id']]['answered']) {
             $obligationsAnswered = false;
         }
         $unordered[$row['question_id']] = $data;
         $key++;
     }
     $pass_max = 0;
     $pass_reached = 0;
     $pass_requested_hints = 0;
     $pass_hint_points = 0;
     $key = 1;
     $found = array();
     foreach ($sequence as $qid) {
         // building pass point sums based on prepared data
         // for question that exists in users qst sequence
         $pass_max += round($unordered[$qid]['max'], 2);
         $pass_reached += round($unordered[$qid]['reached'], 2);
         $pass_requested_hints += $unordered[$qid]['requested_hints'];
         $pass_hint_points += $unordered[$qid]['hint_points'];
         // pickup prepared data for question
         // that exists in users qst sequence
         $unordered[$qid]['nr'] = $key;
         array_push($found, $unordered[$qid]);
         // increment key counter
         $key++;
     }
     $unordered = null;
     if ($this->getScoreCutting() == 1) {
         if ($results['reached_points'] < 0) {
             $results['reached_points'] = 0;
         }
         if ($pass_reached < 0) {
             $pass_reached = 0;
         }
     }
     $found['pass']['total_max_points'] = $pass_max;
     $found['pass']['total_reached_points'] = $pass_reached;
     $found['pass']['total_requested_hints'] = $pass_requested_hints;
     $found['pass']['total_hint_points'] = $pass_hint_points;
     $found['pass']['percent'] = $pass_max > 0 ? $pass_reached / $pass_max : 0;
     $found['pass']['obligationsAnswered'] = $obligationsAnswered;
     $found["test"]["total_max_points"] = $results['max_points'];
     $found["test"]["total_reached_points"] = $results['reached_points'];
     $found["test"]["total_requested_hints"] = $results['hint_count'];
     $found["test"]["total_hint_points"] = $results['hint_points'];
     $found["test"]["result_pass"] = $results['pass'];
     $found['test']['obligations_answered'] = $results['obligations_answered'];
     if (!$total_reached_points or !$total_max_points) {
         $percentage = 0.0;
     } else {
         $percentage = $total_reached_points / $total_max_points * 100.0;
         if ($percentage < 0) {
             $percentage = 0.0;
         }
     }
     $found["test"]["passed"] = $results['passed'];
     return $found;
 }