ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Survey\Execution\RunManager Class Reference

Survey Run Note: The manager should get the current user id passed. More...

+ Collaboration diagram for ILIAS\Survey\Execution\RunManager:

Public Member Functions

 __construct (InternalRepoService $repo_service, InternalDomainService $domain_service, \ilObjSurvey $survey, int $current_user_id, int $appraisee_id=0)
 
 getCurrentRunId ()
 
 hasStarted (int $appraisee=0)
 
 hasFinished ()
 
 belongsToFinishedRun (string $code)
 Does code belong to current anonymous started, but not finished run? Note: this method acts on the current user, but accepts the passed code and does not retrieve the code from the session. More...
 
 getRunsForUser (int $user_id, string $code="")
 
 getById (int $run_id)
 
 start (int $appraisee_id=0)
 Starts the survey creating a new run. More...
 
 initSession (string $requested_code="")
 
 getCode ()
 Get current valid code. More...
 
 clearCode ()
 
 setStartTime (int $first_question)
 Set start time of run. More...
 
 setEndTime ()
 
 getPageEnter ()
 
 setPreviewData (int $question_id, array $data)
 
 getPreviewData (int $question_id)
 
 clearPreviewData (int $question_id)
 
 clearAllPreviewData ()
 
 setErrors (array $errors)
 
 getErrors ()
 
 clearErrors ()
 
 setPostData (array $data)
 
 getPostData ()
 
 clearPostData ()
 

Protected Member Functions

 codeNeeded ()
 
 checkUserParameters (int $user_id, string $code="")
 Check user parameters. More...
 
 getCurrentState ()
 

Protected Attributes

ilLanguage $lng
 
ILIAS Survey Code CodeManager $code_manager
 
RunSessionRepo $session_repo
 
RunDBRepository $repo
 
int $survey_id
 
Mode FeatureConfig $feature_config
 
InternalDomainService $domain_service
 
ilObjSurvey $survey
 
int $current_user_id
 
int $appraisee_id
 

Detailed Description

Survey Run Note: The manager should get the current user id passed.

The manager also receives the current access key (code) from the session manager automatically.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 34 of file class.RunManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Survey\Execution\RunManager::__construct ( InternalRepoService  $repo_service,
InternalDomainService  $domain_service,
\ilObjSurvey  $survey,
int  $current_user_id,
int  $appraisee_id = 0 
)

Definition at line 47 of file class.RunManager.php.

53 {
54 $this->repo = $repo_service->execution()->run();
55
56 $this->survey_id = $survey->getSurveyId();
57 $this->survey = $survey;
58 $this->feature_config = $domain_service->modeFeatureConfig($survey->getMode());
59 $this->domain_service = $domain_service;
60 $this->current_user_id = $current_user_id;
61 $this->appraisee_id = $appraisee_id;
62 $this->session_repo = $repo_service->execution()->runSession();
63 $this->code_manager = $domain_service->code($survey, $current_user_id);
64 $this->lng = $domain_service->lng();
65 }
InternalDomainService $domain_service
code(\ilObjSurvey $survey, int $user_id)

References ILIAS\Survey\Execution\RunManager\$appraisee_id, ILIAS\Survey\Execution\RunManager\$current_user_id, ILIAS\Survey\Execution\RunManager\$domain_service, ILIAS\Survey\Execution\RunManager\$survey, ILIAS\Survey\InternalDomainService\code(), ILIAS\Survey\InternalRepoService\execution(), ilObjSurvey\getMode(), ilObjSurvey\getSurveyId(), ILIAS\Repository\lng(), and ILIAS\Survey\InternalDomainService\modeFeatureConfig().

+ Here is the call graph for this function:

Member Function Documentation

◆ belongsToFinishedRun()

ILIAS\Survey\Execution\RunManager::belongsToFinishedRun ( string  $code)

Does code belong to current anonymous started, but not finished run? Note: this method acts on the current user, but accepts the passed code and does not retrieve the code from the session.

Definition at line 145 of file class.RunManager.php.

147 : bool {
149 $code_manager = $this->domain_service->code($this->survey, $this->current_user_id);
150
151 if ($code_manager->exists($code)) {
152 $run_id = $repo->getCurrentRunId(
153 $this->survey_id,
154 $this->current_user_id,
155 $code,
156 $this->appraisee_id
157 );
158 if ($run_id > 0) {
159 $state = $repo->getState($run_id);
160 if ($state === RunDBRepository::FINISHED) {
161 return true;
162 }
163 }
164 }
165 return false;
166 }
getCurrentRunId(int $survey_id, int $user_id, string $code="", int $appr_id=0)
ILIAS Survey Code CodeManager $code_manager

