ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ILIAS\Test\Participants\ParticipantTableIpRangeAction Class Reference
+ Inheritance diagram for ILIAS\Test\Participants\ParticipantTableIpRangeAction:
+ Collaboration diagram for ILIAS\Test\Participants\ParticipantTableIpRangeAction:

Public Member Functions

 __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,)
 
 getActionId ()
 
 isAvailable ()
 
 getTableAction (URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
 
 getModal (URLBuilder $url_builder, array $selected_participants, bool $all_participants_selected)
 
 onSubmit (URLBuilder $url_builder, ServerRequestInterface $request, array $selected_participants, bool $all_participants_selected)
 
 allowActionForRecord (Participant $record)
 
 getSelectionErrorMessage ()
 

Data Fields

const ACTION_ID = 'client_ip_range'
 

Private Member Functions

 resolveInfoMessage (array $selected_participants, bool $all_participants_selected)
 
 isUniqueClientIp (array $selected_participants)
 
 checkIpRangeValidity (string $start, string $end)
 

Detailed Description

Definition at line 32 of file ParticipantTableIpRangeAction.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::__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 
)

Definition at line 36 of file ParticipantTableIpRangeAction.php.

43  {
44  }

Member Function Documentation

◆ allowActionForRecord()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::allowActionForRecord ( Participant  $record)

Implements ILIAS\Test\Participants\TableAction.

Definition at line 198 of file ParticipantTableIpRangeAction.php.

References ILIAS\Test\Participants\Participant\isInvitedParticipant().

198  : bool
199  {
200  return $record->isInvitedParticipant();
201  }
+ Here is the call graph for this function:

◆ checkIpRangeValidity()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::checkIpRangeValidity ( string  $start,
string  $end 
)
private

Definition at line 230 of file ParticipantTableIpRangeAction.php.

Referenced by ILIAS\Test\Participants\ParticipantTableIpRangeAction\getModal().

230  : bool
231  {
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);
235  }
236 
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));
240  }
241  return false;
242  }
+ Here is the caller graph for this function:

◆ getActionId()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::getActionId ( )

Implements ILIAS\Test\Participants\TableAction.

Definition at line 46 of file ParticipantTableIpRangeAction.php.

46  : string
47  {
48  return self::ACTION_ID;
49  }

◆ getModal()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::getModal ( URLBuilder  $url_builder,
array  $selected_participants,
bool  $all_participants_selected 
)
Parameters
array<Participant>$selected_participants

Implements ILIAS\Test\Participants\TableAction.

Definition at line 71 of file ParticipantTableIpRangeAction.php.

References ILIAS\UI\URLBuilder\buildURI(), ILIAS\Test\Participants\ParticipantTableIpRangeAction\checkIpRangeValidity(), ILIAS\Test\Participants\Participant\getFirstname(), ILIAS\Test\Participants\Participant\getLastname(), ILIAS\Test\Participants\ParticipantTableIpRangeAction\isUniqueClientIp(), ILIAS\Repository\lng(), null, ILIAS\Repository\refinery(), ILIAS\UI\Implementation\Component\Input\ViewControl\withAdditionalTransformation(), and ILIAS\UI\Implementation\Component\Input\withValue().

Referenced by ILIAS\Test\Participants\ParticipantTableIpRangeAction\onSubmit().

75  : ?Modal {
76  $valid_ip_constraint = $this->refinery->custom()->constraint(
77  fn(?string $ip): bool => $ip === null
78  || $ip === ''
79  || filter_var($ip, FILTER_VALIDATE_IP) !== false,
80  $this->lng->txt('invalid_ip')
81  );
82  $validate_order = $this->refinery->custom()->constraint(
83  function (?array $vs): bool {
84  if ($vs['from'] === '' && $vs['to'] === '') {
85  return true;
86  }
87  return $this->checkIpRangeValidity(
88  $vs['from'],
89  $vs['to']
90  );
91  },
92  sprintf($this->lng->txt('not_greater_than'), $this->lng->txt('max_ip_label'), $this->lng->txt('min_ip_label'))
93  );
94  $ip_range_group_trafo = $this->refinery->custom()->transformation(
95  static function (?array $vs): array {
96  if ($vs === null) {
97  $vs = [
98  'from' => null,
99  'to' => null
100  ];
101  }
102  return $vs;
103  }
104  );
105 
106 
107  $participant_rows = array_map(
108  fn(Participant $participant) => sprintf(
109  '%s, %s',
110  $participant->getLastname(),
111  $participant->getFirstname()
112  ),
113  $selected_participants
114  );
115 
116  return $this->ui_factory->modal()->roundtrip(
117  $this->lng->txt('client_ip_range'),
118  [
119  $this->ui_factory->messageBox()->info(
120  $this->lng->txt(
121  $this->resolveInfoMessage(
122  $selected_participants,
123  $all_participants_selected
124  )
125  )
126  ),
127  $this->ui_factory->listing()->unordered($participant_rows)
128  ],
129  [
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),
138  ])->withValue(
139  $this->isUniqueClientIp($selected_participants)
140  ? [
141  'from' => $selected_participants[0]->getClientIpFrom() ?? '',
142  'to' => $selected_participants[0]->getClientIpTo() ?? ''
143  ]
144  : [
145  'from' => '',
146  'to' => ''
147  ]
148  )
149  ->withAdditionalTransformation($ip_range_group_trafo)
150  ->withAdditionalTransformation($validate_order)
151  ],
152  $url_builder->buildURI()->__toString()
153  )->withSubmitLabel($this->lng->txt('change'));
154  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSelectionErrorMessage()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::getSelectionErrorMessage ( )

