function saveToDb()
 {
     global $ilDB, $ilLog;
     $submitted = $this->isSubmitted() ? 1 : 0;
     if ($this->active_id > 0) {
         $affectedRows = $ilDB->update('tst_active', array('lastindex' => array('integer', $this->getLastSequence()), 'tries' => array('integer', $this->getPass()), 'submitted' => array('integer', $submitted), 'submittimestamp' => array('timestamp', strlen($this->getSubmittedTimestamp()) ? $this->getSubmittedTimestamp() : NULL), 'tstamp' => array('integer', time() - 10), 'taxfilter' => array('text', serialize($this->getTaxonomyFilterSelection()))), array('active_id' => array('integer', $this->getActiveId())));
         // update learning progress
         include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
         include_once "./Services/Tracking/classes/class.ilLPStatusWrapper.php";
         ilLPStatusWrapper::_updateStatus(ilObjTestAccess::_lookupObjIdForTestId($this->getTestId()), ilObjTestAccess::_getParticipantId($this->getActiveId()));
     } else {
         if (!$this->activeIDExists($this->getUserId(), $this->getTestId())) {
             $anonymous_id = $this->getAnonymousId() ? $this->getAnonymousId() : NULL;
             $next_id = $ilDB->nextId('tst_active');
             $affectedRows = $ilDB->insert('tst_active', array('active_id' => array('integer', $next_id), 'user_fi' => array('integer', $this->getUserId()), 'anonymous_id' => array('text', $anonymous_id), 'test_fi' => array('integer', $this->getTestId()), 'lastindex' => array('integer', $this->getLastSequence()), 'tries' => array('integer', $this->getPass()), 'submitted' => array('integer', $submitted), 'submittimestamp' => array('timestamp', strlen($this->getSubmittedTimestamp()) ? $this->getSubmittedTimestamp() : NULL), 'tstamp' => array('integer', time() - 10), 'taxfilter' => array('text', serialize($this->getTaxonomyFilterSelection()))));
             $this->active_id = $next_id;
             // update learning progress
             include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
             include_once "./Services/Tracking/classes/class.ilLPStatusWrapper.php";
             ilLPStatusWrapper::_updateStatus(ilObjTestAccess::_lookupObjIdForTestId($this->getTestId()), $this->getUserId());
         }
     }
     include_once "./Services/Tracking/classes/class.ilLearningProgress.php";
     ilLearningProgress::_tracProgress($this->getUserId(), ilObjTestAccess::_lookupObjIdForTestId($this->getTestId()), $this->getRefId(), 'tst');
 }
 /**
  * This method is called after an user submitted one or more files.
  * It should handle the setting "Completion by Submission" and, if enabled, set the status of
  * the current user.
  *
  * @param	integer
  * @param	integer
  * @access	protected
  */
 protected function handleSubmission($active_id, $pass, $obligationsAnswered)
 {
     global $ilObjDataCache;
     if ($this->isCompletionBySubmissionEnabled()) {
         $maxpoints = assQuestion::_getMaximumPoints($this->getId());
         if ($this->getUploadedFiles($active_id, $pass)) {
             $points = $maxpoints;
         } else {
             $points = 0;
         }
         assQuestion::_setReachedPoints($active_id, $this->getId(), $points, $maxpoints, $pass, 1, $obligationsAnswered);
         // update learning progress
         include_once 'Modules/Test/classes/class.ilObjTestAccess.php';
         include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
         ilLPStatusWrapper::_updateStatus(ilObjTest::_getObjectIDFromActiveID((int) $active_id), ilObjTestAccess::_getParticipantId((int) $active_id));
     }
 }
 private function saveManScoringParticipantScreen($redirect = true)
 {
     global $tpl, $ilCtrl, $lng;
     $activeId = $this->fetchActiveIdParameter();
     $pass = $this->fetchPassParameter($activeId);
     $questionGuiList = $this->service->getManScoringQuestionGuiList($activeId, $pass);
     $form = $this->buildManScoringParticipantForm($questionGuiList, $activeId, $pass, false);
     $form->setValuesByPost();
     if (!$form->checkInput()) {
         ilUtil::sendFailure(sprintf($lng->txt('tst_save_manscoring_failed'), $pass + 1));
         return $this->showManScoringParticipantScreen($form);
     }
     include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
     $maxPointsByQuestionId = array();
     $maxPointsExceeded = false;
     foreach ($questionGuiList as $questionId => $questionGui) {
         $reachedPoints = $form->getItemByPostVar("question__{$questionId}__points")->getValue();
         $maxPoints = assQuestion::_getMaximumPoints($questionId);
         if ($reachedPoints > $maxPoints) {
             $maxPointsExceeded = true;
             $form->getItemByPostVar("question__{$questionId}__points")->setAlert(sprintf($lng->txt('tst_manscoring_maxpoints_exceeded_input_alert'), $maxPoints));
         }
         $maxPointsByQuestionId[$questionId] = $maxPoints;
     }
     if ($maxPointsExceeded) {
         ilUtil::sendFailure(sprintf($lng->txt('tst_save_manscoring_failed'), $pass + 1));
         return $this->showManScoringParticipantScreen($form);
     }
     include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
     foreach ($questionGuiList as $questionId => $questionGui) {
         $reachedPoints = $form->getItemByPostVar("question__{$questionId}__points")->getValue();
         assQuestion::_setReachedPoints($activeId, $questionId, $reachedPoints, $maxPointsByQuestionId[$questionId], $pass, 1, $this->object->areObligationsEnabled());
         $feedback = ilUtil::stripSlashes($form->getItemByPostVar("question__{$questionId}__feedback")->getValue(), false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
         $this->object->saveManualFeedback($activeId, $questionId, $pass, $feedback);
         $notificationData[$questionId] = array('points' => $reachedPoints, 'feedback' => $feedback);
     }
     include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
     include_once "./Services/Tracking/classes/class.ilLPStatusWrapper.php";
     ilLPStatusWrapper::_updateStatus($this->object->getId(), ilObjTestAccess::_getParticipantId($activeId));
     $manScoringDone = $form->getItemByPostVar("manscoring_done")->getChecked();
     ilTestService::setManScoringDone($activeId, $manScoringDone);
     $manScoringNotify = $form->getItemByPostVar("manscoring_notify")->getChecked();
     if ($manScoringNotify) {
         require_once 'Modules/Test/classes/notifications/class.ilTestManScoringParticipantNotification.php';
         $notification = new ilTestManScoringParticipantNotification($this->object->_getUserIdFromActiveId($activeId), $this->object->getRefId());
         $notification->setAdditionalInformation(array('test_title' => $this->object->getTitle(), 'test_pass' => $pass + 1, 'questions_gui_list' => $questionGuiList, 'questions_scoring_data' => $notificationData));
         $notification->send();
     }
     require_once './Modules/Test/classes/class.ilTestScoring.php';
     $scorer = new ilTestScoring($this->object);
     $scorer->setPreserveManualScores(true);
     $scorer->recalculateSolutions();
     if ($this->object->getAnonymity() == 0) {
         $user_name = ilObjUser::_lookupName(ilObjTestAccess::_getParticipantId($activeId));
         $name_real_or_anon = $user_name['firstname'] . ' ' . $user_name['lastname'];
     } else {
         $name_real_or_anon = $lng->txt('anonymous');
     }
     ilUtil::sendSuccess(sprintf($lng->txt('tst_saved_manscoring_successfully'), $pass + 1, $name_real_or_anon), true);
     if ($redirect == true) {
         $ilCtrl->redirect($this, 'showManScoringParticipantScreen');
     } else {
         return;
     }
 }
 public function saveManScoringByQuestion()
 {
     /**
      * @var $ilAccess ilAccessHandler
      */
     global $ilAccess, $lng;
     if (!$ilAccess->checkAccess('write', '', $this->ref_id)) {
         ilUtil::sendInfo($this->lng->txt('cannot_edit_test'), true);
         $this->ctrl->redirectByClass('ilobjtestgui', 'infoScreen');
     }
     if (!isset($_POST['scoring']) || !is_array($_POST['scoring'])) {
         ilUtil::sendFailure($this->lng->txt('tst_save_manscoring_failed_unknown'));
         $this->showManScoringByQuestionParticipantsTable();
         return;
     }
     include_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
     include_once 'Modules/Test/classes/class.ilObjTestAccess.php';
     include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
     $oneExceededMaxPoints = false;
     $manPointsPost = array();
     $skipParticipant = array();
     $maxPointsByQuestionId = array();
     foreach ($_POST['scoring'] as $pass => $active_ids) {
         foreach ((array) $active_ids as $active_id => $questions) {
             // check for existing test result data
             if (!$this->object->getTestResult($active_id, $pass)) {
                 if (!isset($skipParticipant[$pass])) {
                     $skipParticipant[$pass] = array();
                 }
                 $skipParticipant[$pass][$active_id] = true;
                 continue;
             }
             foreach ((array) $questions as $qst_id => $reached_points) {
                 if (!isset($manPointsPost[$pass])) {
                     $manPointsPost[$pass] = array();
                 }
                 if (!isset($manPointsPost[$pass][$active_id])) {
                     $manPointsPost[$pass][$active_id] = array();
                 }
                 $maxPointsByQuestionId[$qst_id] = assQuestion::_getMaximumPoints($qst_id);
                 if ($reached_points > $maxPointsByQuestionId[$qst_id]) {
                     $oneExceededMaxPoints = true;
                 }
                 $manPointsPost[$pass][$active_id][$qst_id] = $reached_points;
             }
         }
     }
     if ($oneExceededMaxPoints) {
         ilUtil::sendFailure(sprintf($this->lng->txt('tst_save_manscoring_failed'), $pass + 1));
         $this->showManScoringByQuestionParticipantsTable($manPointsPost);
         return;
     }
     $changed_one = false;
     foreach ($_POST['scoring'] as $pass => $active_ids) {
         foreach ((array) $active_ids as $active_id => $questions) {
             $update_participant = false;
             if ($skipParticipant[$pass][$active_id]) {
                 continue;
             }
             foreach ((array) $questions as $qst_id => $reached_points) {
                 $update_participant = assQuestion::_setReachedPoints($active_id, $qst_id, $reached_points, $maxPointsByQuestionId[$qst_id], $pass, 1, $this->object->areObligationsEnabled());
             }
             if ($update_participant) {
                 $changed_one = true;
                 ilLPStatusWrapper::_updateStatus($this->object->getId(), ilObjTestAccess::_getParticipantId($active_id));
             }
         }
     }
     if ($changed_one) {
         if ($this->object->getAnonymity() == 0) {
             $user_name = $user_name = ilObjUser::_lookupName(ilObjTestAccess::_getParticipantId($active_id));
             $name_real_or_anon = $user_name['firstname'] . ' ' . $user_name['lastname'];
         } else {
             $name_real_or_anon = $lng->txt('anonymous');
         }
         ilUtil::sendSuccess(sprintf($this->lng->txt('tst_saved_manscoring_successfully'), $pass + 1, $name_real_or_anon), true);
         require_once './Modules/Test/classes/class.ilTestScoring.php';
         $scorer = new ilTestScoring($this->object);
         $scorer->setPreserveManualScores(true);
         $scorer->recalculateSolutions();
         if ($this->object->getEnableArchiving()) {
             require_once 'Modules/Test/classes/class.ilTestArchiveService.php';
             $archiveService = new ilTestArchiveService($this->object);
             $archiveService->archivePassesByActives($scorer->getRecalculatedPassesByActives());
         }
     }
     $this->showManScoringByQuestionParticipantsTable();
 }
 function saveToDb()
 {
     global $ilDB, $ilLog;
     $submitted = $this->isSubmitted() ? 1 : 0;
     if ($this->active_id > 0) {
         $affectedRows = $ilDB->manipulateF("UPDATE tst_active SET lastindex = %s, tries = %s, submitted = %s, submittimestamp = %s, tstamp = %s WHERE active_id = %s", array('integer', 'integer', 'integer', 'timestamp', 'integer', 'integer'), array($this->getLastSequence(), $this->getPass(), $submitted, strlen($this->getSubmittedTimestamp()) ? $this->getSubmittedTimestamp() : NULL, time() - 10, $this->getActiveId()));
         // update learning progress
         include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
         include_once "./Services/Tracking/classes/class.ilLPStatusWrapper.php";
         ilLPStatusWrapper::_updateStatus(ilObjTestAccess::_lookupObjIdForTestId($this->getTestId()), ilObjTestAccess::_getParticipantId($this->getActiveId()));
     } else {
         if (!$this->activeIDExists($this->getUserId(), $this->getTestId())) {
             $anonymous_id = $this->getAnonymousId() ? $this->getAnonymousId() : NULL;
             $next_id = $ilDB->nextId('tst_active');
             $affectedRows = $ilDB->manipulateF("INSERT INTO tst_active (active_id, user_fi, anonymous_id, test_fi, lastindex, tries, submitted, submittimestamp, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'text', 'integer', 'integer', 'integer', 'integer', 'timestamp', 'integer'), array($next_id, $this->getUserId(), $anonymous_id, $this->getTestId(), $this->getLastSequence(), $this->getPass(), $submitted, strlen($this->getSubmittedTimestamp()) ? $this->getSubmittedTimestamp() : NULL, time() - 10));
             $this->active_id = $next_id;
             // update learning progress
             include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
             include_once "./Services/Tracking/classes/class.ilLPStatusWrapper.php";
             ilLPStatusWrapper::_updateStatus(ilObjTestAccess::_lookupObjIdForTestId($this->getTestId()), $this->getUserId());
         }
     }
     include_once "./Services/Tracking/classes/class.ilLearningProgress.php";
     ilLearningProgress::_tracProgress($this->getUserId(), ilObjTestAccess::_lookupObjIdForTestId($this->getTestId()), $this->getRefId(), 'tst');
 }