ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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...
 
- 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...
 

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 _getCommands ()
 get commands More...
 
static _lookupCreationComplete ($a_obj_id)
 checks wether all necessary parts of the test are given 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 _getTestIDFromObjectID ($object_id)
 Returns the ILIAS test id for a given object id. More...
 
static _lookupObjIdForTestId ($a_test_id)
 Lookup object id for test id. More...
 
static _getRandomTestsForQuestionPool ($qpl_id)
 Get all tests using a question pool for random selection. More...
 
static _lookupOnlineTestAccess ($a_test_id, $a_user_id)
 Checks if a user is allowd to run an online exam. More...
 
static _getParticipantData ($active_id)
 Retrieves a participant name from active id. More...
 
static _getParticipantId ($active_id)
 Get user id for active id. More...
 
static _getPassedUsers ($a_obj_id)
 Returns an array containing the users who passed the test. More...
 
static _checkGoto ($a_target)
 check whether goto script will succeed 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 hasVisibleCertificate ($testObjId, $userId)
 @ideaof Andre Michels amich.nosp@m.els@.nosp@m.datab.nosp@m.ay.d.nosp@m.e More...
 
- Static Public Member Functions inherited from ilObjectAccess
static _getCommands ()
 get commands More...
 
static _checkGoto ($a_target)
 check whether goto script will succeed More...
 
static _isOffline ($a_obj_id)
 Type-specific implementation of general status, has to be overwritten. More...
 
static _preloadData ($a_obj_ids, $a_ref_ids)
 Preload data. 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...
 

Static Protected Member Functions

static 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
static _lookupCreationComplete($a_obj_id)
checks wether all necessary parts of the test are given
global $lng
Definition: privfeed.php:17
$ilUser
Definition: imgupload.php:18

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

+ Here is the call graph for this function:

◆ _checkGoto()

static ilObjTestAccess::_checkGoto (   $a_target)
static

check whether goto script will succeed

Reimplemented from ilObjectAccess.

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

768 {
769 global $ilAccess;
770
771 $t_arr = explode("_", $a_target);
772
773 if ($t_arr[0] != "tst" || ((int) $t_arr[1]) <= 0)
774 {
775 return false;
776 }
777
778 if ($ilAccess->checkAccess("read", "", $t_arr[1]))
779 {
780 return true;
781 }
782 return false;
783 }

◆ _getCommands()

static ilObjTestAccess::_getCommands ( )
static

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 371 of file class.ilObjTestAccess.php.

372 {
373 $commands = array
374 (
375 array("permission" => "write", "cmd" => "questionsTabGateway", "lang_var" => "tst_edit_questions"),
376 array("permission" => "write", "cmd" => "ilObjTestSettingsGeneralGUI::showForm", "lang_var" => "settings"),
377 array("permission" => "read", "cmd" => "infoScreen", "lang_var" => "tst_run",
378 "default" => true),
379 //array("permission" => "write", "cmd" => "", "lang_var" => "edit"),
380 array("permission" => "tst_statistics", "cmd" => "outEvaluation", "lang_var" => "tst_statistical_evaluation"),
381 array("permission" => "read", "cmd" => "userResultsGateway", "lang_var" => "tst_test_results")
382 );
383
384 return $commands;
385 }

Referenced by ilObjTestListGUI\init().

+ Here is the caller graph for this function:

◆ _getParticipantData()

static ilObjTestAccess::_getParticipantData (   $active_id)
static

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 596 of file class.ilObjTestAccess.php.