Implements ILIAS\Test\Participants\TableAction.

Definition at line 244 of file ParticipantTableIpRangeAction.php.

References null.

244  : ?string
245  {
246  return null;
247  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getTableAction()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::getTableAction ( URLBuilder  $url_builder,
URLBuilderToken  $row_id_token,
URLBuilderToken  $action_token,
URLBuilderToken  $action_type_token 
)

Implements ILIAS\Test\Participants\TableAction.

Definition at line 56 of file ParticipantTableIpRangeAction.php.

References ILIAS\Repository\lng(), ILIAS\Test\Participants\ParticipantTableActions\SHOW_ACTION, and ILIAS\UI\URLBuilder\withParameter().

61  : Action {
62  return $this->ui_factory->table()->action()->standard(
63  $this->lng->txt(self::ACTION_ID),
64  $url_builder
65  ->withParameter($action_token, self::ACTION_ID)
66  ->withParameter($action_type_token, ParticipantTableActions::SHOW_ACTION),
67  $row_id_token
68  )->withAsync();
69  }
+ Here is the call graph for this function:

◆ isAvailable()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::isAvailable ( )

Implements ILIAS\Test\Participants\TableAction.

Definition at line 51 of file ParticipantTableIpRangeAction.php.

51  : bool
52  {
53  return $this->test_access->checkManageParticipantsAccess();
54  }

◆ isUniqueClientIp()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::isUniqueClientIp ( array  $selected_participants)
private

Definition at line 221 of file ParticipantTableIpRangeAction.php.

References ILIAS\Test\Participants\Participant\getClientIpFrom(), and ILIAS\Test\Participants\Participant\getClientIpTo().

Referenced by ILIAS\Test\Participants\ParticipantTableIpRangeAction\getModal().

221  : bool
222  {
223  return count($selected_participants) === 1
224  || count(array_unique(array_map(
225  fn(Participant $participant) => $participant->getClientIpFrom() . '-' . $participant->getClientIpTo(),
226  $selected_participants
227  ))) === 1;
228  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ onSubmit()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::onSubmit ( URLBuilder  $url_builder,
ServerRequestInterface  $request,
array  $selected_participants,
bool  $all_participants_selected 
)
Parameters
array<Participant>$selected_participants

Implements ILIAS\Test\Participants\TableAction.

Definition at line 156 of file ParticipantTableIpRangeAction.php.

References $data, ILIAS\Test\Participants\ParticipantTableIpRangeAction\getModal(), ILIAS\Repository\lng(), ILIAS\UICore\GlobalTemplate\MESSAGE_TYPE_FAILURE, ILIAS\UICore\GlobalTemplate\MESSAGE_TYPE_SUCCESS, null, and ILIAS\Test\Participants\Participant\withClientIpFrom().

161  : ?Modal {
162  if (!$this->test_access->checkManageParticipantsAccess()) {
163  $this->tpl->setOnScreenMessage(
165  $this->lng->txt('no_permission'),
166  true
167  );
168  return null;
169  }
170 
171  $modal = $this->getModal(
172  $url_builder,
173  $selected_participants,
174  $all_participants_selected
175  )->withRequest($request);
176 
177  $data = $modal->getData();
178  if ($data === null) {
179  return $modal->withOnLoad($modal->getShowSignal());
180  }
181 
182  $this->participant_repository->updateIpRange(
183  array_map(
184  static fn(Participant $v) => $v->withClientIpFrom($data['ip_range']['from'])
185  ->withClientIpTo($data['ip_range']['to']),
186  $selected_participants
187  )
188  );
189 
190  $this->tpl->setOnScreenMessage(
192  $this->lng->txt('ip_range_updated'),
193  true
194  );
195  return null;
196  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getModal(URLBuilder $url_builder, array $selected_participants, bool $all_participants_selected)
+ Here is the call graph for this function:

◆ resolveInfoMessage()

ILIAS\Test\Participants\ParticipantTableIpRangeAction::resolveInfoMessage ( array  $selected_participants,
bool  $all_participants_selected 
)
private
Parameters
array$selected_participants

Definition at line 206 of file ParticipantTableIpRangeAction.php.

209  : string {
210  if ($all_participants_selected) {
211  return 'ip_range_for_all_participants';
212  }
213 
214  if (count($selected_participants) === 1) {
215  return 'ip_range_for_single_participant';
216  }
217 
218  return 'ip_range_for_selected_participants';
219  }

Field Documentation

◆ ACTION_ID

const ILIAS\Test\Participants\ParticipantTableIpRangeAction::ACTION_ID = 'client_ip_range'

Definition at line 34 of file ParticipantTableIpRangeAction.php.


The documentation for this class was generated from the following file: