ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
QuestionsTableQuery.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 use ILIAS\Data\URI;
31 
33 {
40 
41  public function __construct(
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),
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 }
if($err=$client->getError()) $namespace
getName()
Get the full name of the token including its namespace.
$http
Definition: deliver.php:30
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$token
Definition: xapitoken.php:70
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(HTTPService $http, protected Refinery $refinery, protected DataFactory $data_factory, array $namespace)
URLBuilder.
Definition: URLBuilder.php:40