ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
QuestionsTableQuery.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Psr\Http\Message\ServerRequestInterface;
25use ILIAS\HTTP\Services as HTTPService;
28use ILIAS\Refinery\Factory as Refinery;
29use ILIAS\Data\Factory as DataFactory;
31
33{
34 protected ServerRequestInterface $request;
35 protected RequestWrapper $request_wrapper;
40
41 public function __construct(
42 HTTPService $http,
43 protected Refinery $refinery,
44 protected DataFactory $data_factory,
45 array $namespace
46 ) {
47 $this->request = $http->request();
48 $this->request_wrapper = $http->wrapper()->query();
49
50 list(
51 $this->url_builder,
52 $this->action_token,
53 $this->row_id_token,
54 $this->print_view_type_token
55 ) = $this->getUrlBuilder()->acquireParameters(
56 $namespace,
57 'action',
58 'ids',
59 'print_view_type'
60 );
61 }
62
63 private function getUrlBuilder(): URLBuilder
64 {
65 return new URLBuilder(
66 $this->data_factory->uri(
67 $this->request->getUri()->__toString()
68 )
69 );
70 }
71
72 public function getTableAction(): ?string
73 {
74 return $this->retrieveStringOrNull($this->action_token);
75 }
76
77 public function getRowIds(\ilObjTest $obj_test): ?array
78 {
79 if ($this->request_wrapper->retrieve(
80 $this->row_id_token->getName(),
81 $this->refinery->identity()
82 ) === ['ALL_OBJECTS']) {
83 return array_map(
84 fn($record) => $record['question_id'],
85 $obj_test->getTestQuestions()
86 );
87 }
88 return $this->request_wrapper->retrieve(
89 $this->row_id_token->getName(),
90 $this->refinery->kindlyTo()->listOf(
91 $this->refinery->byTrying([
92 $this->refinery->kindlyTo()->int(),
93 $this->refinery->always(null)
94 ])
95 )
96 );
97 }
98
99 public function getPrintViewType(): string
100 {
101 if (!$this->request_wrapper->has($this->print_view_type_token->getName())) {
102 return '';
103 }
104 return $this->request_wrapper->retrieve(
105 $this->print_view_type_token->getName(),
106 $this->refinery->kindlyTo()->string()
107 );
108 }
109
110 public function getActionURL(string $action): URI
111 {
112 return $this->url_builder->withParameter(
113 $this->action_token,
114 $action
115 )->buildURI();
116 }
117
118 public function getPrintViewTypeURL(
119 string $action,
120 string $type
121 ): URI {
122 return $this->url_builder->withParameter(
123 $this->action_token,
124 $action
125 )->withParameter(
126 $this->print_view_type_token,
127 $type
128 )->withParameter(
129 $this->row_id_token,
130 $this->request_wrapper->retrieve(
131 $this->row_id_token->getName(),
132 $this->refinery->identity()
133 )
134 )->buildURI();
135 }
136
137 public function getRowBoundURLBuilder(string $action): array
138 {
139 return [
140 $this->url_builder->withParameter($this->action_token, $action),
141 $this->row_id_token
142 ];
143 }
144
145 private function retrieveStringOrNull(URLBuilderToken $token): ?string
146 {
147 return $this->request_wrapper->retrieve(
148 $token->getName(),
149 $this->refinery->custom()->transformation(
150 function (?string $v): ?string {
151 if ($v === null) {
152 return null;
153 }
154 $tv = $this->refinery->kindlyTo()->string()->transform($v);
155 if ($tv === '') {
156 return null;
157 }
158 return $tv;
159 }
160 )
161 );
162 }
163}
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
withParameter(string $key, $value)
Get URI with modified parameters.
Definition: URI.php:388
Class Services.
Definition: Services.php:38
__construct(HTTPService $http, protected Refinery $refinery, protected DataFactory $data_factory, array $namespace)
$http
Definition: deliver.php:30
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($err=$client->getError()) $namespace
$token
Definition: xapitoken.php:70