ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestPasswordChecker.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
5 
13 {
17  protected $rbacsystem;
18 
22  protected $user;
23 
27  protected $testOBJ;
28 
32  protected $lng;
33 
35  {
36  $this->rbacsystem = $rbacsystem;
37  $this->user = $user;
38  $this->testOBJ = $testOBJ;
39  $this->lng = $lng;
40 
41  $this->initSession();
42  }
43 
45  {
46  if( !$this->isTestPasswordEnabled() )
47  {
48  return false;
49  }
50 
51  if( $this->isPrivilegedParticipant() )
52  {
53  return false;
54  }
55 
56  if( $this->isUserEnteredPasswordCorrect() )
57  {
58  return false;
59  }
60 
61  return true;
62  }
63 
64  protected function isTestPasswordEnabled()
65  {
66  return strlen($this->testOBJ->getPassword());
67  }
68 
69  protected function isPrivilegedParticipant()
70  {
71  return $this->rbacsystem->checkAccess('write', $this->testOBJ->getRefId());
72  }
73 
75  {
76  if( !strlen($this->getUserEnteredPassword()) )
77  {
78  return false;
79  }
80 
81  return !$this->isUserEnteredPasswordCorrect();
82  }
83 
84  public function isUserEnteredPasswordCorrect()
85  {
86  return $this->getUserEnteredPassword() == $this->testOBJ->getPassword();
87  }
88 
89  public function setUserEnteredPassword($enteredPassword)
90  {
91  $_SESSION[$this->buildSessionKey()] = $enteredPassword;
92  }
93 
94  protected function getUserEnteredPassword()
95  {
96  return $_SESSION[$this->buildSessionKey()];
97  }
98 
99  protected function initSession()
100  {
101  if( !isset($_SESSION[$this->buildSessionKey()]) )
102  {
103  $_SESSION[$this->buildSessionKey()] = null;
104  }
105  }
106 
107  protected function buildSessionKey()
108  {
109  return 'tst_password_'.$this->testOBJ->getTestId();
110  }
111 
112  public function logWrongEnteredPassword()
113  {
115  {
116  return;
117  }
118 
119  ilObjAssessmentFolder::_addLog( $this->user->getId(), $this->testOBJ->getId(),
120  $this->getWrongEnteredPasswordLogMsg(), null, null, true, $this->testOBJ->getRefId()
121  );
122  }
123 
124  protected function getWrongEnteredPasswordLogMsg()
125  {
126  $msg = $this->lng->txtlng(
127  'assessment', 'log_wrong_test_password_entered', ilObjAssessmentFolder::_getLogLanguage()
128  );
129 
130  return sprintf($msg, $this->getUserEnteredPassword());
131  }
132 }
class ilRbacSystem system function like checkAccess, addActiveRole ...
static _addLog($user_id, $object_id, $logtext, $question_id="", $original_id="", $test_only=FALSE, $test_ref_id=NULL)
Add an assessment log entry.
$_SESSION["AccountId"]
__construct(ilRbacSystem $rbacsystem, ilObjUser $user, ilObjTest $testOBJ, ilLanguage $lng)
user()
Definition: user.php:4
static _getLogLanguage()
retrieve the log language for assessment logging
static _enabledAssessmentLogging()
check wether assessment logging is enabled or not
setUserEnteredPassword($enteredPassword)
language handling