ILIAS  release_8 Revision v8.24
AccessQuestionImage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Modules\Test;
22
26
28{
30
32 {
33 $this->readable = $readable;
34 }
35
36 public function isPermitted(string $path): Result
37 {
38 $object_id = $this->objectId($path);
39 if (!$object_id) {
40 return new Error('Not a question image path of test questions.');
41 }
42
43 return new Ok($this->readable->objectId($object_id));
44 }
45
46 private function objectId(string $path): ?int
47 {
48 $results = [];
49 if (!preg_match(':/assessment/(\d+)/(\d+)/images/([^/]+)$:', $path, $results)) {
50 return null;
51 }
52
53 return (int) $results[1];
54 }
55}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Error.php:18
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:17
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:15
$path
Definition: ltiservices.php:32
$results