ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilObjTestAccess Class Reference

Class ilObjTestAccess. More...

+ Inheritance diagram for ilObjTestAccess:
+ Collaboration diagram for ilObjTestAccess:

Public Member Functions

 _checkAccess ($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
 Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess) More...
 
 _getMaxPointsForTestPass ($random, $user_id, $test_id, $pass)
 Returns the maximum number of points available for a test pass. More...
 
 _getCommands ()
 get commands More...
 
 _lookupCreationComplete ($a_obj_id)
 checks wether all necessary parts of the test are given More...
 
 _getTestIDFromObjectID ($object_id)
 Returns the ILIAS test id for a given object id. More...
 
_getTestQuestions ($active_id, $pass=NULL)
 
 _isComplete ($a_obj_id)
 Returns true, if a test is complete for use. More...
 
_getTestData ($test_id)
 Returns the database content of a test with a given id. More...
 
 _lookupObjIdForTestId ($a_test_id)
 Lookup object id for test id. More...
 
 _getRandomTestsForQuestionPool ($qpl_id)
 Get all tests using a question pool for random selection. More...
 
 _lookupOnlineTestAccess ($a_test_id, $a_user_id)
 Checks if a user is allowd to run an online exam. More...
 
 _getParticipantData ($active_id)
 Retrieves a participant name from active id. More...
 
 _getParticipantId ($active_id)
 Get user id for active id. More...
 
_getPassedUsers ($a_obj_id)
 Returns an array containing the users who passed the test. More...
 
 _checkGoto ($a_target)
 check whether goto script will succeed More...
 
- Public Member Functions inherited from ilObjectAccess
 _checkAccess ($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
 Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess) More...
 
 _checkCondition ($a_obj_id, $a_operator, $a_value, $a_usr_id)
 check condition More...
 
 _getCommands ()
 get commands More...
 
 _checkGoto ($a_target)
 check whether goto script will succeed More...
 
 _preloadData ($a_obj_ids, $a_ref_ids)
 Preload data. More...
 

Static Public Member Functions

static _isPassed ($user_id, $a_obj_id)
 Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id. More...
 
static isFailed ($user_id, $a_obj_id)
 Returns TRUE if the user with the user id $user_id failed the test with the object id $a_obj_id. More...
 
static getConditionOperators ()
 Get possible conditions operators. More...
 
static checkCondition ($a_obj_id, $a_operator, $a_value, $a_usr_id)
 check condition More...
 
static hasFinished ($a_user_id, $a_obj_id)
 Returns (request cached) information if a specific user has finished at least one test pass. More...
 
static _isOffline ($a_obj_id)
 returns the objects's OFFline status More...
 
static _isOnline ($a_obj_id)
 returns the objects's ONline status More...
 
static visibleUserResultExists ($testObjId, $userId)
 
static _isOffline ($a_obj_id)
 Type-specific implementation of general status, has to be overwritten. More...
 
static getConditionOperators ()
 Returns an array with valid operators for the specific object type. More...
 
static checkCondition ($a_trigger_obj_id, $a_operator, $a_value, $a_usr_id)
 check condition for a specific user and object More...
 

Protected Member Functions

 updateTestResultCache ($a_user_id, $a_obj_id)
 Update test result cache. More...
 

Static Private Attributes

static $hasFinishedCache = array()
 

Detailed Description

Class ilObjTestAccess.

This class contains methods that check object specific conditions for accessing test objects.

Author
Helmut Schottmueller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 20 of file class.ilObjTestAccess.php.

Member Function Documentation

◆ _checkAccess()

ilObjTestAccess::_checkAccess (   $a_cmd,
  $a_permission,
  $a_ref_id,
  $a_obj_id,
  $a_user_id = "" 
)

Checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAccess)

Please do not check any preconditions handled by ilConditionHandler here.

Parameters
string$a_cmdcommand (not permission!)
string$a_permissionpermission
int$a_ref_idreference id
int$a_obj_idobject id
int$a_user_iduser id (if not provided, current user is taken)
Returns
boolean true, if everything is ok

Reimplemented from ilObjectAccess.

Definition at line 37 of file class.ilObjTestAccess.php.

38 {
39 global $ilUser, $lng, $rbacsystem, $ilAccess;
40
41 if ($a_user_id == "")
42 {
43 $a_user_id = $ilUser->getId();
44 }
45
46 $is_admin = $rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id);
47
48 // check "global" online switch
49 if(!self::_isOnline($a_obj_id) && !$is_admin)
50 {
51 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
52 return false;
53 }
54
55 switch ($a_permission)
56 {
57 case "visible":
58 case "read":
60 !$is_admin)
61 {
62 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("tst_warning_test_not_complete"));
63 return false;
64 }
65 break;
66 }
67
68 switch ($a_cmd)
69 {
70 case "eval_a":
71 case "eval_stat":
73 {
74 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("tst_warning_test_not_complete"));
75 return false;
76 }
77 break;
78
79 }
80
81 return true;
82 }
const IL_NO_OBJECT_ACCESS
_lookupCreationComplete($a_obj_id)
checks wether all necessary parts of the test are given
global $lng
Definition: privfeed.php:40
global $ilUser
Definition: imgupload.php:15

