19 declare(strict_types=1);
65 $session = [ilSession::class,
'get'],
74 $this->session = Closure::fromCallable(
$session);
75 $this->checkResultsAccess =
$checkResultsAccess ??
static function (
int $reference,
int $test_id,
int $active_id):
bool {
77 return $access->checkResultsAccessForActiveId($active_id);
85 if (!$path_and_test) {
86 return new Error(
'Not a file upload path of test answers.');
88 if (!$path_and_test[
'test']) {
92 $object_id = (int) ($this->object_id_of_test_id)($path_and_test[
'test']);
97 $references = array_map(
'intval', ($this->references_of)($object_id));
99 return new Ok($this->readable->references($references) && $this->
roleBasedCheck($path_and_test[
'test'], $references, $path_and_test[
'path']));
104 return $this->container->user()->isAnonymous() || !$this->container->user()->getId();
111 return $code && $this->
userDidUpload($test_id, $file, $code);
114 private function userDidUpload(
int $test_id,
string $file,
string $code = null) : bool
117 'active_id = active_fi',
120 'anonymous_id ' . (null === $code ?
'IS' :
'=') .
' %s',
124 $result = $this->container->database()->queryF(
125 'SELECT 1 FROM tst_solutions WHERE EXISTS (SELECT 1 FROM tst_active WHERE ' . implode(
' AND ', $where) .
')',
126 [
'integer',
'text',
'text',
'integer'],
127 [$this->container->user()->getId(), $file, $code, $test_id]
130 return (
bool) $this->container->database()->numRows(
$result);
135 $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)';
136 $is_in_test =
'EXISTS (SELECT 1 FROM tst_active WHERE test_fi = %s AND active_id = active_fi)';
138 $result = $this->container->database()->queryF(
139 "SELECT active_fi, value1 FROM tst_solutions WHERE $is_upload_question AND $is_in_test",
141 [
'assFileUpload', $test]
144 while (($row = $this->container->database()->fetchAssoc(
$result))) {
145 if ($row[
'value1'] === $file) {
146 return (
int) $row[
'active_fi'];
160 private function roleBasedCheck(
int $test_id, array $references,
string $file) : bool
179 return $this->incident->any(
function (
int $reference) use ($test_id, $active_id):
bool {
180 return ($this->checkResultsAccess)($reference, $test_id, $active_id);
192 if (!preg_match(
':/assessment/tst_(\d+)/.*/([^/]+)$:', $path,
$results)) {
__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)
accessCodeOk(string $file, int $test_id)
A result encapsulates a value or an error and simplifies the handling of those.
Customizing of pimple-DIC for ILIAS.
canAccessResults(int $test_id, array $references, string $file)
const ACCESS_CODE_SESSION_INDEX
A result encapsulates a value or an error and simplifies the handling of those.
pathAndTestId(string $path)
isPermitted(string $path)
A result encapsulates a value or an error and simplifies the handling of those.
roleBasedCheck(int $test_id, array $references, string $file)
activeIdOfFile(string $file, int $test)
userDidUpload(int $test_id, string $file, string $code=null)