597 {
598 global $lng, $ilDB;
599
600 $result = $ilDB->queryF("SELECT * FROM tst_active WHERE active_id = %s",
601 array("integer"),
602 array($active_id)
603 );
604 $row = $ilDB->fetchAssoc($result);
605 $user_id = $row["user_fi"];
606 $test_id = $row["test_fi"];
607 $importname = $row['importname'];
608
609 $result = $ilDB->queryF("SELECT obj_fi FROM tst_tests WHERE test_id = %s",
610 array("integer"),
611 array($test_id)
612 );
613 $row = $ilDB->fetchAssoc($result);
614 $obj_id = $row["obj_fi"];
615
616 include_once "./Modules/Test/classes/class.ilObjTest.php";
617 $is_anonymous = ilObjTest::_lookupAnonymity($obj_id);
618
619 include_once './Services/User/classes/class.ilObjUser.php';
620 $uname = ilObjUser::_lookupName($user_id);
621
622 $name = "";
623 if (strlen($importname))
624 {
625 $name = $importname . ' (' . $lng->txt('imported') . ')';
626 }
627 else if (strlen($uname["firstname"].$uname["lastname"]) == 0)
628 {
629 $name = $lng->txt("deleted_user");
630 }
631 else
632 {
633 if ($user_id == ANONYMOUS_USER_ID)
634 {
635 $name = $lastname;
636 }
637 else
638 {
639 $name = trim($uname["lastname"] . ", " . $uname["firstname"] . " " . $uname["title"]);
640 }
641 if ($is_anonymous)
642 {
643 $name = $lng->txt("anonymous");
644 }
645 }
646 return $name;
647 }
$result
static _lookupAnonymity($a_obj_id)
Returns the anonymity status of a test with a given object id.
static _lookupName($a_user_id)
lookup user name
global $ilDB

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()

static ilObjTestAccess::_getParticipantId (   $active_id)
static

Get user id for active id.

Parameters
intactive ID of the participant
Returns
int user id

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

656 {
657 global $lng, $ilDB;
658
659 $result = $ilDB->queryF("SELECT user_fi FROM tst_active WHERE active_id = %s",
660 array("integer"),
661 array($active_id)
662 );
663 $row = $ilDB->fetchAssoc($result);
664 return $row["user_fi"];
665 }

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

Referenced by assFileUpload\handleSubmission(), ilTestScoringGUI\saveManScoringParticipantScreen(), ilTestSessionDynamicQuestionSet\saveToDb(), and ilTestPassFinishTasks\updateLearningProgressAfterPassFinishedIsWritten().

+ Here is the caller graph for this function:

◆ _getPassedUsers()

static ilObjTestAccess::_getPassedUsers (   $a_obj_id)
static

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 682 of file class.ilObjTestAccess.php.

683 {
684 global $ilDB;
685
686 $passed_users = array();
687 // Maybe SELECT DISTINCT(tst_active.user_fi)... ?
688 $userresult = $ilDB->queryF("
689 SELECT tst_active.active_id, COUNT(tst_sequence.active_fi) sequences, tst_active.last_finished_pass,
690 CASE WHEN
691 (tst_tests.nr_of_tries - 1) = tst_active.last_finished_pass
692 THEN '1'
693 ELSE '0'
694 END is_last_pass
695 FROM tst_tests
696 INNER JOIN tst_active
697 ON tst_active.test_fi = tst_tests.test_id
698 LEFT JOIN tst_sequence
699 ON tst_sequence.active_fi = tst_active.active_id
700 WHERE tst_tests.obj_fi = %s
701 GROUP BY tst_active.active_id
702 ",
703 array('integer'), array($a_obj_id)
704 );
705 $all_participants = array();
706 $notAttempted = array();
707 $lastPassUsers = array();
708 while ($row = $ilDB->fetchAssoc($userresult))
709 {
710 if($row['sequences'] == 0)
711 {
712 $notAttempted[$row['active_id']] = $row['active_id'];
713 }
714 if($row['is_last_pass'])
715 {
716 $lastPassUsers[$row['active_id']] = $row['active_id'];
717 }
718
719 $all_participants[$row['active_id']] = $row['active_id'];
720 }
721
722 $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'));
723 $found_all = ($result->numRows() == count($all_participants)) ? true : false;
724 if (!$found_all)
725 {
726 // if the result cache entries do not exist, create them
727 $found_participants = array();
728 while ($data = $ilDB->fetchAssoc($result))
729 {
730 array_push($found_participants, $data['active_fi']);
731 }
732 foreach ($all_participants as $active_id)
733 {
734 if (!in_array($active_id, $found_participants))
735 {
736 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
738 }
739 }
740 $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'));
741 }
742 while ($data = $ilDB->fetchAssoc($result))
743 {
744 if( isset($notAttempted[$data['active_fi']]) )
745 {
746 $data['failed'] = 0;
747 $data['passed'] = 0;
748 $data['not_attempted'] = 1;
749 }
750
751 if( $data['failed'] && !isset($lastPassUsers[$data['active_fi']]) )
752 {
753 $data['passed'] = 0;
754 $data['failed'] = 0;
755 $data['in_progress'] = 1;
756 }
757
758 $data['user_id'] = $data['user_fi'];
759 array_push($passed_users, $data);
760 }
761 return $passed_users;
762 }
static _updateTestResultCache($active_id, ilAssQuestionProcessLocker $processLocker=null)
@TODO Move this to a proper place.

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()