References $ilUser, $lng, _lookupCreationComplete(), and IL_NO_OBJECT_ACCESS.

+ Here is the call graph for this function:

◆ _checkGoto()

ilObjTestAccess::_checkGoto (   $a_target)

check whether goto script will succeed

Reimplemented from ilObjectAccess.

Definition at line 890 of file class.ilObjTestAccess.php.

891 {
892 global $ilAccess;
893
894 $t_arr = explode("_", $a_target);
895
896 if ($t_arr[0] != "tst" || ((int) $t_arr[1]) <= 0)
897 {
898 return false;
899 }
900
901 if ($ilAccess->checkAccess("read", "", $t_arr[1]))
902 {
903 return true;
904 }
905 return false;
906 }

◆ _getCommands()

ilObjTestAccess::_getCommands ( )

get commands

this method returns an array of all possible commands/permission combinations

example:
$commands = array ( array("permission" => "read", "cmd" => "view", "lang_var" => "show"), array("permission" => "write", "cmd" => "edit", "lang_var" => "edit"), );

Reimplemented from ilObjectAccess.

Definition at line 410 of file class.ilObjTestAccess.php.

411 {
412 $commands = array
413 (
414 array("permission" => "write", "cmd" => "questionsTabGateway", "lang_var" => "tst_edit_questions"),
415 array("permission" => "write", "cmd" => "ilObjTestSettingsGeneralGUI::showForm", "lang_var" => "settings"),
416 array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "tst_run",
417 "default" => true),
418 //array("permission" => "write", "cmd" => "", "lang_var" => "edit"),
419 array("permission" => "tst_statistics", "cmd" => "outEvaluation", "lang_var" => "tst_statistical_evaluation"),
420 array("permission" => "read", "cmd" => "userResultsGateway", "lang_var" => "tst_test_results")
421 );
422
423 return $commands;
424 }

Referenced by ilObjTestListGUI\init().

+ Here is the caller graph for this function:

◆ _getMaxPointsForTestPass()

ilObjTestAccess::_getMaxPointsForTestPass (   $random,
  $user_id,
  $test_id,
  $pass 
)

Returns the maximum number of points available for a test pass.

Parameters
boolean$randomTRUE if the test is a random test, otherwise FALSE
int$test_idThe test id
int$passThe test pass
Returns
int The available points for the test pass

Definition at line 92 of file class.ilObjTestAccess.php.

93 {
94 global $ilDB;
95 $max = 0;
96 if ($random)
97 {
98 $result = $ilDB->queryF("SELECT SUM(qpl_questions.points) maxpoints FROM tst_test_rnd_qst, qpl_questions, tst_active WHERE tst_active.active_id = tst_test_rnd_qst.active_fi AND tst_test_rnd_qst.question_fi = qpl_questions.question_id AND tst_active.test_fi = %s AND tst_test_rnd_qst.pass = %s AND tst_active.user_fi = %s",
99 array('integer','integer','integer'),
100 array($test_id, $pass, $user_id)
101 );
102 if ($result->numRows())
103 {
104 $row = $ilDB->fetchAssoc($result);
105 $max = $row["maxpoints"];
106 }
107 }
108 else
109 {
110 $result = $ilDB->queryF("SELECT SUM(qpl_questions.points) maxpoints FROM tst_test_question, qpl_questions WHERE tst_test_question.question_fi = qpl_questions.question_id AND tst_test_question.test_fi = %s",
111 array('integer'),
112 array($test_id)
113 );
114 if ($result->numRows())
115 {
116 $row = $ilDB->fetchAssoc($result);
117 $max = $row["maxpoints"];
118 }
119 }
120 return $max;
121 }
$result
global $ilDB

References $ilDB, $pass, $result, and $row.

◆ _getParticipantData()

ilObjTestAccess::_getParticipantData (   $active_id)

Retrieves a participant name from active id.

Parameters
integer$active_idActive ID of the participant
Returns
string The output name of the user @access public

Definition at line 737 of file class.ilObjTestAccess.php.

