Example #1
0
 /**
 * Returns the text answer of a given user for a given question
 *
 * @param integer $user_id The user id
 * @param integer $question_id The question id
 * @return string The answer text
 * @access public
 */
 function getTextAnswer($active_id, $question_id, $pass = NULL)
 {
     global $ilDB;
     $res = "";
     if ($active_id && $question_id) {
         if (is_null($pass)) {
             include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
             $pass = assQuestion::_getSolutionMaxPass($question_id, $active_id);
         }
         $result = $ilDB->queryF("SELECT value1 FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s", array('integer', 'integer', 'integer'), array($active_id, $question_id, $pass));
         if ($result->numRows() == 1) {
             $row = $ilDB->fetchAssoc($result);
             $res = $row["value1"];
         }
     }
     return $res;
 }
Example #2
0
 /**
  * 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;
     }
 }