static ilObjTestAccess::_getRandomTestsForQuestionPool (   $qpl_id)
static

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 504 of file class.ilObjTestAccess.php.

505 {
506 global $ilDB;
507
508 $query = "
509 SELECT DISTINCT t.obj_fi
510 FROM tst_tests t
511 INNER JOIN tst_rnd_quest_set_qpls r
512 ON t.test_id = r.test_fi
513 WHERE r.pool_fi = %s
514 ";
515
516 $result = $ilDB->queryF($query, array('integer'), array($qpl_id));
517
518 $tests = array();
519 while ($row = $ilDB->fetchAssoc($result))
520 {
521 $tests[] = $row['obj_fi'];
522 }
523
524 return $tests;
525 }

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

Referenced by ilObjMediaObjectAccess\checkAccessTestQuestion().

+ Here is the caller graph for this function:

◆ _getTestIDFromObjectID()

static ilObjTestAccess::_getTestIDFromObjectID (   $object_id)
static

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 462 of file class.ilObjTestAccess.php.

463 {
464 global $ilDB;
465 $test_id = FALSE;
466 $result = $ilDB->queryF("SELECT test_id FROM tst_tests WHERE obj_fi = %s",
467 array('integer'),
468 array($object_id)
469 );
470 if ($result->numRows())
471 {
472 $row = $ilDB->fetchAssoc($result);
473 $test_id = $row["test_id"];
474 }
475 return $test_id;
476 }

References $ilDB, $result, and $row.

Referenced by ilLPStatusTestFinished\getParticipants().

+ Here is the caller graph for this function:

◆ _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 793 of file class.ilObjTestAccess.php.

794 {
795// global $ilUser;
796// return (self::_lookupOnlineTestAccess($a_obj_id, $ilUser->getId()) !== true) ||
797// (!ilObjTestAccess::_lookupCreationComplete($a_obj_id));
798 return !self::_isOnline($a_obj_id);
799 }
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 807 of file class.ilObjTestAccess.php.

808 {
809 global $ilDB;
810
811 $query = "
812 SELECT test_id
813 FROM tst_tests
814 WHERE obj_fi = %s
815 AND online_status = 1
816 ";
817
818 $result = $ilDB->queryF( $query, array('integer'), array($a_obj_id) );
819
820 return $result->numRows() == 1;
821 }

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 91 of file class.ilObjTestAccess.php.

92 {
93 global $ilDB;
94 $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",
95 array('integer','integer'),
96 array($user_id, $a_obj_id)
97 );
98 if (!$result->numRows())
99 {
100 $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",
101 array('integer','integer'),
102 array($user_id, $a_obj_id)
103 );
104 $row = $ilDB->fetchAssoc($result);
105 if ($row['active_id'] > 0)
106 {
107 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
109 }
110 else
111 {
112 return false;
113 }
114 }
115 $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",
116 array('integer','integer'),
117 array($user_id, $a_obj_id)
118 );
119 if (!$result->numRows())
120 {
121 $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",
122 array('integer','integer'),
123 array($user_id, $a_obj_id)
124 );
125 $points = array();
126 while ($row = $ilDB->fetchAssoc($result))
127 {
128 array_push($points, $row);
129 }
130 $reached = 0;
131 $max = 0;
132 if ($points[0]["pass_scoring"] == 0)
133 {
134 $reached = $points[count($points)-1]["points"];
135 $max = $points[count($points)-1]["maxpoints"];
136 if (!$max)
137 {
138 $active_id = $points[count($points)-1]["active_fi"];
139 $pass = $points[count($points)-1]["pass"];
140 if (strlen($active_id) && strlen($pass))
141 {
142 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
143 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
144 $max = $res['maxpoints'];
145 $reached = $res['points'];
146 }
147 }
148 }
149 else
150 {
151 foreach ($points as $row)
152 {
153 if ($row["points"] > $reached)
154 {
155 $reached = $row["points"];
156 $max = $row["maxpoints"];
157 if (!$max)
158 {
159 $active_id = $row["active_fi"];
160 $pass = $row["pass"];
161 if (strlen($active_id) && strlen($pass))
162 {
163 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
164 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
165 $max = $res['maxpoints'];
166 $reached = $res['points'];
167 }
168 }
169 }
170 }
171 }
172 include_once "./Modules/Test/classes/class.assMarkSchema.php";
173 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
174 $mark = ASS_MarkSchema::_getMatchingMarkFromObjId($a_obj_id, $percentage);
175 return ($mark["passed"]) ? TRUE : FALSE;
176 }
177 else
178 {
179 $row = $ilDB->fetchAssoc($result);
180 return ($row['passed']) ? true : false;
181 }
182 }
static _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()

static ilObjTestAccess::_lookupCreationComplete (   $a_obj_id)
static

checks wether all necessary parts of the test are given

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

395 {
396 global $ilDB;
397
398 $result = $ilDB->queryF("SELECT complete FROM tst_tests WHERE obj_fi=%s",
399 array('integer'),
400 array($a_obj_id)
401 );
402 if ($result->numRows() == 1)
403 {
404 $row = $ilDB->fetchAssoc($result);
405 }
406
407 return ($row['complete']) ? true : false;
408 }

References $ilDB, $result, and $row.

Referenced by _checkAccess().

+ Here is the caller graph for this function:

◆ _lookupObjIdForTestId()

static ilObjTestAccess::_lookupObjIdForTestId (   $a_test_id)
static

Lookup object id for test id.

Parameters
inttest id
Returns
int object id

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

485 {
486 global $ilDB;
487
488 $result = $ilDB->queryF("SELECT obj_fi FROM tst_tests WHERE test_id = %s",
489 array('integer'),
490 array($a_test_id)
491 );
492
493 $row = $ilDB->fetchAssoc($result);
494 return $row["obj_fi"];
495 }

References $ilDB, $result, and $row.

Referenced by ilTestSessionDynamicQuestionSet\saveToDb().

+ Here is the caller graph for this function:

◆ _lookupOnlineTestAccess()

static ilObjTestAccess::_lookupOnlineTestAccess (   $a_test_id,
  $a_user_id 
)
static

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 534 of file class.ilObjTestAccess.php.

