34         $this->questionrepository = TestDIC::dic()[
'general_question_properties_repository'];
    44         $ilAccess = $DIC[
'ilAccess'];
    46         $permission_ok = 
false;
    47         $result = 
$ilDB->queryF(
    48             "SELECT tst_tests.obj_fi FROM tst_active, tst_tests WHERE tst_active.active_id = %s AND tst_active.test_fi = tst_tests.test_id",
    52         $row = 
$ilDB->fetchAssoc($result);
    54             $obj_id = $row[
'obj_fi'];
    56                 if ($ilAccess->checkAccess(
"write", 
"", $ref_id)) {
    57                     $permission_ok = 
true;
    62         return $permission_ok;
    65     public function isAllowedCall(
string $sid, 
int $active_id, 
bool $saveaction = 
true): bool
    72         $ilUser = $DIC[
'ilUser'];
    79             $result = 
$ilDB->queryF(
    80                 "SELECT * FROM tst_times WHERE active_fi = %s ORDER BY started DESC",
    84             if ($result->numRows()) {
    85                 $row = 
$ilDB->fetchAssoc($result);
    86                 if (preg_match(
"/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $row[
"started"], $matches)) {
    87                     $time = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    93                     $ilClientIniFile = $DIC[
'ilClientIniFile'];
    94                     $expires = $ilClientIniFile->readVariable(
'session', 
'expire');
    95                     return $diff <= $expires;
   104         $result = 
$ilDB->queryF(
   105             "SELECT user_fi FROM tst_active WHERE active_id = %s",
   109         $row = 
$ilDB->fetchAssoc($result);
   111         return (
int) $row[
'user_fi'] === $ilUser->getId();
   117     public function saveQuestion(
string $sid, 
int $active_id, 
int $question_id, 
int $pass, array $solution)
   126             return $this->
raiseError(
"The required user information is only available for active users.", 
"");
   131         $ilDB = $DIC[
'ilDB'];
   132         $ilUser = $DIC[
'ilUser'];
   135         $processLockerFactory->setQuestionId($question_id);
   136         $processLockerFactory->setUserId($ilUser->getId());
   137         $processLocker = $processLockerFactory->getLocker();
   141         $processLocker->executePersistWorkingStateLockOperation(
function () use (
   149             $processLocker->executeUserSolutionUpdateLockOperation(
function () use (
   157                 if (($active_id > 0) && ($question_id > 0) && ($pass > 0)) {
   158                     $affectedRows = 
$ilDB->manipulateF(
   159                         "DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
   160                         array(
'integer', 
'integer', 
'integer'),
   161                         array($active_id, $question_id, $pass)
   164                 for ($i = 0, $iMax = count($solution); $i < $iMax; $i += 3) {
   165                     $next_id = 
$ilDB->nextId(
'tst_solutions');
   166                     $affectedRows = 
$ilDB->insert(
"tst_solutions", array(
   167                         "solution_id" => array(
"integer", $next_id),
   168                         "active_fi" => array(
"integer", $active_id),
   169                         "question_fi" => array(
"integer", $question_id),
   170                         "value1" => array(
"clob", $solution[$i]),
   171                         "value2" => array(
"clob", $solution[$i + 1]),
   172                         "points" => array(
"float", $solution[$i + 2]),
   173                         "pass" => array(
"integer", $pass),
   174                         "tstamp" => array(
"integer", time())
   176                     $totalrows += $affectedRows;
   180             if ($totalrows !== 0) {
   182                 $question->setProcessLocker($processLocker);
   183                 $question->calculateResultsFromSolution($active_id, $pass);
   187         if ($totalrows === 0) {
   189                 "Wrong solution data. ILIAS did not execute any database queries: Solution data: " . print_r(
   211             return $this->
raiseError(
"The required user information is only available for active users.", 
"");
   215         if (preg_match(
"/<values>(.*?)<\/values>/is", $solution, $matches)) {
   217                 "/<value>(.*?)<\/value><value>(.*?)<\/value><points>(.*?)<\/points>/is",
   222                 foreach ($matches as $match) {
   223                     if (count($match) === 4) {
   224                         for ($i = 1, $iMax = count($match); $i < $iMax; $i++) {
   225                             $solutions[] = trim($match[$i]);
   232         if (count($solutions) === 0) {
   234                 "Wrong solution data. ILIAS did not find one or more solution triplets: $solution",
   240         if (($active_id > 0) && ($question_id > 0) && ($pass > 0)) {
   241             $affectedRows = 
$ilDB->manipulateF(
   242                 "DELETE FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
   243                 array(
'integer', 
'integer', 
'integer'),
   244                 array($active_id, $question_id, $pass)
   248         for ($i = 0, $iMax = count($solutions); $i < $iMax; $i += 3) {
   249             $next_id = 
$ilDB->nextId(
'tst_solutions');
   250             $affectedRows = 
$ilDB->insert(
"tst_solutions", array(
   251                 "solution_id" => array(
"integer", $next_id),
   252                 "active_fi" => array(
"integer", $active_id),
   253                 "question_fi" => array(
"integer", $question_id),
   254                 "value1" => array(
"clob", $solutions[$i]),
   255                 "value2" => array(
"clob", $solutions[$i + 1]),
   256                 "points" => array(
"float", $solutions[$i + 2]),
   257                 "pass" => array(
"integer", $pass),
   258                 "tstamp" => array(
"integer", time())
   260             $totalrows += $affectedRows;
   262         if ($totalrows === 0) {
   263             return $this->
raiseError(
"Wrong solution data. ILIAS did not execute any database queries", 
'');
   267         $question->calculateResultsFromSolution($active_id, $pass);
   283             return $this->
raiseError(
"The required user information is only available for active users.", 
"");
   289         $ilDB = $DIC[
'ilDB'];
   291         $use_previous_answers = 1;
   293         $result = 
$ilDB->queryF(
   294             "SELECT tst_tests.use_previous_answers FROM tst_tests, tst_active WHERE tst_tests.test_id = tst_active.test_fi AND tst_active.active_id = %s",
   298         if ($result->numRows()) {
   299             $row = 
$ilDB->fetchAssoc($result);
   300             $use_previous_answers = $row[
"use_previous_answers"];
   303         if ($use_previous_answers) {
   304             $result = 
$ilDB->queryF(
   305                 "SELECT MAX(pass) maxpass FROM tst_test_result WHERE active_fi = %s AND question_fi = %s",
   306                 array(
'integer', 
'integer'),
   307                 array($active_id, $question_id)
   309             if ($result->numRows() === 1) {
   310                 $row = 
$ilDB->fetchAssoc($result);
   311                 $lastpass = (
int) $row[
"maxpass"];
   317         if (($active_id > 0) && ($question_id > 0) && ($lastpass > 0)) {
   318             $result = 
$ilDB->queryF(
   319                 "SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
   320                 array(
'integer', 
'integer', 
'integer'),
   321                 array($active_id, $question_id, $lastpass)
   323             if ($result->numRows()) {
   324                 while ($row = 
$ilDB->fetchAssoc($result)) {
   325                     $solution[] = $row[
"value1"];
   326                     $solution[] = $row[
"value2"];
   327                     $solution[] = $row[
"points"];
   346             return $this->
raiseError(
"The required user information is only available for active users.", 
"");
   352         $ilDB = $DIC[
'ilDB'];
   354         $result = 
$ilDB->queryF(
   355             "SELECT user_fi, test_fi FROM tst_active WHERE active_id = %s",
   359         $row = 
$ilDB->fetchAssoc($result);
   361         $test_id = $row[
"test_fi"];
   363         $result = 
$ilDB->queryF(
   364             "SELECT anonymity FROM tst_tests WHERE test_id = %s",
   368         $row = 
$ilDB->fetchAssoc($result);
   369         $anonymity = $row[
"anonymity"];
   371         $result = 
$ilDB->queryF(
   372             "SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
   378         if ($result->numRows() === 0) {
   379             $userdata[
"fullname"] = 
$lng->txt(
"deleted_user");
   380             $userdata[
"title"] = 
"";
   381             $userdata[
"firstname"] = 
"";
   382             $userdata[
"lastname"] = 
$lng->txt(
"anonymous");
   383             $userdata[
"login"] = 
"";
   387                 $userdata[
"fullname"] = 
$lng->txt(
"anonymous");
   388                 $userdata[
"title"] = 
"";
   389                 $userdata[
"firstname"] = 
"";
   390                 $userdata[
"lastname"] = 
$lng->txt(
"anonymous");
   391                 $userdata[
"login"] = 
"";
   393                 $userdata[
"fullname"] = trim(
$data[
"title"] . 
" " . 
$data[
"firstname"] . 
" " . 
$data[
"lastname"]);
   394                 $userdata[
"title"] = $data[
"title"];
   395                 $userdata[
"firstname"] = $data[
"firstname"];
   396                 $userdata[
"lastname"] = $data[
"lastname"];
   397                 $userdata[
"login"] = $data[
"login"];
   400         return array_values($userdata);
   415             return $this->
raiseError(
"The required user information is only available for active users.", 
"");
   421         $ilDB = $DIC[
'ilDB'];
   423         $result = 
$ilDB->queryF(
   424             "SELECT tst_tests.random_test FROM tst_active, tst_tests WHERE tst_active.active_id = %s AND tst_tests.test_id = tst_active.test_fi",
   428         if ($result->numRows() !== 1) {
   431         $row = 
$ilDB->fetchAssoc($result);
   432         $is_random = $row[
"random_test"];
   435         return $sequence->getSequenceForQuestion($question_id);
   450             return $this->
raiseError(
"The required user information is only available for active users.", 
"");
   456         $ilDB = $DIC[
'ilDB'];
   458         $result = 
$ilDB->queryF(
   459             "SELECT tst_tests.random_test FROM tst_active, tst_tests WHERE tst_active.active_id = %s AND tst_tests.test_id = tst_active.test_fi",
   463         if ($result->numRows() !== 1) {
   466         $row = 
$ilDB->fetchAssoc($result);
   467         $is_random = $row[
"random_test"];
   470         $result = 
$ilDB->queryF(
   471             "SELECT question_fi, points FROM tst_test_result WHERE active_fi = %s AND pass = %s",
   472             array(
'integer', 
'integer'),
   473             array($active_id, $pass)
   475         $reachedpoints = array();
   476         while ($row = 
$ilDB->fetchAssoc($result)) {
   477             $reachedpoints[$row[
"question_fi"]] = $row[
"points"];
   480         $pointsforposition = array();
   481         foreach ($sequence->getUserSequence() as $seq) {
   483                 $qid = $sequence->getQuestionForSequence($seq);
   484                 if ($qid == $question_id) {
   487                     $pointsforposition[] = $reachedpoints[$qid];
   491         return $pointsforposition;
   506             return $this->
raiseError(
"The required user information is only available for active users.", 
"");
   512         $ilDB = $DIC[
'ilDB'];
   514         $result = 
$ilDB->queryF(
   515             "SELECT tst_tests.random_test FROM tst_active, tst_tests WHERE tst_active.active_id = %s AND tst_tests.test_id = tst_active.test_fi",
   519         if ($result->numRows() !== 1) {
   522         $row = 
$ilDB->fetchAssoc($result);
   523         $is_random = $row[
"random_test"];
   526         return $sequence->getUserQuestionCount();
   540         if (!($test_ref_id > 0)) {
   542                 'No test id given. Aborting!',
   548         $rbacsystem = $DIC[
'rbacsystem'];
   549         $tree = $DIC[
'tree'];
   550         $ilLog = $DIC[
'ilLog'];
   553             return $this->
raiseError(
'no permission. Aborting!', 
'Client');
   558                 'Test is trashed. Aborting!',
   564             return $this->
raiseError(
'No test found for id: ' . $test_ref_id, 
'Client');
   566         if ($tst->getType() !== 
'tst') {
   568                 'Object with ref_id ' . $test_ref_id . 
' is not of type test. Aborting',
   574         if (isset($a_user_ids[
'item'])) {
   575             $a_user_ids = $a_user_ids[
'item'];
   579         $part->setParticipantAccessFilter(
   580             ilTestParticipantAccessFilter::getManageParticipantsUserFilter($test_ref_id)
   582         $part->setUserIdsFilter((array) $a_user_ids);
   583         $part->load($tst->getTestId());
   584         $tst->removeTestResults($part);
   600         if (!($test_ref_id > 0)) {
   602                 'No test id given. Aborting!',
   608         $rbacsystem = $DIC[
'rbacsystem'];
   609         $tree = $DIC[
'tree'];
   610         $ilLog = $DIC[
'ilLog'];
   614                 'Test is trashed. Aborting!',
   621                 'No test found for id: ' . $test_ref_id,
   626         $permission_ok = 
false;
   628             if ($rbacsystem->checkAccess(
'write', $ref_id)) {
   629                 $permission_ok = 
true;
   637         if (!$permission_ok) {
   639                 'No permission to edit the object with id: ' . $test_ref_id,
   645         $xmlResultSet->addColumn(
"user_id");
   646         $xmlResultSet->addColumn(
"login");
   647         $xmlResultSet->addColumn(
"firstname");
   648         $xmlResultSet->addColumn(
"lastname");
   649         $xmlResultSet->addColumn(
"matriculation");
   651         $test_obj = 
new ilObjTest($obj_id, 
false);
   652         $participants = $test_obj->getTestParticipants();
   654         $accessFilter = ilTestParticipantAccessFilter::getAccessResultsUserFilter($test_ref_id);
   656         $participantList->initializeFromDbRows($participants);
   657         $participantList = $participantList->getAccessFilteredList($accessFilter);
   658         $participantList = $participantList->getScoredParticipantList();
   659         foreach ($participants as $activeId => $part) {
   660             if ($participantList->isActiveIdInList($activeId)) {
   661                 $participants[$activeId][
'passed'] = $participantList->getParticipantByActiveId($activeId)->getScoring()->isPassed();
   665             unset($participants[$activeId]);
   669             $data = $test_obj->getAllTestResults($participants);
   671             $xmlResultSet->addColumn(
"maximum_points");
   672             $xmlResultSet->addColumn(
"received_points");
   673             $xmlResultSet->addColumn(
"passed");
   675             $titles = array_shift(
$data);
   676             foreach (
$data as $row) {
   678                 $xmlRow->setValue(0, $row[
"user_id"]);
   679                 $xmlRow->setValue(1, $row[
"login"]);
   680                 $xmlRow->setValue(2, $row[
"firstname"]);
   681                 $xmlRow->setValue(3, $row[
"lastname"]);
   682                 $xmlRow->setValue(4, $row[
"matriculation"]);
   683                 $xmlRow->setValue(5, $row[
"max_points"]);
   684                 $xmlRow->setValue(6, $row[
"reached_points"]);
   685                 $xmlRow->setValue(7, $row[
"passed"]);
   686                 $xmlResultSet->addRow($xmlRow);
   689             $data = $test_obj->getDetailedTestResults($participants);
   691             $xmlResultSet->addColumn(
"question_id");
   692             $xmlResultSet->addColumn(
"question_title");
   693             $xmlResultSet->addColumn(
"maximum_points");
   694             $xmlResultSet->addColumn(
"received_points");
   695             $xmlResultSet->addColumn(
"passed");
   696             foreach (
$data as $row) {
   698                 $xmlRow->setValue(0, $row[
"user_id"]);
   699                 $xmlRow->setValue(1, $row[
"login"]);
   700                 $xmlRow->setValue(2, $row[
"firstname"]);
   701                 $xmlRow->setValue(3, $row[
"lastname"]);
   702                 $xmlRow->setValue(4, $row[
"matriculation"]);
   703                 $xmlRow->setValue(5, $row[
"question_id"]);
   704                 $xmlRow->setValue(6, $row[
"question_title"]);
   705                 $xmlRow->setValue(7, $row[
"max_points"]);
   706                 $xmlRow->setValue(8, $row[
"reached_points"]);
   707                 $xmlRow->setValue(9, $row[
"passed"]);
   708                 $xmlResultSet->addRow($xmlRow);
   714         return $xmlWriter->getXML();
   719         return $this->
getTestAccess($refId)->checkManageParticipantsAccess();
   724         return $this->
getTestAccess($refId)->checkParticipantsResultsAccess();
 isAllowedCall(string $sid, int $active_id, bool $saveaction=true)
 
XML Writer for XMLResultSet. 
 
getTestResults(string $sid, int $test_ref_id, bool $sum_only)
 
__construct(bool $use_nusoap=true)
 
getQuestionSolution(string $sid, int $active_id, int $question_id, int $pass)
 
static _getAllReferences(int $id)
get all reference ids for object ID 
 
raiseError(string $a_message, $a_code)
 
Row Class for XMLResultSet. 
 
getTestAccess(int $refId)
 
saveQuestionSolution(string $sid, int $active_id, int $question_id, int $pass, int $solution)
 
removeTestResults(string $sid, int $test_ref_id, array $a_user_ids)
 
static instantiateQuestion(int $question_id)
 
checkParticipantsResultsAccess(int $refId)
 
checkManageParticipantsAccess(int $refId)
 
getNrOfQuestionsInPass(string $sid, int $active_id, int $pass)
 
GeneralQuestionPropertiesRepository $questionrepository
 
checkSession(string $sid)
 
static _isInTrash(int $ref_id)
 
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id 
 
static _lookupObjectId(int $ref_id)
 
static _getTestIDFromObjectID($object_id)
Returns the ILIAS test id for a given object id. 
 
saveQuestion(string $sid, int $active_id, int $question_id, int $pass, array $solution)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
hasWritePermissionForTest(int $active_id)
 
getPositionOfQuestion(string $sid, int $active_id, int $question_id, int $pass)
 
getPreviousReachedPoints(string $sid, int $active_id, int $question_id, int $pass)
 
__construct(Container $dic, ilPlugin $plugin)
 
getTestUserData(string $sid, int $active_id)