ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ConsecutiveScoringURLs.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\Refinery\Factory as Refinery;
29
31{
39
40 public function __construct(
41 private URLBuilder $url_builder,
42 array $namespace,
43 private readonly Refinery $refinery,
44 private readonly RequestWrapper $request_wrapper,
45 private readonly \ilCtrl $ctrl,
46 ) {
47 [
48 $this->url_builder,
54 ] = $this->url_builder->acquireParameters(
56 'action',
57 'question',
58 'user',
59 'attempt',
60 'force',
61 );
62 }
63
64 private function retrieveString(URLBuilderToken $token): ?string
65 {
66 return $this->request_wrapper->retrieve(
67 $token->getName(),
68 $this->refinery->byTrying([
69 $this->refinery->kindlyTo()->string(),
70 $this->refinery->always(null)
71 ])
72 );
73 }
75 {
76 return $this->request_wrapper->retrieve(
77 $token->getName(),
78 $this->refinery->byTrying([
79 $this->refinery->kindlyTo()->int(),
80 $this->refinery->always(null)
81 ])
82 );
83 }
84
85 public function buildURI(): URI
86 {
87 return $this->url_builder->buildURI();
88 }
89
90 public function getAction(): ?string
91 {
92 return $this->retrieveString($this->action_token);
93 }
94
95 public function withAction(string $act): self
96 {
97 $clone = clone $this;
98 $clone->url_builder = $clone->url_builder
99 ->withParameter($clone->action_token, $act);
100 return $clone;
101 }
102
103 public function withFragment(string $fragment): self
104 {
105 $clone = clone $this;
106 $clone->url_builder = $clone->url_builder
107 ->withFragment($fragment);
108 return $clone;
109 }
110
111 public function withForceRedirect(): self
112 {
113 $clone = clone $this;
114 $clone->url_builder = $clone->url_builder
115 ->withParameter($clone->force_redirect_token, (string) time());
116 return $clone;
117 }
118
119 public function getIdParameters(): array
120 {
121 return [
122 $this->retrieveInt($this->question_token),
123 $this->retrieveInt($this->user_token),
124 $this->retrieveInt($this->attempt_token)
125 ];
126 }
127
128 public function withIdParameters(int $qid, int $uid, int $attempt): self
129 {
130 $clone = clone $this;
131 $clone->url_builder = $clone->url_builder
132 ->withParameter($clone->question_token, (string) $qid)
133 ->withParameter($clone->user_token, (string) $uid)
134 ->withParameter($clone->attempt_token, (string) $attempt);
135 return $clone;
136 }
137
138 public function withUserId(int $uid): self
139 {
140 $clone = clone $this;
141 $clone->url_builder = $clone->url_builder
142 ->withParameter($clone->user_token, (string) $uid);
143 return $clone;
144 }
145
146 public function getUserId(): int
147 {
148 return $this->retrieveInt($this->user_token);
149 }
150
151 public function redirect(): void
152 {
153 $this->ctrl->redirectToURL(
154 $this->url_builder->buildURI()->__toString()
155 );
156 }
157}
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct(private URLBuilder $url_builder, array $namespace, private readonly Refinery $refinery, private readonly RequestWrapper $request_wrapper, private readonly \ilCtrl $ctrl,)
Class ilCtrl provides processing control methods.
if($err=$client->getError()) $namespace
A transformation is a function from one datatype to another.
$token
Definition: xapitoken.php:67