References ILIAS\Survey\Execution\RunDBRepository\FINISHED, ILIAS\Survey\Execution\RunDBRepository\getCurrentRunId(), and ILIAS\Survey\Execution\RunDBRepository\getState().

+ Here is the call graph for this function:

◆ checkUserParameters()

ILIAS\Survey\Execution\RunManager::checkUserParameters ( int  $user_id,
string  $code = "" 
)
protected

Check user parameters.

Exceptions

ilSurveyException

Todo:
: somehow this does not belong here, maybe session manager instead?

Definition at line 95 of file class.RunManager.php.

98 : void {
99 if ($this->feature_config->usesAppraisees() && $this->appraisee_id === 0) {
100 throw new \ilSurveyException("No appraisee specified");
101 }
102
103 if (!$this->feature_config->usesAppraisees() && $this->appraisee_id > 0) {
104 // self eval currently uses current user as appraisee id
105 if ($this->survey->getMode() !== \ilObjSurvey::MODE_SELF_EVAL || $user_id !== $this->appraisee_id) {
106 throw new \ilSurveyException("Appraisee ID given, but appraisees not supported");
107 }
108 }
109
110 /* this fails on the info screen
111 if ($user_id === ANONYMOUS_USER_ID && $code === "") {
112 throw new \ilSurveyException("Code missing for anonymous user.");
113 }*/
114 }

Referenced by ILIAS\Survey\Execution\RunManager\getCurrentRunId().

+ Here is the caller graph for this function:

◆ clearAllPreviewData()

ILIAS\Survey\Execution\RunManager::clearAllPreviewData ( )

Definition at line 314 of file class.RunManager.php.

314 : void
315 {
316 $this->session_repo->clearAllPreviewData($this->survey_id);
317 }

◆ clearCode()

ILIAS\Survey\Execution\RunManager::clearCode ( )

Definition at line 269 of file class.RunManager.php.

269 : void
270 {
271 $this->session_repo->clearCode($this->survey->getId());
272 }

◆ clearErrors()

ILIAS\Survey\Execution\RunManager::clearErrors ( )

Definition at line 329 of file class.RunManager.php.

329 : void
330 {
331 $this->session_repo->clearErrors();
332 }

◆ clearPostData()

ILIAS\Survey\Execution\RunManager::clearPostData ( )

Definition at line 344 of file class.RunManager.php.

344 : void
345 {
346 $this->session_repo->clearPostData();
347 }

◆ clearPreviewData()

ILIAS\Survey\Execution\RunManager::clearPreviewData ( int  $question_id)

Definition at line 309 of file class.RunManager.php.

309 : void
310 {
311 $this->session_repo->clearPreviewData($this->survey_id, $question_id);
312 }

◆ codeNeeded()

ILIAS\Survey\Execution\RunManager::codeNeeded ( )
protected

Definition at line 67 of file class.RunManager.php.

67 : bool
68 {
69 return !$this->survey->isAccessibleWithoutCode();
70 }

Referenced by ILIAS\Survey\Execution\RunManager\getCurrentRunId().

+ Here is the caller graph for this function:

◆ getById()

ILIAS\Survey\Execution\RunManager::getById ( int  $run_id)

Definition at line 178 of file class.RunManager.php.

178 : ?Run
179 {
180 $run = $this->repo->getById($run_id);
181 if (!is_null($run) && $run->getSurveyId() !== $this->survey->getSurveyId()) {
182 throw new \ilSurveyException("Run survey id mismatch.");
183 }
184 return $run;
185 }

◆ getCode()

ILIAS\Survey\Execution\RunManager::getCode ( )

Get current valid code.

Definition at line 264 of file class.RunManager.php.

264 : string
265 {
266 return $this->session_repo->getCode($this->survey->getId());
267 }

Referenced by ILIAS\Survey\Execution\RunManager\getCurrentRunId().

+ Here is the caller graph for this function:

◆ getCurrentRunId()

ILIAS\Survey\Execution\RunManager::getCurrentRunId ( )

Definition at line 72 of file class.RunManager.php.

