protected function exportActiveIDs() { global $ilDB, $ilSetting; include_once "./Modules/Test/classes/class.ilObjTestAccess.php"; $assessmentSetting = new ilSetting("assessment"); $user_criteria = $assessmentSetting->get("user_criteria"); if (strlen($user_criteria) == 0) { $user_criteria = 'usr_id'; } if ($this->anonymized) { $result = $ilDB->queryF("SELECT * FROM tst_active WHERE test_fi = %s", array('integer'), array($this->test_id)); } else { $result = $ilDB->queryF("SELECT tst_active.*, usr_data." . $user_criteria . " FROM tst_active, usr_data WHERE tst_active.test_fi = %s AND tst_active.user_fi = usr_data.usr_id", array('integer'), array($this->test_id)); } $this->xmlStartTag("tst_active", NULL); while ($row = $ilDB->fetchAssoc($result)) { $attrs = array('active_id' => $row['active_id'], 'user_fi' => $row['user_fi'], 'anonymous_id' => $row['anonymous_id'], 'test_fi' => $row['test_fi'], 'lastindex' => $row['lastindex'], 'tries' => $row['tries'], 'submitted' => $row['submitted'], 'submittimestamp' => $row['submittimestamp'], 'tstamp' => $row['tstamp']); $attrs['fullname'] = ilObjTestAccess::_getParticipantData($row['active_id']); if (!$this->anonymized) { $attrs['user_criteria'] = $user_criteria; $attrs[$user_criteria] = $row[$user_criteria]; } array_push($this->active_ids, $row['active_id']); $this->xmlElement("row", $attrs); } $this->xmlEndTag("tst_active"); }
/** * Determine status * * @param integer object id * @param integer user id * @param object object (optional depends on object type) * @return integer status */ function determineStatus($a_obj_id, $a_user_id, $a_obj = null) { global $ilDB; include_once './Modules/Test/classes/class.ilObjTestAccess.php'; $res = $ilDB->query("\n\t\t\tSELECT active_id, user_fi, tries, COUNT(tst_sequence.active_fi) sequences\n\t\t\tFROM tst_active\n\t\t\tLEFT JOIN tst_sequence\n\t\t\tON tst_sequence.active_fi = tst_active.active_id\n\t\t\tWHERE user_fi = {$ilDB->quote($a_user_id, "integer")}\n\t\t\tAND test_fi = {$ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))}\n\t\t\tGROUP BY active_id, user_fi, tries\n\t\t"); $status = self::LP_STATUS_NOT_ATTEMPTED_NUM; if ($rec = $ilDB->fetchAssoc($res)) { if ($rec['sequences'] > 0) { $status = self::LP_STATUS_IN_PROGRESS_NUM; if ($rec['tries'] > 0) { $status = self::LP_STATUS_COMPLETED_NUM; } } } return $status; }
/** * Determine status * * @param integer object id * @param integer user id * @param object object (optional depends on object type) * @return integer status */ function determineStatus($a_obj_id, $a_user_id, $a_obj = null) { global $ilObjDataCache, $ilDB, $ilLog; $status = self::LP_STATUS_NOT_ATTEMPTED_NUM; include_once './Modules/Test/classes/class.ilObjTestAccess.php'; $res = $ilDB->query("SELECT tries FROM tst_active" . " WHERE user_fi = " . $ilDB->quote($a_user_id, "integer") . " AND test_fi = " . $ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))); if ($rec = $ilDB->fetchAssoc($res)) { if ($rec["tries"] == 0) { $status = self::LP_STATUS_IN_PROGRESS_NUM; } else { if ($rec["tries"] > 0) { $status = self::LP_STATUS_COMPLETED_NUM; } } } return $status; }
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->getQuestionSetFilterSelection()->getTaxonomySelection())), 'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection())), 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->getQuestionSetFilterSelection()->getTaxonomySelection())), 'answerstatusfilter' => array('text', $this->getQuestionSetFilterSelection()->getAnswerStatusSelection()))); $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'); }
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(); }
/** * checks wether a single condition is fulfilled * every trigger object type must implement a static method * _checkCondition($a_operator, $a_value) */ function _checkCondition($a_id, $a_usr_id = 0) { global $ilUser; $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId(); $condition = ilConditionHandler::_getCondition($a_id); switch ($condition['trigger_type']) { case "tst": include_once './Modules/Test/classes/class.ilObjTestAccess.php'; return ilObjTestAccess::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case "crs": include_once './Modules/Course/classes/class.ilObjCourse.php'; return ilObjCourse::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case 'exc': include_once './Modules/Exercise/classes/class.ilObjExercise.php'; return ilObjExercise::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case 'crsg': include_once './Modules/Course/classes/class.ilObjCourseGrouping.php'; return ilObjCourseGrouping::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); case 'sahs': include_once './Services/Tracking/classes/class.ilLPStatus.php'; return ilLPStatus::_lookupStatus($condition['trigger_obj_id'], $a_usr_id) == LP_STATUS_COMPLETED_NUM; case 'svy': include_once './Modules/Survey/classes/class.ilObjSurvey.php'; return ilObjSurvey::_checkCondition($condition['trigger_obj_id'], $condition['operator'], $condition['value'], $a_usr_id); default: return false; } }
/** * Get item properties * * @return array array of property arrays: * "alert" (boolean) => display as an alert property (usually in red) * "property" (string) => property name * "value" (string) => property value */ function getProperties() { global $lng, $ilUser; $props = array(); include_once "./Modules/Test/classes/class.ilObjTestAccess.php"; // if (!ilObjTestAccess::_lookupCreationComplete($this->obj_id)) // { // $props[] = array("alert" => true, "property" => $lng->txt("status"), // "value" => $lng->txt("tst_warning_test_not_complete")); // } if (!ilObjTestAccess::_isOnline($this->obj_id)) { $props[] = array("alert" => true, "property" => $lng->txt("status"), "value" => $lng->txt("offline")); } // we cannot use ilObjTestAccess::_isOffline() because of text messages $onlineaccess = ilObjTestAccess::_lookupOnlineTestAccess($this->obj_id, $ilUser->id); if ($onlineaccess !== true) { $props[] = array("alert" => true, "property" => $lng->txt("status"), "value" => $onlineaccess); } return $props; }
/** * Questions per page * * @param * @return */ function buildPageViewToolbar($qid = 0) { if ($this->create_question_mode) { return; } global $ilToolbar, $ilCtrl, $lng; require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php'; $this->getQuestionsSubTabs(); $ilCtrl->saveParameter($this, 'q_mode'); $ilCtrl->setParameterByClass('iltestexpresspageobjectgui', 'test_express_mode', 1); $ilCtrl->setParameter($this, 'test_express_mode', 1); $ilCtrl->setParameterByClass('iltestexpresspageobjectgui', 'q_id', $_REQUEST['q_id']); $ilCtrl->setParameter($this, 'q_id', $_REQUEST['q_id']); $ilToolbar->setFormAction($ilCtrl->getFormActionByClass('iltestexpresspageobjectgui', 'edit')); if ($this->object->evalTotalPersons() == 0) { /* include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php'; $pool = new ilObjQuestionPool(); $questionTypes = $pool->getQuestionTypes();$options = array(); foreach($questionTypes as $label => $data) { $options[$data['question_type_id']] = $label; } include_once("./Services/Form/classes/class.ilSelectInputGUI.php"); $si = new ilSelectInputGUI($lng->txt("test_add_new_question"), "qtype"); $si->setOptions($options); $ilToolbar->addInputItem($si, true); /* // use pool if ($this->object->isExpressModeQuestionPoolAllowed()) { include_once("./Services/Form/classes/class.ilCheckboxInputGUI.php"); $cb = new ilCheckboxInputGUI($lng->txt("test_use_pool"), "use_pool"); $ilToolbar->addInputItem($cb, true); } */ $ilToolbar->addFormButton($lng->txt("ass_create_question"), "addQuestion"); $ilToolbar->addSeparator(); if ($this->object->getPoolUsage()) { require_once 'Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php'; $this->populateQuestionBrowserToolbarButtons($ilToolbar, ilTestQuestionBrowserTableGUI::CONTEXT_PAGE_VIEW); $show_separator = true; } } $questions = $this->object->getQuestionTitlesAndIndexes(); // desc $options = array(); foreach ($questions as $id => $label) { $options[$id] = $label . ' [' . $this->lng->txt('question_id_short') . ': ' . $id . ']'; } $optionKeys = array_keys($options); if (!$options) { $options[] = $lng->txt('none'); } //else if (count($options) > 1) { // $addSeparator = false; // if ($optionKeys[0] != $qid) { // //$ilToolbar->addFormButton($lng->txt("test_prev_question"), "prevQuestion"); // $ilToolbar->addLink($lng->txt("test_prev_question"), $ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'prevQuestion')); // $addSeparator = true; // } // else { // $ilToolbar->addSpacer(45); // } // // if ($optionKeys[count($optionKeys)-1] != $qid) { // //$ilToolbar->addFormButton($lng->txt("test_next_question"), "nextQuestion"); // $ilToolbar->addLink($lng->txt("test_next_question"), $ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'nextQuestion')); // $addSeparator = true; // } // else { // $ilToolbar->addSpacer(45); // } // // //if ($addSeparator) { // $ilToolbar->addSeparator(); // //} if (count($questions)) { if (isset($show_separator) && $show_separator) { $ilToolbar->addSeparator(); } $btn = ilLinkButton::getInstance(); $btn->setCaption("test_prev_question"); $btn->setUrl($ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'prevQuestion')); $ilToolbar->addButtonInstance($btn); if (count($options) <= 1 || $optionKeys[0] == $qid) { $btn->setDisabled(true); } $btn = ilLinkButton::getInstance(); $btn->setCaption("test_next_question"); $btn->setUrl($ilCtrl->getLinkTargetByClass('iltestexpresspageobjectgui', 'nextQuestion')); $ilToolbar->addButtonInstance($btn); if (count($options) <= 1 || $optionKeys[count($optionKeys) - 1] == $qid) { $btn->setDisabled(true); } } if (count($questions) > 1) { $ilToolbar->addSeparator(); include_once "./Services/Form/classes/class.ilSelectInputGUI.php"; $si = new ilSelectInputGUI($lng->txt("test_jump_to"), "q_id"); $si->addCustomAttribute("onChange=\"forms['ilToolbar'].submit();\""); $si->setOptions($options); if ($qid) { $si->setValue($qid); } $ilToolbar->addInputItem($si, true); } $total = $this->object->evalTotalPersons(); /*if (count($options)) { include_once("./Services/Form/classes/class.ilSelectInputGUI.php"); $si = new ilSelectInputGUI($lng->txt("test_jump_to"), "q_id"); $si->addCustomAttribute("onChange=\"forms['ilToolbar'].submit();\""); $si->setOptions($options); if ($qid) { $si->setValue($qid); } $ilToolbar->addInputItem($si, true); }*/ if (count($questions) && !$total) { $ilCtrl->setParameter($this, 'q_id', $_REQUEST['q_id']); $ilToolbar->addSeparator(); $ilToolbar->addButton($lng->txt("test_delete_page"), $ilCtrl->getLinkTarget($this, "removeQuestions")); } if (count($questions) > 1 && !$total) { $ilToolbar->addSeparator(); $ilToolbar->addButton($lng->txt("test_move_page"), $ilCtrl->getLinkTarget($this, "movePageForm")); } global $ilAccess, $ilUser; $online_access = false; if ($this->object->getFixedParticipants()) { include_once "./Modules/Test/classes/class.ilObjTestAccess.php"; $online_access_result = ilObjTestAccess::_lookupOnlineTestAccess($this->object->getId(), $ilUser->getId()); if ($online_access_result === true) { $online_access = true; } } if ($this->object->isOnline() && $this->object->isComplete($this->testQuestionSetConfigFactory->getQuestionSetConfig())) { if ((!$this->object->getFixedParticipants() || $online_access) && $ilAccess->checkAccess("read", "", $this->ref_id)) { $testSession = $this->testSessionFactory->getSession(); $executable = $this->object->isExecutable($testSession, $ilUser->getId(), $allowPassIncrease = TRUE); if ($executable["executable"]) { $player_factory = new ilTestPlayerFactory($this->object); $player_instance = $player_factory->getPlayerGUI(); if ($testSession->getActiveId() > 0) { $ilToolbar->addSeparator(); $ilToolbar->addButton($lng->txt('tst_resume_test'), $ilCtrl->getLinkTarget($player_instance, 'resumePlayer')); } else { $ilToolbar->addSeparator(); $ilToolbar->addButton($lng->txt('tst_start_test'), $ilCtrl->getLinkTarget($player_instance, 'startTest')); } } } } }
/** * Calculates the number of questions in a test * * @return int The number of questions in the test * @access public */ function _getQuestionCount($test_id) { global $ilDB; $num = 0; $test =& ilObjTestAccess::_getTestData($test_id); if ($test["random_test"] == 1) { if ($test["random_question_count"] > 0) { $num = $test["random_question_count"]; } else { $result = $ilDB->queryF("SELECT SUM(num_of_q) questioncount FROM tst_test_random WHERE test_fi = %s ORDER BY test_random_id", array('integer'), array($test_id)); if ($result->numRows()) { $row = $ilDB->fetchAssoc($result); $num = $row["questioncount"]; } } } else { $result = $ilDB->queryF("SELECT test_question_id FROM tst_test_question WHERE test_fi = %s", array('integer'), array($test_id)); $num = $result->numRows(); } return $num; }
function isFullfilled($user_id, $item_id) { global $ilObjDataCache; include_once './Modules/Course/classes/class.ilCourseLMHistory.php'; $lm_continue =& new ilCourseLMHistory($this->getRefId(), $user_id); $continue_data = $lm_continue->getLMHistory(); $obj_id = $ilObjDataCache->lookupObjId($item_id); $type = $ilObjDataCache->lookupType($obj_id); switch ($type) { case 'tst': include_once './Modules/Test/classes/class.ilObjTestAccess.php'; if (!ilObjTestAccess::_checkCondition($obj_id, 'finished', '')) { return false; } break; case 'svy': include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php'; if (!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id)) { return false; } break; case 'sahs': include_once 'Services/Tracking/classes/class.ilLPStatus.php'; $completed = ilLPStatus::_lookupStatus($obj_id, $user_id); if ($completed == LP_STATUS_COMPLETED_NUM) { return false; } break; default: if (!isset($continue_data[$item_id])) { return false; } } return true; }
/** * check condition * * this method is called by ilConditionHandler */ public static function checkCondition($a_obj_id, $a_operator, $a_value, $a_usr_id) { include_once './Services/AccessControl/classes/class.ilConditionHandler.php'; switch ($a_operator) { case ilConditionHandler::OPERATOR_PASSED: return ilObjTestAccess::_isPassed($a_usr_id, $a_obj_id); break; case ilConditionHandler::OPERATOR_FAILED: return ilObjTestAccess::isFailed($a_usr_id, $a_obj_id); case ilConditionHandler::OPERATOR_FINISHED: return ilObjTestAccess::hasFinished($a_usr_id, $a_obj_id); case ilConditionHandler::OPERATOR_NOT_FINISHED: return !ilObjTestAccess::hasFinished($a_usr_id, $a_obj_id); default: return true; } return true; }
/** * Returns information if a specific user has finished a test * * @param integer $user_id Database id of the user * @param integer test obj_id * @return bool * @access public * @static */ function _hasFinished($a_user_id, $a_obj_id) { global $ilDB; $res = $ilDB->queryF("SELECT active_id FROM tst_active WHERE user_fi = %s AND test_fi = %s AND tries > '0'", array('integer', 'integer'), array($a_user_id, ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))); return $res->numRows() ? true : false; }
/** * Determine status. * * Behaviour of "old" 4.0 learning progress: * * Setting "Multiple Pass Scoring": Score the last pass * - Test not started: No entry * - First question opened: Icon/Text: Failed, Score 0% * - First question answered (correct, points enough for passing): Icon/Text: Completed, Score 66% * - No change after successfully finishing the pass. (100%) * - 2nd Pass, first question opened: Still Completed/Completed * - First question answered (incorrect, success possible): Icon/Text Failed, Score 33% * - Second question answered (correct): Icon/Text completed * - 3rd pass, like 2nd, but two times wrong answer: Icon/Text: Failed * * Setting "Multiple Pass Scoring": Score the best pass * - Test not started: No entry * - First question opened: Icon/Text: Failed, Score 0% * - First question answered (correct, points enough for passing): Icon/Text: Completed, Score 66% * - No change after successfully finishing the pass. (100%) * - 2nd Pass, first question opened: Still Completed/Completed * - First question answered (incorrect, success possible): Still Completed/Completed * * Due to this behaviour in 4.0 we do not have a "in progress" status. During the test * the status is "failed" unless the score is enough to pass the test, which makes the * learning progress status "completed". * * @param integer object id * @param integer user id * @param object object (optional depends on object type) * @return integer status */ function determineStatus($a_obj_id, $a_user_id, $a_obj = null) { global $ilObjDataCache, $ilDB, $ilLog; $status = self::LP_STATUS_NOT_ATTEMPTED_NUM; include_once './Modules/Test/classes/class.ilObjTestAccess.php'; $res = $ilDB->query("\n\t\t\tSELECT tst_active.active_id, tst_active.tries, count(tst_sequence.active_fi) sequences\n\t\t\tFROM tst_active\n\t\t\tLEFT JOIN tst_sequence\n\t\t\tON tst_sequence.active_fi = tst_active.active_id\n\t\t\tWHERE tst_active.user_fi = {$ilDB->quote($a_user_id, "integer")}\n\t\t\tAND tst_active.test_fi = {$ilDB->quote(ilObjTestAccess::_getTestIDFromObjectID($a_obj_id))}\n\t\t\tGROUP BY tst_active.active_id, tst_active.tries\n\t\t"); if ($rec = $ilDB->fetchAssoc($res)) { if ($rec['sequences'] > 0) { include_once './Modules/Test/classes/class.ilObjTestAccess.php'; if (ilObjTestAccess::_isPassed($a_user_id, $a_obj_id)) { $status = self::LP_STATUS_COMPLETED_NUM; } else { $status = self::LP_STATUS_FAILED_NUM; } } else { $status = self::LP_STATUS_NOT_ATTEMPTED_NUM; } } return $status; }
public static function getTestResultLinkForUser($a_test_ref_id, $a_user_id) { global $ilCtrl, $ilUser, $ilAccess; if ($ilUser->getId() == ANONYMOUS_USER_ID) { return; } $valid = $tutor = false; if ($a_user_id == $ilUser->getId()) { $valid = $ilAccess->checkAccess('read', '', $a_test_ref_id); } if (!$valid) { $valid = $ilAccess->checkAccess('write', '', $a_test_ref_id); $tutor = true; } if ($valid) { $testObjId = ilObject::_lookupObjId($a_test_ref_id); if (!$tutor) { require_once 'Modules/Test/classes/class.ilObjTestAccess.php'; if (ilObjTestAccess::visibleUserResultExists($testObjId, $a_user_id)) { $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', $a_test_ref_id); $link = $ilCtrl->getLinkTargetByClass(array('ilRepositoryGUI', 'ilObjTestGUI'), 'userResultsGateway'); $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', ''); return $link; } } else { include_once 'Modules/Test/classes/class.ilObjTest.php'; $testId = ilObjTest::_getTestIDFromObjectID($testObjId); if ($testId) { $userActiveId = ilObjTest::_getActiveIdOfUser($a_user_id, $testId); if ($userActiveId) { $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', $a_test_ref_id); $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', $userActiveId); $link = $ilCtrl->getLinkTargetByClass(array('ilRepositoryGUI', 'ilObjTestGUI', 'ilTestEvaluationGUI'), 'outParticipantsResultsOverview'); $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', ''); $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', ''); return $link; } } } } }
/** * Generates a ZIP file containing all file uploads for a given test and the original id of the question * * @param int $test_id */ public function getFileUploadZIPFile($test_id) { /** @var ilDB $ilDB */ global $ilDB; $query = "\n\t\tSELECT \n\t\t\ttst_solutions.solution_id, tst_solutions.pass, tst_solutions.active_fi, tst_solutions.question_fi, \n\t\t\ttst_solutions.value1, tst_solutions.value2, tst_solutions.tstamp \n\t\tFROM tst_solutions, tst_active, qpl_questions \n\t\tWHERE tst_solutions.active_fi = tst_active.active_id \n\t\tAND tst_solutions.question_fi = qpl_questions.question_id \n\t\tAND tst_solutions.question_fi = %s \n\t\tAND tst_active.test_fi = %s \n\t\tORDER BY tst_solutions.active_fi, tst_solutions.tstamp"; $result = $ilDB->queryF($query, array("integer", "integer"), array($this->getId(), $test_id)); $zipfile = ilUtil::ilTempnam() . ".zip"; $tempdir = ilUtil::ilTempnam(); if ($result->numRows()) { $userdata = array(); $data .= "<html><head>"; $data .= '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'; $data .= '<style> table { border: 1px #333 solid; border-collapse:collapse;} td, th { border: 1px #333 solid; padding: 0.25em;} th { color: #fff; background-color: #666;} </style> '; $data .= "<title>" . $this->getTitle() . "</title></head><body>\n"; $data .= "<h1>" . $this->getTitle() . "</h1>\n"; $data .= "<table><thead>\n"; $data .= "<tr><th>" . $this->lng->txt("name") . "</th><th>" . $this->lng->txt("filename") . "</th><th>" . $this->lng->txt("pass") . "</th><th>" . $this->lng->txt("location") . "</th><th>" . $this->lng->txt("date") . "</th></tr></thead><tbody>\n"; while ($row = $ilDB->fetchAssoc($result)) { ilUtil::makeDirParents($tempdir . "/" . $row["active_fi"] . "/" . $row["question_fi"]); @copy($this->getFileUploadPath($test_id, $row["active_fi"], $row["question_fi"]) . $row["value1"], $tempdir . "/" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"]); if (!array_key_exists($row["active_fi"], $userdata)) { include_once "./Modules/Test/classes/class.ilObjTestAccess.php"; $userdata[$row["active_fi"]] = ilObjTestAccess::_getParticipantData($row["active_fi"]); } $data .= "<tr><td>" . $userdata[$row["active_fi"]] . "</td><td><a href=\"" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"] . "\" target=\"_blank\">" . $row["value2"] . "</a></td><td>" . $row["pass"] . "</td><td>" . $row["active_fi"] . "/" . $row["question_fi"] . "/" . $row["value1"] . "</td>"; $data .= "<td>" . ilFormat::fmtDateTime(ilFormat::unixtimestamp2datetime($row["tstamp"]), $this->lng->txt("lang_dateformat"), $this->lng->txt("lang_timeformat"), "datetime", FALSE) . "</td>"; $data .= "</tr>\n"; } $data .= "</tbody></table>\n"; $data .= "</body></html>\n"; $indexfile = $tempdir . "/index.html"; $fh = fopen($indexfile, 'w'); fwrite($fh, $data); fclose($fh); } ilUtil::zip($tempdir, $zipfile); ilUtil::delDir($tempdir); ilUtil::deliverFile($zipfile, ilUtil::getASCIIFilename($this->getTitle() . ".zip"), "application/zip", false, true); }
private function handleUserResultsCommand($commands) { global $ilUser; if (!$this->isObjectiveTest()) { $commands = $this->removeUserResultsCommand($commands); } else { require_once 'Modules/Test/classes/class.ilObjTestAccess.php'; if (!ilObjTestAccess::visibleUserResultExists($this->obj_id, $ilUser->getId())) { $commands = $this->removeUserResultsCommand($commands); } } return $commands; }
/** * Check access rights for a test question * This checks also tests with random selection of questions * * @param int object id (question pool or test) * @param int usage id (not yet used) * @return boolean access given (true/false) */ private function checkAccessTestQuestion($obj_id, $usage_id = 0) { global $ilAccess; // give access if direct usage is readable if ($this->checkAccessObject($obj_id)) { return true; } $obj_type = ilObject::_lookupType($obj_id); if ($obj_type == 'qpl') { // give access if question pool is used by readable test // for random selection of questions include_once './Modules/Test/classes/class.ilObjTestAccess.php'; $tests = ilObjTestAccess::_getRandomTestsForQuestionPool($obj_id); foreach ($tests as $test_id) { if ($this->checkAccessObject($test_id, 'tst')) { return true; } } } return false; }
function isFullfilled($user_id, $item_id) { global $ilObjDataCache; include_once './Modules/Course/classes/class.ilCourseLMHistory.php'; $lm_continue =& new ilCourseLMHistory($this->getRefId(), $user_id); $continue_data = $lm_continue->getLMHistory(); $obj_id = $ilObjDataCache->lookupObjId($item_id); $type = $ilObjDataCache->lookupType($obj_id); switch ($type) { case 'tst': include_once './Modules/Test/classes/class.ilObjTestAccess.php'; include_once './Services/AccessControl/classes/class.ilConditionHandler.php'; if (!ilObjTestAccess::checkCondition($obj_id, ilConditionHandler::OPERATOR_FINISHED, '', $user_id)) { return false; } break; case 'svy': include_once './Modules/Survey/classes/class.ilObjSurveyAccess.php'; if (!ilObjSurveyAccess::_lookupFinished($obj_id, $user_id)) { return false; } break; case 'sahs': include_once 'Services/Tracking/classes/class.ilLPStatus.php'; if (!ilLPStatus::_hasUserCompleted($obj_id, $user_id)) { return false; } break; default: if (!isset($continue_data[$item_id])) { return false; } } return true; }
/** * Sets the points, a learner has reached answering the question * Additionally objective results are updated * * @param integer $user_id The database ID of the learner * @param integer $test_id The database Id of the test containing the question * @param integer $points The points the user has reached answering the question * @return boolean true on success, otherwise false * @access public */ function _setReachedPoints($active_id, $question_id, $points, $maxpoints, $pass, $manualscoring, $obligationsEnabled) { global $ilDB; if ($points <= $maxpoints) { if (is_null($pass)) { $pass = assQuestion::_getSolutionMaxPass($question_id, $active_id); } // retrieve the already given points $old_points = 0; $result = $ilDB->queryF("SELECT points FROM tst_test_result WHERE active_fi = %s AND question_fi = %s AND pass = %s", array('integer', 'integer', 'integer'), array($active_id, $question_id, $pass)); $manual = $manualscoring ? 1 : 0; $rowsnum = $result->numRows(); if ($rowsnum) { $row = $ilDB->fetchAssoc($result); $old_points = $row["points"]; if ($old_points != $points) { $affectedRows = $ilDB->manipulateF("UPDATE tst_test_result SET points = %s, manual = %s, tstamp = %s WHERE active_fi = %s AND question_fi = %s AND pass = %s", array('float', 'integer', 'integer', 'integer', 'integer', 'integer'), array($points, $manual, time(), $active_id, $question_id, $pass)); } } else { $next_id = $ilDB->nextId('tst_test_result'); $affectedRows = $ilDB->manipulateF("INSERT INTO tst_test_result (test_result_id, active_fi, question_fi, points, pass, manual, tstamp) VALUES (%s, %s, %s, %s, %s, %s, %s)", array('integer', 'integer', 'integer', 'float', 'integer', 'integer', 'integer'), array($next_id, $active_id, $question_id, $points, $pass, $manual, time())); } if ($old_points != $points || !$rowsnum) { assQuestion::_updateTestPassResults($active_id, $pass, $obligationsEnabled); // finally update objective result include_once "./Modules/Test/classes/class.ilObjTest.php"; include_once './Modules/Course/classes/class.ilCourseObjectiveResult.php'; ilCourseObjectiveResult::_updateObjectiveResult(ilObjTest::_getUserIdFromActiveId($active_id), $question_id, $points); include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php"; if (ilObjAssessmentFolder::_enabledAssessmentLogging()) { global $lng, $ilUser; include_once "./Modules/Test/classes/class.ilObjTestAccess.php"; $username = ilObjTestAccess::_getParticipantData($active_id); assQuestion::_logAction(sprintf($lng->txtlng("assessment", "log_answer_changed_points", ilObjAssessmentFolder::_getLogLanguage()), $username, $old_points, $points, $ilUser->getFullname() . " (" . $ilUser->getLogin() . ")"), $active_id, $question_id); } } return TRUE; } else { return FALSE; } }
/** * Saves the manual feedback for a question in a test * * @param integer $active_id Active ID of the user * @param integer $question_id Question ID * @param integer $pass Pass number * @param string $feedback The feedback text * @return boolean TRUE if the operation succeeds, FALSE otherwise * @access public */ function saveManualFeedback($active_id, $question_id, $pass, $feedback) { global $ilDB; $affectedRows = $ilDB->manipulateF("DELETE FROM tst_manual_fb WHERE active_fi = %s AND question_fi = %s AND pass = %s", array('integer', 'integer', 'integer'), array($active_id, $question_id, $pass)); if (strlen($feedback)) { $next_id = $ilDB->nextId('tst_manual_fb'); /** @var ilDB $ilDB */ $result = $ilDB->insert('tst_manual_fb', array('manual_feedback_id' => array('integer', $next_id), 'active_fi' => array('integer', $active_id), 'question_fi' => array('integer', $question_id), 'pass' => array('integer', $pass), 'feedback' => array('clob', ilRTE::_replaceMediaObjectImageSrc($feedback, 0)), 'tstamp' => array('integer', time()))); include_once "./Modules/Test/classes/class.ilObjAssessmentFolder.php"; if (ilObjAssessmentFolder::_enabledAssessmentLogging()) { global $lng, $ilUser; include_once "./Modules/Test/classes/class.ilObjTestAccess.php"; $username = ilObjTestAccess::_getParticipantData($active_id); include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $this->logAction(sprintf($lng->txtlng("assessment", "log_manual_feedback", ilObjAssessmentFolder::_getLogLanguage()), $ilUser->getFullname() . " (" . $ilUser->getLogin() . ")", $username, assQuestion::_getQuestionTitle($question_id), $feedback)); } } if (PEAR::isError($result)) { global $ilias; $ilias->raiseError($result->getMessage()); } else { return TRUE; } }
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'); }