738 {
739 global $lng, $ilDB;
740
741 $result = $ilDB->queryF("SELECT * FROM tst_active WHERE active_id = %s",
742 array("integer"),
743 array($active_id)
744 );
745 $row = $ilDB->fetchAssoc($result);
746 $user_id = $row["user_fi"];
747 $test_id = $row["test_fi"];
748 $importname = $row['importname'];
749
750 $result = $ilDB->queryF("SELECT obj_fi FROM tst_tests WHERE test_id = %s",
751 array("integer"),
752 array($test_id)
753 );
754 $row = $ilDB->fetchAssoc($result);
755 $obj_id = $row["obj_fi"];
756
757 include_once "./Modules/Test/classes/class.ilObjTest.php";
758 $is_anonymous = ilObjTest::_lookupAnonymity($obj_id);
759
760 include_once './Services/User/classes/class.ilObjUser.php';
761 $uname = ilObjUser::_lookupName($user_id);
762
763 $name = "";
764 if (strlen($importname))
765 {
766 $name = $importname . ' (' . $lng->txt('imported') . ')';
767 }
768 else if (strlen($uname["firstname"].$uname["lastname"]) == 0)
769 {
770 $name = $lng->txt("deleted_user");
771 }
772 else
773 {
774 if ($user_id == ANONYMOUS_USER_ID)
775 {
776 $name = $lastname;
777 }
778 else
779 {
780 $name = trim($uname["lastname"] . ", " . $uname["firstname"] . " " . $uname["title"]);
781 }
782 if ($is_anonymous)
783 {
784 $name = $lng->txt("anonymous");
785 }
786 }
787 return $name;
788 }
_lookupAnonymity($a_obj_id)
Returns the anonymity status of a test with a given object id.
static _lookupName($a_user_id)
lookup user name

References $ilDB, $lng, $result, $row, ilObjTest\_lookupAnonymity(), and ilObjUser\_lookupName().

Referenced by assQuestion\_setReachedPoints(), ilTestResultsToXML\exportActiveIDs(), and ilObjTestGUI\participantsObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getParticipantId()

ilObjTestAccess::_getParticipantId (   $active_id)

Get user id for active id.

Parameters
intactive ID of the participant
Returns
int user id

Definition at line 796 of file class.ilObjTestAccess.php.

797 {
798 global $lng, $ilDB;
799
800 $result = $ilDB->queryF("SELECT user_fi FROM tst_active WHERE active_id = %s",
801 array("integer"),
802 array($active_id)
803 );
804 $row = $ilDB->fetchAssoc($result);
805 return $row["user_fi"];
806 }

References $ilDB, $lng, $result, and $row.

Referenced by assFileUpload\handleSubmission(), ilTestSession\increaseTestPass(), ilTestScoringGUI\saveManScoringParticipantScreen(), ilTestSession\saveToDb(), and ilTestSessionDynamicQuestionSet\saveToDb().

+ Here is the caller graph for this function:

◆ _getPassedUsers()

& ilObjTestAccess::_getPassedUsers (   $a_obj_id)

Returns an array containing the users who passed the test.

Returns
array An array containing the users who passed the test. Format of the values of the resulting array: array( "user_id" => user ID, "max_points" => maximum available points in the test "reached_points" => maximum reached points of the user "mark_short" => short text of the passed mark "mark_official" => official text of the passed mark ) @access public

Definition at line 823 of file class.ilObjTestAccess.php.

824 {
825 global $ilDB;
826
827 $passed_users = array();
828 // Maybe SELECT DISTINCT(tst_active.user_fi)... ?
829 $userresult = $ilDB->queryF("
830 SELECT tst_active.active_id, COUNT(tst_sequence.active_fi) sequences
831 FROM tst_tests
832 INNER JOIN tst_active
833 ON tst_active.test_fi = tst_tests.test_id
834 LEFT JOIN tst_sequence
835 ON tst_sequence.active_fi = tst_active.active_id
836 WHERE tst_tests.obj_fi = %s
837 GROUP BY tst_active.active_id
838 ",
839 array('integer'), array($a_obj_id)
840 );
841 $all_participants = array();
842 $notAttempted = array();
843 while ($row = $ilDB->fetchAssoc($userresult))
844 {
845 if($row['sequences'] == 0)
846 {
847 $notAttempted[$row['active_id']] = $row['active_id'];
848 }
849
850 $all_participants[$row['active_id']] = $row['active_id'];
851 }
852
853 $result = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM tst_result_cache, tst_active WHERE tst_active.active_id = tst_result_cache.active_fi AND " . $ilDB->in('active_fi', $all_participants, false, 'integer'));
854 $found_all = ($result->numRows() == count($all_participants)) ? true : false;
855 if (!$found_all)
856 {
857 // if the result cache entries do not exist, create them
858 $found_participants = array();
859 while ($data = $ilDB->fetchAssoc($result))
860 {
861 array_push($found_participants, $data['active_fi']);
862 }
863 foreach ($all_participants as $active_id)
864 {
865 if (!in_array($active_id, $found_participants))
866 {
867 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
869 }
870 }
871 $result = $ilDB->query("SELECT tst_result_cache.*, tst_active.user_fi FROM tst_result_cache, tst_active WHERE tst_active.active_id = tst_result_cache.active_fi AND " . $ilDB->in('active_fi', $all_participants, false, 'integer'));
872 }
873 while ($data = $ilDB->fetchAssoc($result))
874 {
875 if( isset($notAttempted[$data['active_fi']]) )
876 {
877 $data['failed'] = 0;
878 $data['passed'] = 0;
879 }
880
881 $data['user_id'] = $data['user_fi'];
882 array_push($passed_users, $data);
883 }
884 return $passed_users;
885 }
_updateTestResultCache($active_id, ilAssQuestionProcessLocker $processLocker=null)
@TODO Move this to a proper place.
$data