72 : int
73 {
77 $code = $this->getCode();
78
79 $this->checkUserParameters($user_id, $code);
80
81 // code needed, no code given -> no run
82 if ($code === "" && $this->codeNeeded()) {
83 return 0;
84 }
85
86 $run_id = $repo->getCurrentRunId($survey_id, $user_id, $code, $this->appraisee_id);
87 return (int) $run_id;
88 }
checkUserParameters(int $user_id, string $code="")
Check user parameters.
getCode()
Get current valid code.

References ILIAS\Survey\Execution\RunManager\$current_user_id, ILIAS\Survey\Execution\RunManager\$repo, ILIAS\Survey\Execution\RunManager\$survey_id, $user_id, ILIAS\Survey\Execution\RunManager\checkUserParameters(), ILIAS\Survey\Execution\RunManager\codeNeeded(), ILIAS\Survey\Execution\RunManager\getCode(), and ILIAS\Survey\Execution\RunDBRepository\getCurrentRunId().

+ Here is the call graph for this function:

◆ getCurrentState()

ILIAS\Survey\Execution\RunManager::getCurrentState ( )
protected

Definition at line 118 of file class.RunManager.php.

118 : int
119 {
121 $run_id = $this->getCurrentRunId();
122 return $repo->getState($run_id);
123 }

References ILIAS\Survey\Execution\RunDBRepository\getState().

+ Here is the call graph for this function:

◆ getErrors()

ILIAS\Survey\Execution\RunManager::getErrors ( )

Definition at line 324 of file class.RunManager.php.

324 : array
325 {
326 return $this->session_repo->getErrors();
327 }

◆ getPageEnter()

ILIAS\Survey\Execution\RunManager::getPageEnter ( )

Definition at line 294 of file class.RunManager.php.

294 : int
295 {
296 return $this->session_repo->getPageEnter();
297 }

◆ getPostData()

ILIAS\Survey\Execution\RunManager::getPostData ( )

Definition at line 339 of file class.RunManager.php.

339 : array
340 {
341 return $this->session_repo->getPostData();
342 }

◆ getPreviewData()

ILIAS\Survey\Execution\RunManager::getPreviewData ( int  $question_id)

Definition at line 304 of file class.RunManager.php.

304 : array
305 {
306 return $this->session_repo->getPreviewData($this->survey_id, $question_id);
307 }

◆ getRunsForUser()

ILIAS\Survey\Execution\RunManager::getRunsForUser ( int  $user_id,
string  $code = "" 
)
Returns
Run[]

Definition at line 171 of file class.RunManager.php.

174 : array {
175 return $this->repo->getRunsForUser($this->survey->getSurveyId(), $user_id, $code);
176 }

◆ hasFinished()

ILIAS\Survey\Execution\RunManager::hasFinished ( )

Definition at line 134 of file class.RunManager.php.

134 : bool
135 {
136 return ($this->getCurrentState() ===
138 }

References ILIAS\Survey\Execution\RunDBRepository\FINISHED.

◆ hasStarted()

ILIAS\Survey\Execution\RunManager::hasStarted ( int  $appraisee = 0)

◆ initSession()

ILIAS\Survey\Execution\RunManager::initSession ( string  $requested_code = "")

Definition at line 206 of file class.RunManager.php.

208 : void {
212 // validate incoming
213 $code_input = false;
214 // ->requested_code
215 $anonymous_code = $requested_code;
216 if ($anonymous_code !== "") {
217 $code_input = true;
218 if ($this->belongsToFinishedRun($anonymous_code)) { // #15031 - valid as long survey is not finished
219 $anonymous_code = "";
220 } else {
221 // #15860
222 // a user has used a valid code, we store this in table
223 // svy_anonymous
224 $this->code_manager->bindUser($anonymous_code, $user_id);
225 $session_repo->setCode($survey->getId(), $anonymous_code);
226 }
227 }
228 // now we try to get the code from the session
229 if (!$anonymous_code) {
230 $anonymous_code = $session_repo->getCode($survey->getId());
231 if ($anonymous_code) {
232 $code_input = true; // ??
233 }
234 }
235
236 // if the survey is anonymous, codes are stored for logged
237 // in users in svy_finished. Here we get this code, if already stored
238 if ($survey->getAnonymize() && !$anonymous_code) {
239 $anonymous_code = $survey->findCodeForUser($user_id);
240 }
241
242 // get existing runs for current user, might generate code
243 $execution_status = $survey->getUserSurveyExecutionStatus($anonymous_code);
244 if ($execution_status) {
245 $anonymous_code = (string) $execution_status["code"];
246 $execution_status = $execution_status["runs"];
247 }
248
249 // (final) check for proper anonymous code
251// !$is_appraisee &&
252 $code_input && // #11346
253 (!$anonymous_code || !$this->code_manager->exists($anonymous_code))) {
254 $anonymous_code = "";
255 $this->clearCode();
256 throw new \ilWrongSurveyCodeException($this->lng->txt("svy_wrong_or_expired_code"));
257 }
258 $this->session_repo->setCode($survey->getId(), $anonymous_code);
259 }
belongsToFinishedRun(string $code)
Does code belong to current anonymous started, but not finished run? Note: this method acts on the cu...
setCode(int $survey_id, string $code)
findCodeForUser(int $a_user_id)
getUserSurveyExecutionStatus(?string $a_code=null)
Get current user execution status.

