ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.InternalRequestService.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\TestQuestionPool;
20 
22 
24 
26 {
27  use BaseGUIRequest;
28 
29  protected \ILIAS\HTTP\Services $http;
30  protected \ILIAS\FileUpload\FileUpload $upload;
31 
32  public function __construct(
33  \ILIAS\HTTP\Services $http,
35  \ILIAS\FileUpload\FileUpload $upload
36  ) {
37  $this->initRequest(
38  $http,
39  $refinery
40  );
41  $this->upload = $upload;
42  }
43 
47  public function getProcessedUploads(): array
48  {
49  $uploads = [];
50  if ($this->upload->hasUploads()) {
51  if (!$this->upload->hasBeenProcessed()) {
52  $this->upload->process();
53  }
54  $uploads = $this->upload->getResults();
55  }
56 
57  return $uploads;
58  }
59 
65  public function getUploadFilename(array $http_names, int $index): ?string
66  {
67  $uploaded_files = $this->http->request()->getUploadedFiles();
68 
69  while (($current_key = array_shift($http_names)) !== null) {
70  if (!isset($uploaded_files[$current_key])) {
71  return null;
72  }
73 
74  $uploaded_files = $uploaded_files[$current_key];
75 
76  if (isset($uploaded_files[$index]) && $http_names === []) {
78  $file = $uploaded_files[$index];
79  $c = \Closure::bind(static function (\GuzzleHttp\Psr7\UploadedFile $file): ?string {
80  return $file->file ?? null;
81  }, null, $file);
82 
83  return $c($file);
84  }
85  }
86 
87  return null;
88  }
89 
90  public function upload(): \ILIAS\FileUpload\FileUpload
91  {
92  return $this->upload;
93  }
94 
95  public function isset(string $key): bool
96  {
97  return $this->raw($key) !== null;
98  }
99  public function hasRefId(): int
100  {
101  return $this->raw('ref_id') !== null;
102  }
103 
104  public function getRefId(): int
105  {
106  return $this->int("ref_id");
107  }
108 
109  public function hasQuestionId(): bool
110  {
111  return $this->raw('q_id') !== null;
112  }
113 
114  public function getQuestionId(): int
115  {
116  return $this->int('q_id');
117  }
118 
120  public function getIds(): array
121  {
122  return $this->strArray("id");
123  }
124 
128  public function raw(string $key)
129  {
130  $no_transform = $this->refinery->identity();
131  return $this->get($key, $no_transform);
132  }
133 
134  public function float(string $key): ?float
135  {
136  $t = $this->refinery->kindlyTo()->float();
137  try {
138  return $this->get($key, $t) ?? 0.0;
139  } catch (ConstraintViolationException $e) {
140  return 0.0;
141  }
142  }
143 
144  public function string(string $key): string
145  {
146  $t = $this->refinery->kindlyTo()->string();
147  return $this->get($key, $t) ?? '';
148  }
149 
150  public function getParsedBody()
151  {
152  return $this->http->request()->getParsedBody();
153  }
154 
158  public function getUnitIds(): array
159  {
160  return $this->intArray("unit_ids");
161  }
162 
166  public function getUnitCategoryIds(): array
167  {
168  return $this->intArray("category_ids");
169  }
170 }
Class ChatMainBarProvider .
initRequest(HTTP\Services $http, Refinery\Factory $refinery, ?array $passed_query_params=null, ?array $passed_post_data=null)
Query params and post data parameters are used for testing.
static http()
Fetches the global http state from ILIAS.
__construct(\ILIAS\HTTP\Services $http, \ILIAS\Refinery\Factory $refinery, \ILIAS\FileUpload\FileUpload $upload)
string $key
Consumer key/client ID value.
Definition: System.php:193
trait BaseGUIRequest
Base gui request wrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Refinery Factory $refinery