19declare(strict_types=1);
59 $session = [ilSession::class,
'get'],
68 $this->session = Closure::fromCallable(
$session);
71 return $access->checkResultsAccessForActiveId($active_id);
80 if (!$path_and_test) {
81 return new Error(
'Not a file upload path of test answers.');
83 if (!$path_and_test[
'test']) {
87 $object_id = (
int) ($this->object_id_of_test_id)($path_and_test[
'test']);
94 return new Ok($this->readable->references($references) && $this->roleBasedCheck($path_and_test[
'test'], $references, $path_and_test[
'path']));
99 return $this->container->user()->isAnonymous() || !$this->container->user()->getId();
106 return $code && $this->
userDidUpload($test_id, $file, $code);
109 private function userDidUpload(
int $test_id,
string $file,
string $code =
null): bool
112 'active_id = active_fi',
115 'anonymous_id ' . (
null === $code ?
'IS' :
'=') .
' %s',
119 $result = $this->container->database()->queryF(
120 'SELECT 1 FROM tst_solutions WHERE EXISTS (SELECT 1 FROM tst_active WHERE ' . implode(
' AND ', $where) .
')',
121 [
'integer',
'text',
'text',
'integer'],
122 [$this->container->user()->getId(), $file, $code, $test_id]
125 return (
bool) $this->container->database()->numRows($result);
130 $is_upload_question =
'EXISTS (SELECT 1 FROM qpl_qst_type INNER JOIN qpl_questions ON question_type_id = question_type_fi WHERE type_tag = %s AND tst_solutions.question_fi = qpl_questions.question_id)';
131 $is_in_test =
'EXISTS (SELECT 1 FROM tst_active WHERE test_fi = %s AND active_id = active_fi)';
133 $result = $this->container->database()->queryF(
134 "SELECT active_fi, value1 FROM tst_solutions WHERE $is_upload_question AND $is_in_test",
136 [
'assFileUpload', $test]
139 while (($row = $this->container->database()->fetchAssoc($result))) {
140 if ($row[
'value1'] === $file) {
141 return (
int) $row[
'active_fi'];
155 private function roleBasedCheck(
int $test_id, array $references,
string $file): bool
174 return $this->incident->any(fn (
int $reference):
bool => (
175 ($this->checkResultsAccess)($reference, $test_id, $active_id)
187 if (!preg_match(
':/assessment/tst_(\d+)/.*/([^/]+)$:',
$path,
$results)) {
Customizing of pimple-DIC for ILIAS.
A result encapsulates a value or an error and simplifies the handling of those.
A result encapsulates a value or an error and simplifies the handling of those.
accessCodeOk(string $file, int $test_id)
pathAndTestId(string $path)
canAccessResults(int $test_id, array $references, string $file)
__construct(Container $container, Readable $readable, $object_id_of_test_id=[ilObjTest::class, '_getObjectIDFromTestID'], $references_of=[ilObject::class, '_getAllReferences'], $session=[ilSession::class, 'get'], callable $checkResultsAccess=null, Incident $incident=null)
activeIdOfFile(string $file, int $test)
userDidUpload(int $test_id, string $file, string $code=null)
roleBasedCheck(int $test_id, array $references, string $file)
isPermitted(string $path)
Closure $checkResultsAccess
Closure $object_id_of_test_id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ACCESS_CODE_SESSION_INDEX
A result encapsulates a value or an error and simplifies the handling of those.