References $user_id, and ILIAS\Survey\Execution\RunSessionRepo\setCode().

+ Here is the call graph for this function:

◆ setEndTime()

ILIAS\Survey\Execution\RunManager::setEndTime ( )

Definition at line 286 of file class.RunManager.php.

286 : void
287 {
288 $run_id = $this->getCurrentRunId();
289 $time = time();
290 $this->repo->updateTime($run_id, $time, $this->session_repo->getPageEnter());
291 $this->session_repo->clearPageEnter();
292 }

◆ setErrors()

ILIAS\Survey\Execution\RunManager::setErrors ( array  $errors)

Definition at line 319 of file class.RunManager.php.

319 : void
320 {
321 $this->session_repo->setErrors($errors);
322 }

◆ setPostData()

ILIAS\Survey\Execution\RunManager::setPostData ( array  $data)

Definition at line 334 of file class.RunManager.php.

334 : void
335 {
336 $this->session_repo->setPostData($data);
337 }

References $data.

◆ setPreviewData()

ILIAS\Survey\Execution\RunManager::setPreviewData ( int  $question_id,
array  $data 
)

Definition at line 299 of file class.RunManager.php.

299 : void
300 {
301 $this->session_repo->setPreviewData($this->survey_id, $question_id, $data);
302 }

References $data.

◆ setStartTime()

ILIAS\Survey\Execution\RunManager::setStartTime ( int  $first_question)

Set start time of run.

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

279 : void {
280 $run_id = $this->getCurrentRunId();
281 $time = time();
282 $this->session_repo->setPageEnter($time);
283 $this->repo->addTime($run_id, $time, $first_question);
284 }

◆ start()

ILIAS\Survey\Execution\RunManager::start ( int  $appraisee_id = 0)

Starts the survey creating a new run.

Definition at line 190 of file class.RunManager.php.

192 : void {
195 : $this->appraisee_id;
196 $code = $this->getCode();
199
200 if ($survey->getAnonymize() && $code === '') {
201 return;
202 }
203 $this->repo->add($this->survey->getSurveyId(), $user_id, $code, $appraisee_id);
204 }

Field Documentation

◆ $appraisee_id

int ILIAS\Survey\Execution\RunManager::$appraisee_id
protected

Definition at line 45 of file class.RunManager.php.

Referenced by ILIAS\Survey\Execution\RunManager\__construct().

◆ $code_manager

ILIAS Survey Code CodeManager ILIAS\Survey\Execution\RunManager::$code_manager
protected

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

◆ $current_user_id

int ILIAS\Survey\Execution\RunManager::$current_user_id
protected

◆ $domain_service

InternalDomainService ILIAS\Survey\Execution\RunManager::$domain_service
protected

Definition at line 42 of file class.RunManager.php.

Referenced by ILIAS\Survey\Execution\RunManager\__construct().

◆ $feature_config

Mode FeatureConfig ILIAS\Survey\Execution\RunManager::$feature_config
protected

Definition at line 41 of file class.RunManager.php.

◆ $lng

ilLanguage ILIAS\Survey\Execution\RunManager::$lng
protected

Definition at line 36 of file class.RunManager.php.

◆ $repo

RunDBRepository ILIAS\Survey\Execution\RunManager::$repo
protected

◆ $session_repo

RunSessionRepo ILIAS\Survey\Execution\RunManager::$session_repo
protected

Definition at line 38 of file class.RunManager.php.

◆ $survey

ilObjSurvey ILIAS\Survey\Execution\RunManager::$survey
protected

Definition at line 43 of file class.RunManager.php.

Referenced by ILIAS\Survey\Execution\RunManager\__construct().

◆ $survey_id

int ILIAS\Survey\Execution\RunManager::$survey_id
protected

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