References $data, $ilDB, $result, $row, and assQuestion\_updateTestResultCache().

Referenced by ilLPStatusTestPassed\_getStatusInfo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getRandomTestsForQuestionPool()

ilObjTestAccess::_getRandomTestsForQuestionPool (   $qpl_id)

Get all tests using a question pool for random selection.

Parameters
intquestion pool id
Returns
array list if test obj ids @access public

Definition at line 645 of file class.ilObjTestAccess.php.

646 {
647 global $ilDB;
648
649 $query = "
650 SELECT DISTINCT t.obj_fi
651 FROM tst_tests t
652 INNER JOIN tst_rnd_quest_set_qpls r
653 ON t.test_id = r.test_fi
654 WHERE r.pool_fi = %s
655 ";
656
657 $result = $ilDB->queryF($query, array('integer'), array($qpl_id));
658
659 $tests = array();
660 while ($row = $ilDB->fetchAssoc($result))
661 {
662 $tests[] = $row['obj_fi'];
663 }
664
665 return $tests;
666 }

References $ilDB, $query, $result, $row, and $tests.

Referenced by ilObjMediaObjectAccess\checkAccessTestQuestion().

+ Here is the caller graph for this function:

◆ _getTestData()

& ilObjTestAccess::_getTestData (   $test_id)

Returns the database content of a test with a given id.

Parameters
int$test_idDatabase id of the test
Returns
array An associative array with the contents of the tst_tests database row @access public

Definition at line 605 of file class.ilObjTestAccess.php.

606 {
607 global $ilDB;
608 $result = $ilDB->queryF("SELECT * FROM tst_tests WHERE test_id = %s",
609 array('integer'),
610 array($test_id)
611 );
612 if (!$result->numRows())
613 {
614 return 0;
615 }
616 return $ilDB->fetchAssoc($result);
617 }

References $ilDB, and $result.

◆ _getTestIDFromObjectID()

ilObjTestAccess::_getTestIDFromObjectID (   $object_id)

Returns the ILIAS test id for a given object id.

Parameters
integer$object_idThe object id
Returns
mixed The ILIAS test id or FALSE if the query was not successful @access public

Definition at line 501 of file class.ilObjTestAccess.php.

502 {
503 global $ilDB;
504 $test_id = FALSE;
505 $result = $ilDB->queryF("SELECT test_id FROM tst_tests WHERE obj_fi = %s",
506 array('integer'),
507 array($object_id)
508 );
509 if ($result->numRows())
510 {
511 $row = $ilDB->fetchAssoc($result);
512 $test_id = $row["test_id"];
513 }
514 return $test_id;
515 }

References $ilDB, $result, and $row.

Referenced by ilLPStatusTestFinished\getParticipants().

+ Here is the caller graph for this function:

◆ _getTestQuestions()

& ilObjTestAccess::_getTestQuestions (   $active_id,
  $pass = NULL 
)

Definition at line 517 of file class.ilObjTestAccess.php.

