19declare(strict_types=1);
29use Psr\Http\Message\ServerRequestInterface;
39 private readonly UIFactory $ui_factory,
53 return $this->test_access->checkManageParticipantsAccess();
65 ->withParameter($action_token, self::
ACTION_ID)
73 array $selected_participants,
74 bool $all_participants_selected
77 fn(?string $ip): bool => $ip === null
79 || filter_var($ip, FILTER_VALIDATE_IP) !== false,
80 $this->
lng->txt(
'invalid_ip')
82 $validate_order = $this->
refinery->custom()->constraint(
83 function (?array $vs):
bool {
84 if ($vs[
'from'] ===
'' && $vs[
'to'] ===
'') {
87 return $this->checkIpRangeValidity(
92 sprintf($this->
lng->txt(
'not_greater_than'), $this->lng->txt(
'max_ip_label'), $this->lng->txt(
'min_ip_label'))
94 $ip_range_group_trafo = $this->
refinery->custom()->transformation(
95 static function (?array $vs): array {
107 $participant_rows = array_map(
108 fn(Participant $participant) => sprintf(
110 $participant->getLastname(),
111 $participant->getFirstname()
113 $selected_participants
116 return $this->ui_factory->modal()->roundtrip(
117 $this->
lng->txt(
'client_ip_range'),
119 $this->ui_factory->messageBox()->info(
121 $this->resolveInfoMessage(
122 $selected_participants,
123 $all_participants_selected
127 $this->ui_factory->listing()->unordered($participant_rows)
130 'ip_range' => $this->ui_factory->input()->field()->group([
131 'from' => $this->ui_factory->input()->field()->text(
132 $this->lng->txt(
'min_ip_label')
133 )->withAdditionalTransformation($valid_ip_constraint),
134 'to' => $this->ui_factory->input()->field()->text(
135 $this->lng->txt(
'max_ip_label'),
136 $this->lng->txt(
'ip_range_byline')
137 )->withAdditionalTransformation($valid_ip_constraint),
139 $this->isUniqueClientIp($selected_participants)
141 'from' => $selected_participants[0]->getClientIpFrom() ??
'',
142 'to' => $selected_participants[0]->getClientIpTo() ??
''
149 ->withAdditionalTransformation($ip_range_group_trafo)
150 ->withAdditionalTransformation($validate_order)
152 $url_builder->
buildURI()->__toString()
153 )->withSubmitLabel($this->
lng->txt(
'change'));
158 ServerRequestInterface $request,
159 array $selected_participants,
160 bool $all_participants_selected
162 if (!$this->test_access->checkManageParticipantsAccess()) {
163 $this->tpl->setOnScreenMessage(
165 $this->
lng->txt(
'no_permission'),
171 $modal = $this->getModal(
173 $selected_participants,
174 $all_participants_selected
175 )->withRequest($request);
177 $data = $modal->getData();
178 if (
$data ===
null) {
179 return $modal->withOnLoad($modal->getShowSignal());
182 $this->participant_repository->updateIpRange(
184 static fn(Participant $v) => $v->withClientIpFrom(
$data[
'ip_range'][
'from'])
185 ->withClientIpTo(
$data[
'ip_range'][
'to']),
186 $selected_participants
190 $this->tpl->setOnScreenMessage(
192 $this->
lng->txt(
'ip_range_updated'),
207 array $selected_participants,
208 bool $all_participants_selected
210 if ($all_participants_selected) {
211 return 'ip_range_for_all_participants';
214 if (count($selected_participants) === 1) {
215 return 'ip_range_for_single_participant';
218 return 'ip_range_for_selected_participants';
223 return count($selected_participants) === 1
224 || count(array_unique(array_map(
226 $selected_participants
232 if (filter_var($start, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !==
false
233 && filter_var($end, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !==
false) {
234 return ip2long($start) <= ip2long($end);
237 if (filter_var($start, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !==
false
238 && filter_var($end, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !==
false) {
239 return bin2hex(inet_pton($start)) <= bin2hex(inet_pton($end));
Builds a Color from either hex- or rgb values.
getTableAction(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
allowActionForRecord(Participant $record)
resolveInfoMessage(array $selected_participants, bool $all_participants_selected)
getModal(URLBuilder $url_builder, array $selected_participants, bool $all_participants_selected)
isUniqueClientIp(array $selected_participants)
getSelectionErrorMessage()
checkIpRangeValidity(string $start, string $end)
onSubmit(URLBuilder $url_builder, ServerRequestInterface $request, array $selected_participants, bool $all_participants_selected)
__construct(private readonly Language $lng, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly Refinery $refinery, private readonly ParticipantRepository $participant_repository, private readonly \ilTestAccess $test_access,)
buildURI()
Get a URI representation of the full URL including query string and fragment/hash.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const MESSAGE_TYPE_SUCCESS
const MESSAGE_TYPE_FAILURE
This describes commonalities between the different modals.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))