535 {
536 global $ilDB, $lng;
537
538 $result = $ilDB->queryF("SELECT tst_tests.* FROM tst_tests WHERE tst_tests.obj_fi = %s",
539 array('integer'),
540 array($a_test_id)
541 );
542 if ($result->numRows())
543 {
544 $row = $ilDB->fetchAssoc($result);
545 if ($row["fixed_participants"])
546 {
547 $result = $ilDB->queryF("SELECT * FROM tst_invited_user WHERE test_fi = %s AND user_fi = %s",
548 array('integer','integer'),
549 array($row["test_id"], $a_user_id)
550 );
551 if ($result->numRows())
552 {
553 $row = $ilDB->fetchAssoc($result);
554 if (trim($row['clientip']) != "")
555 {
556 $row['clientip'] = preg_replace("/[^0-9.?*,:]+/","",$row['clientip']);
557 $row['clientip'] = str_replace(".","\\.",$row['clientip']);
558 $row['clientip'] = str_replace(Array("?","*",","), Array("[0-9]","[0-9]*","|"), $row['clientip']);
559 if (!preg_match("/^".$row['clientip']."$/", $_SERVER["REMOTE_ADDR"]))
560 {
561 return $lng->txt("tst_user_wrong_clientip");
562 }
563 else
564 {
565 return true;
566 }
567 }
568 else
569 {
570 return true;
571 }
572 }
573 else
574 {
575 return $lng->txt("tst_user_not_invited");
576 }
577 }
578 else
579 {
580 return true;
581 }
582 }
583 else
584 {
585 return true;
586 }
587 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

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

Referenced by ilTestInfoScreenToolbarGUI\build(), 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 334 of file class.ilObjTestAccess.php.

335 {
336 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
337
338 switch($a_operator)
339 {
341 return ilObjTestAccess::_isPassed($a_usr_id, $a_obj_id);
342 break;
343
345 return ilObjTestAccess::isFailed($a_usr_id, $a_obj_id);
346
348 return ilObjTestAccess::hasFinished($a_usr_id,$a_obj_id);
349
351 return !ilObjTestAccess::hasFinished($a_usr_id,$a_obj_id);
352
353 default:
354 return true;
355 }
356 return true;
357 }
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 317 of file class.ilObjTestAccess.php.

318 {
319 include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
320 return array(
325 );
326 }

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$a_user_idobj_id of the user
integer$a_obj_idobj_id of the test
Returns
bool

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

425 {
426 if( !isset(self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"]) )
427 {
428 require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
429 require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
430 require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
431
432 global $ilDB, $lng;
433
434 $testOBJ = ilObjectFactory::getInstanceByObjId($a_obj_id);
435
436 $partData = new ilTestParticipantData($ilDB, $lng);
437 $partData->setUserIds(array($a_user_id));
438 $partData->load($testOBJ->getTestId());
439
440 $activeId = $partData->getActiveIdByUserId($a_user_id);
441
442 $testSessionFactory = new ilTestSessionFactory($testOBJ);
443 $testSession = $testSessionFactory->getSession($activeId);
444
445 $testPassesSelector = new ilTestPassesSelector($ilDB, $testOBJ);
446 $testPassesSelector->setActiveId($activeId);
447 $testPassesSelector->setLastFinishedPass($testSession->getLastFinishedPass());
448
449 self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"] = count($testPassesSelector->getClosedPasses());
450 }
451
452 return (bool) self::$hasFinishedCache["{$a_user_id}:{$a_obj_id}"];
453 }
static 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:

◆ hasVisibleCertificate()

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

@ideaof Andre Michels amich.nosp@m.els@.nosp@m.datab.nosp@m.ay.d.nosp@m.e

Parameters
$testObjId
$userId
Returns
bool

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

847 {
848 $testOBJ = ilObjectFactory::getInstanceByObjId($testObjId, false);
849
850 if( !($testOBJ instanceof ilObjTest) || !$userId )
851 {
852 return false;
853 }
854
855 require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
856 $testSessionFactory = new ilTestSessionFactory($testOBJ);
857 $testSession = $testSessionFactory->getSessionByUserId($userId);
858
859 if( !$testSession->getActiveId() )
860 {
861 return false;
862 }
863
864 return $testOBJ->canShowCertificate($testSession, $testSession->getUserId(), $testSession->getActiveId());
865 }

References ilObjectFactory\getInstanceByObjId().

+ Here is the call 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 191 of file class.ilObjTestAccess.php.

192 {
193 global $ilDB;
194
195 $ret = self::updateTestResultCache($user_id, $a_obj_id);
196
197 if(!$ret)
198 {
199 return false;
200 }
201
202 $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",
203 array('integer','integer'),
204 array($user_id, $a_obj_id)
205 );
206
207 if (!$result->numRows())
208 {
209 $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",
210 array('integer','integer'),
211 array($user_id, $a_obj_id)
212 );
213
214 while ($row = $ilDB->fetchAssoc($result))
215 {
216 array_push($points, $row);
217 }
218 $reached = 0;
219 $max = 0;
220 if ($points[0]["pass_scoring"] == 0)
221 {
222 $reached = $points[count($points)-1]["points"];
223 $max = $points[count($points)-1]["maxpoints"];
224 if (!$max)
225 {
226 $active_id = $points[count($points)-1]["active_fi"];
227 $pass = $points[count($points)-1]["pass"];
228 if (strlen($active_id) && strlen($pass))
229 {
230 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
231 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
232 $max = $res['maxpoints'];
233 $reached = $res['points'];
234 }
235 }
236 }
237 else
238 {
239 foreach ($points as $row)
240 {
241 if ($row["points"] > $reached)
242 {
243 $reached = $row["points"];
244 $max = $row["maxpoints"];
245 if (!$max)
246 {
247 $active_id = $row["active_fi"];
248 $pass = $row["pass"];
249 if (strlen($active_id) && strlen($pass))
250 {
251 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
252 $res = assQuestion::_updateTestPassResults($active_id, $pass, null, $a_obj_id);
253 $max = $res['maxpoints'];
254 $reached = $res['points'];
255 }
256 }
257 }
258 }
259 }
260 include_once "./Modules/Test/classes/class.assMarkSchema.php";
261 $percentage = (!$max) ? 0 : ($reached / $max) * 100.0;
262 $mark = ASS_MarkSchema::_getMatchingMarkFromObjId($a_obj_id, $percentage);
263 return ($mark["failed"]) ? TRUE : FALSE;
264 }
265 else
266 {
267 $row = $ilDB->fetchAssoc($result);
268 return ($row['failed']) ? TRUE : FALSE;
269 }
270 }
static updateTestResultCache($a_user_id, $a_obj_id)
Update test result cache.
$ret
Definition: parser.php:6

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()

static ilObjTestAccess::updateTestResultCache (   $a_user_id,
  $a_obj_id 
)
staticprotected

Update test result cache.

Parameters
type$a_user_id
type$a_obj_id

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

278 {
279 global $ilDB;
280
281 $result = $ilDB->queryF(
282 "SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests ".
283 "WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s ".
284 "AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id",
285 array('integer','integer'),
286 array($a_user_id, $a_obj_id)
287 );
288 if (!$result->numRows())
289 {
290 $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",
291 array('integer','integer'),
292 array($a_user_id, $a_obj_id)
293 );
294 $row = $ilDB->fetchAssoc($result);
295 if ($row['active_id'] > 0)
296 {
297 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
299 return true;
300 }
301 else
302 {
303 return false;
304 }
305
306 }
307 else
308 {
309 return true;
310 }
311 }

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 823 of file class.ilObjTestAccess.php.

824 {
825 $testOBJ = ilObjectFactory::getInstanceByObjId($testObjId, false);
826
827 if( !($testOBJ instanceof ilObjTest) )
828 {
829 return false;
830 }
831
832 require_once 'Modules/Test/classes/class.ilTestSessionFactory.php';
833 $testSessionFactory = new ilTestSessionFactory($testOBJ);
834 $testSession = $testSessionFactory->getSessionByUserId($userId);
835
836 return $testOBJ->canShowTestResults($testSession);
837 }

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 415 of file class.ilObjTestAccess.php.


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