518 {
519 if (is_null($pass))
520 {
521 $pass = 0;
522 }
523 $questions = array();
524
525 global $ilDB;
526 $result = $ilDB->queryF("SELECT test_fi FROM tst_active WHERE active_id = %s",
527 array('integer'),
528 array($active_id)
529 );
530 $test_id = "";
531 if ($result->numRows())
532 {
533 $row = $ilDB->fetchAssoc($result);
534 $test_id = $row["test_fi"];
535 }
536 else
537 {
538 return $questions;
539 }
540 $result = $ilDB->queryF("SELECT qpl_questions.question_id, qpl_questions.points FROM qpl_questions, tst_test_question WHERE tst_test_question.question_fi = qpl_questions.question_id AND tst_test_question.test_fi = %s ORDER BY tst_test_question.sequence",
541 array('integer'),
542 array($test_id)
543 );
544 if ($result->numRows())
545 {
546 // standard test
547 while ($row = $ilDB->fetchAssoc($result))
548 {
549 array_push($questions, $row);
550 }
551 }
552 else
553 {
554 // random test
555 $result = $ilDB->queryF("SELECT qpl_questions.question_id, qpl_questions.points FROM qpl_questions, tst_test_rnd_qst WHERE tst_test_rnd_qst.question_fi = qpl_questions.question_id AND tst_test_rnd_qst.active_fi = %s AND tst_test_rnd_qst.pass = %s ORDER BY tst_test_rnd_qst.sequence",
556 array('integer','integer'),
557 array($active_id, $pass)
558 );
559 if ($result->numRows())
560 {
561 while ($row = $ilDB->fetchAssoc($result))
562 {
563 array_push($questions, $row);
564 }
565 }
566 }
567 return $questions;
568 }

References $ilDB, $pass, $result, and $row.

◆ _isComplete()

ilObjTestAccess::_isComplete (   $a_obj_id)

Returns true, if a test is complete for use.

Returns
boolean True, if the test is complete for use, otherwise false @access public

Definition at line 576 of file class.ilObjTestAccess.php.

577 {
578 global $ilDB;
579
580 $query = "
581 SELECT tst_tests.complete
582 FROM object_data
583 INNER JOIN tst_tests
584 ON tst_tests.obj_fi = object_data.obj_id
585 WHERE object_data.obj_id = %s
586 ";
587
588 $res = $ilDB->queryF($query, array('integer'), array($a_obj_id));
589
590 while( $row = $ilDB->fetchAssoc($res) )
591 {
592 return (bool)$row['complete'];
593 }
594
595 return false;
596 }

References $ilDB, $query, $res, and $row.

◆ _isOffline()

static ilObjTestAccess::_isOffline (   $a_obj_id)
static

returns the objects's OFFline status

Used in ListGUI and Learning Progress

Parameters
int$a_obj_id
Returns
bool

Reimplemented from ilObjectAccess.

Definition at line 916 of file class.ilObjTestAccess.php.

917 {
918// global $ilUser;
919// return (self::_lookupOnlineTestAccess($a_obj_id, $ilUser->getId()) !== true) ||
920// (!ilObjTestAccess::_lookupCreationComplete($a_obj_id));
921 return !self::_isOnline($a_obj_id);
922 }
static _isOnline($a_obj_id)
returns the objects's ONline status

References _isOnline().

+ Here is the call graph for this function:

◆ _isOnline()

static ilObjTestAccess::_isOnline (   $a_obj_id)
static

returns the objects's ONline status

Parameters
integer$a_obj_id
Returns
boolean $online

Definition at line 930 of file class.ilObjTestAccess.php.

931 {
932 global $ilDB;
933
934 $query = "
935 SELECT test_id
936 FROM tst_tests
937 WHERE obj_fi = %s
938 AND online_status = 1
939 ";
940
941 $result = $ilDB->queryF( $query, array('integer'), array($a_obj_id) );
942
943 return $result->numRows() == 1;
944 }

References $ilDB, $query, and $result.

Referenced by _isOffline(), ilLOEditorStatus\checkTestOnline(), and ilObjTestListGUI\getProperties().

+ Here is the caller graph for this function:

◆ _isPassed()

static ilObjTestAccess::_isPassed (   $user_id,
  $a_obj_id 
)
static

Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id.

Parameters
int$user_idThe user id
int$a_obj_idThe object id
Returns
boolean TRUE if the user passed the test, FALSE otherwise

Definition at line 130 of file class.ilObjTestAccess.php.

131 {
132 global $ilDB;
133 $result = $ilDB->queryF("SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
134 array('integer','integer'),
135 array($user_id, $a_obj_id)
136 );
137 if (!$result->numRows())
138 {
139 $result = $ilDB->queryF("SELECT tst_active.active_id FROM tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s",
140 array('integer','integer'),
141 array($user_id, $a_obj_id)
142 );
143 $row = $ilDB->fetchAssoc($result);
144 if ($row['active_id'] > 0)
145 {
146 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
148 }
149 else
150 {
151 return false;
152 }
153 }
154 $result = $ilDB->queryF("SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
155 array('integer','integer'),
156 array($user_id, $a_obj_id)
157 );
158 if (!$result->numRows())
159 {
160 $result = $ilDB->queryF("SELECT tst_pass_result.*, tst_tests.pass_scoring, tst_tests.random_test, tst_tests.test_id FROM tst_pass_result, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_pass_result.active_fi = tst_active.active_id ORDER BY tst_pass_result.pass",
161 array('integer','integer'),
162 array($user_id, $a_obj_id)
163 );
164 $points = array();
165 while ($row = $ilDB->fetchAssoc($result))
166 {
167 array_push($points, $row);
168 }
169 $reached = 0;
170 $max = 0;
171 if ($points[0]["pass_scoring"] == 0)
172 {
173 $reached = $points[count($points)-1]["points"];
174 $max = $points[count($points)-1]["maxpoints"];
175 if (!$max)
176 {
177 $active_id = $points[count($points)-1]["active_fi"];
178 $pass = $points[count($points)-1]["pass"];
179 if (strlen($active_id) && strlen($pass))
180 {
181 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
182 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
183 $max = $res['maxpoints'];
184 $reached = $res['points'];
185 }
186 }
187 }
188 else
189 {
190 foreach ($points as $row)
191 {
192 if ($row["points"] > $reached)
193 {
194 $reached = $row["points"];
195 $max = $row["maxpoints"];
196 if (!$max)
197 {
198 $active_id = $row["active_fi"];
199 $pass = $row["pass"];
200 if (strlen($active_id) && strlen($pass))
201 {
202 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
203 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
204 $max = $res['maxpoints'];
205 $reached = $res['points'];
206 }
207 }
208 }
209 }
210 }
211 include_once "./Modules/Test/classes/class.assMarkSchema.php";
212 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
213 $mark = ASS_MarkSchema::_getMatchingMarkFromObjId($a_obj_id, $percentage);
214 return ($mark["passed"]) ? TRUE : FALSE;
215 }
216 else
217 {
218 $row = $ilDB->fetchAssoc($result);
219 return ($row['passed']) ? true : false;
220 }
221 }
_getMatchingMarkFromObjId($a_obj_id, $percentage)
Returns the matching mark for a given percentage.

References $ilDB, $pass, $res, $result, $row, ASS_MarkSchema\_getMatchingMarkFromObjId(), and assQuestion\_updateTestResultCache().

Referenced by checkCondition(), and ilLPStatusTestPassed\determineStatus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupCreationComplete()

ilObjTestAccess::_lookupCreationComplete (   $a_obj_id)

checks wether all necessary parts of the test are given

Definition at line 433 of file class.ilObjTestAccess.php.

434 {
435 global $ilDB;
436
437 $result = $ilDB->queryF("SELECT complete FROM tst_tests WHERE obj_fi=%s",
438 array('integer'),
439 array($a_obj_id)
440 );
441 if ($result->numRows() == 1)
442 {
443 $row = $ilDB->fetchAssoc($result);
444 }
445
446 return ($row['complete']) ? true : false;
447 }

References $ilDB, $result, and $row.

Referenced by _checkAccess().

+ Here is the caller graph for this function:

◆ _lookupObjIdForTestId()

ilObjTestAccess::_lookupObjIdForTestId (   $a_test_id)

Lookup object id for test id.

Parameters
inttest id
Returns
int object id

Definition at line 625 of file class.ilObjTestAccess.php.

626 {
627 global $ilDB;
628
629 $result = $ilDB->queryF("SELECT obj_fi FROM tst_tests WHERE test_id = %s",
630 array('integer'),
631 array($a_test_id)
632 );
633
634 $row = $ilDB->fetchAssoc($result);
635 return $row["obj_fi"];
636 }

References $ilDB, $result, and $row.

Referenced by ilTestSession\increaseTestPass(), ilTestSession\saveToDb(), and ilTestSessionDynamicQuestionSet\saveToDb().

+ Here is the caller graph for this function:

◆ _lookupOnlineTestAccess()

ilObjTestAccess::_lookupOnlineTestAccess (   $a_test_id,
  $a_user_id 
)

Checks if a user is allowd to run an online exam.

Returns
mixed true if the user is allowed to run the online exam or if the test isn't an online exam, an alert message if the test is an online exam and the user is not allowed to run it @access public

Definition at line 675 of file class.ilObjTestAccess.php.

676 {
677 global $ilDB, $lng;
678
679 $result = $ilDB->queryF("SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
680 array('integer'),
681 array($a_test_id)
682 );
683 if ($result->numRows())
684 {
685 $row = $ilDB->fetchAssoc($result);
686 if ($row["fixed_participants"])
687 {
688 $result = $ilDB->queryF("SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
689 array('integer','integer'),
690 array($row["test_id"], $a_user_id)
691 );
692 if ($result->numRows())
693 {
694 $row = $ilDB->fetchAssoc($result);
695 if (trim($row['clientip']) != "")
696 {
697 $row['clientip'] = preg_replace("/[^0-9.?*,:]+/","",$row['clientip']);
698 $row['clientip'] = str_replace(".","\\.",$row['clientip']);
699 $row['clientip'] = str_replace(Array("?","*",","), Array("[0-9]","[0-9]*","|"), $row['clientip']);
700 if (!preg_match("/^".$row['clientip']."$/", $_SERVER["REMOTE_ADDR"]))
701 {
702 return $lng->txt("tst_user_wrong_clientip");
703 }
704 else
705 {
706 return true;
707 }
708 }
709 else
710 {
711 return true;
712 }
713 }
714 else
715 {
716 return $lng->txt("tst_user_not_invited");
717 }
718 }
719 else
720 {
721 return true;
722 }
723 }
724 else
725 {
726 return true;
727 }
728 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_SERVER, $ilDB, $lng, $result, and $row.

Referenced by ilObjTestGUI\buildPageViewToolbar(), ilObjTestListGUI\getProperties(), and ilObjTestGUI\questionsObject().

+ Here is the caller graph for this function:

◆ checkCondition()

static ilObjTestAccess::checkCondition (   $a_obj_id,
  $a_operator,
  $a_value,
  $a_usr_id 
)
static

check condition

this method is called by ilConditionHandler

Implements ilConditionHandling.

Definition at line 373 of file class.ilObjTestAccess.php.

374 {
375 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
376
377 switch($a_operator)
378 {
380 return ilObjTestAccess::_isPassed($a_usr_id, $a_obj_id);
381 break;
382
384 return ilObjTestAccess::isFailed($a_usr_id, $a_obj_id);
385
387 return ilObjTestAccess::hasFinished($a_usr_id,$a_obj_id);
388
390 return !ilObjTestAccess::hasFinished($a_usr_id,$a_obj_id);
391
392 default:
393 return true;
394 }
395 return true;
396 }
static hasFinished($a_user_id, $a_obj_id)
Returns (request cached) information if a specific user has finished at least one test pass.
static _isPassed($user_id, $a_obj_id)
Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id.
static isFailed($user_id, $a_obj_id)
Returns TRUE if the user with the user id $user_id failed the test with the object id $a_obj_id.

References _isPassed(), hasFinished(), isFailed(), ilConditionHandler\OPERATOR_FAILED, ilConditionHandler\OPERATOR_FINISHED, ilConditionHandler\OPERATOR_NOT_FINISHED, and ilConditionHandler\OPERATOR_PASSED.

Referenced by ilContainerObjectiveGUI\getMainContent(), ilContainerStartObjects\isFullfilled(), ilCourseStart\isFullfilled(), and ilContainerObjectiveGUI\renderObjective().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getConditionOperators()

static ilObjTestAccess::getConditionOperators ( )
static

Get possible conditions operators.

Implements ilConditionHandling.

Definition at line 356 of file class.ilObjTestAccess.php.

357 {
358 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
359 return array(
364 );
365 }

References ilConditionHandler\OPERATOR_FAILED, ilConditionHandler\OPERATOR_FINISHED, ilConditionHandler\OPERATOR_NOT_FINISHED, and ilConditionHandler\OPERATOR_PASSED.

◆ hasFinished()

static ilObjTestAccess::hasFinished (   $a_user_id,
  $a_obj_id 
)
static

Returns (request cached) information if a specific user has finished at least one test pass.

Parameters
integer$user_idobj_id of the user
integer$a_obj_idobj_id of the test
Returns
bool

Definition at line 463 of file class.ilObjTestAccess.php.

464 {
465 if( !isset(self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"]) )
466 {
467 require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
468 require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
469 require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
470
471 global $ilDB, $lng;
472
473 $testOBJ = ilObjectFactory::getInstanceByObjId($a_obj_id);
474
475 $partData = new ilTestParticipantData($ilDB, $lng);
476 $partData->setUserIds(array($a_user_id));
477 $partData->load($testOBJ->getTestId());
478
479 $activeId = $partData->getActiveIdByUserId($a_user_id);
480
481 $testSessionFactory = new ilTestSessionFactory($testOBJ);
482 $testSession = $testSessionFactory->getSession($activeId);
483
484 $testPassesSelector = new ilTestPassesSelector($ilDB, $testOBJ);
485 $testPassesSelector->setActiveId($activeId);
486 $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass());
487
488 self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"] = count($testPassesSelector->getClosedPasses());
489 }
490
491 return self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"];
492 }
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id

References $ilDB, $lng, and ilObjectFactory\getInstanceByObjId().

Referenced by checkCondition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isFailed()

static ilObjTestAccess::isFailed (   $user_id,
  $a_obj_id 
)
static

Returns TRUE if the user with the user id $user_id failed the test with the object id $a_obj_id.

Parameters
int$user_idThe user id
int$a_obj_idThe object id
Returns
boolean TRUE if the user failed the test, FALSE otherwise

Definition at line 230 of file class.ilObjTestAccess.php.

231 {
232 global $ilDB;
233
234 $ret = self::updateTestResultCache($user_id, $a_obj_id);
235
236 if(!$ret)
237 {
238 return false;
239 }
240
241 $result = $ilDB->queryF("SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
242 array('integer','integer'),
243 array($user_id, $a_obj_id)
244 );
245
246 if (!$result->numRows())
247 {
248 $result = $ilDB->queryF("SELECT tst_pass_result.*, tst_tests.pass_scoring, tst_tests.random_test, tst_tests.test_id FROM tst_pass_result, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_pass_result.active_fi = tst_active.active_id ORDER BY tst_pass_result.pass",
249 array('integer','integer'),
250 array($user_id, $a_obj_id)
251 );
252
253 while ($row = $ilDB->fetchAssoc($result))
254 {
255 array_push($points, $row);
256 }
257 $reached = 0;
258 $max = 0;
259 if ($points[0]["pass_scoring"] == 0)
260 {
261 $reached = $points[count($points)-1]["points"];
262 $max = $points[count($points)-1]["maxpoints"];
263 if (!$max)
264 {
265 $active_id = $points[count($points)-1]["active_fi"];
266 $pass = $points[count($points)-1]["pass"];
267 if (strlen($active_id) && strlen($pass))
268 {
269 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
270 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
271 $max = $res['maxpoints'];
272 $reached = $res['points'];
273 }
274 }
275 }
276 else
277 {
278 foreach ($points as $row)
279 {
280 if ($row["points"] > $reached)
281 {
282 $reached = $row["points"];
283 $max = $row["maxpoints"];
284 if (!$max)
285 {
286 $active_id = $row["active_fi"];
287 $pass = $row["pass"];
288 if (strlen($active_id) && strlen($pass))
289 {
290 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
291 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
292 $max = $res['maxpoints'];
293 $reached = $res['points'];
294 }
295 }
296 }
297 }
298 }
299 include_once "./Modules/Test/classes/class.assMarkSchema.php";
300 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
301 $mark = ASS_MarkSchema::_getMatchingMarkFromObjId($a_obj_id, $percentage);
302 return ($mark["failed"]) ? TRUE : FALSE;
303 }
304 else
305 {
306 $row = $ilDB->fetchAssoc($result);
307 return ($row['failed']) ? TRUE : FALSE;
308 }
309 }
updateTestResultCache($a_user_id, $a_obj_id)
Update test result cache.

References $ilDB, $pass, $res, $result, $ret, $row, ASS_MarkSchema\_getMatchingMarkFromObjId(), and updateTestResultCache().

Referenced by checkCondition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateTestResultCache()

ilObjTestAccess::updateTestResultCache (   $a_user_id,
  $a_obj_id 
)
protected

Update test result cache.

Parameters
type$a_user_id
type$a_obj_id

Definition at line 316 of file class.ilObjTestAccess.php.

317 {
318 global $ilDB;
319
320 $result = $ilDB->queryF(
321 "SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests ".
322 "WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s ".
323 "AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
324 array('integer','integer'),
325 array($a_user_id, $a_obj_id)
326 );
327 if (!$result->numRows())
328 {
329 $result = $ilDB->queryF("SELECT tst_active.active_id FROM tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s",
330 array('integer','integer'),
331 array($a_user_id, $a_obj_id)
332 );
333 $row = $ilDB->fetchAssoc($result);
334 if ($row['active_id'] > 0)
335 {
336 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
338 return true;
339 }
340 else
341 {
342 return false;
343 }
344
345 }
346 else
347 {
348 return true;
349 }
350 }

References $ilDB, $result, $row, and assQuestion\_updateTestResultCache().

Referenced by isFailed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ visibleUserResultExists()

static ilObjTestAccess::visibleUserResultExists (   $testObjId,
  $userId 
)
static

Definition at line 946 of file class.ilObjTestAccess.php.

947 {
948 $testOBJ = ilObjectFactory::getInstanceByObjId($testObjId, false);
949
950 if( !($testOBJ instanceof ilObjTest) )
951 {
952 return false;
953 }
954
955 require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
956 $testSessionFactory = new ilTestSessionFactory($testOBJ);
957 $testSession = $testSessionFactory->getSessionByUserId($userId);
958
959 return $testOBJ->canShowTestResults($testSession);
960 }

References ilObjectFactory\getInstanceByObjId().

Referenced by ilLOUtils\getTestResultLinkForUser(), and ilObjTestListGUI\handleUserResultsCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $hasFinishedCache

ilObjTestAccess::$hasFinishedCache = array()
staticprivate

Definition at line 454 of file class.ilObjTestAccess.php.


The documentation for this class was generated from the following file: