ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
BookingTableGUI.php
Go to the documentation of this file.
1 <?php
18 declare(strict_types=1);
19 
21 
26 use Generator;
32 use ilLanguage;
33 use ilObjUser;
34 use ilCtrl;
37 
39 {
40  public const ACTION_TOKEN = 'action';
41  public const ID_TOKEN = 'id';
42  public const TABLE_NS = 'ch_booking_table';
43 
44  public const ACTION_TOKEN_NS = self::TABLE_NS . '_' . self::ACTION_TOKEN;
45 
46  public const ID_TOKEN_NS = self::TABLE_NS . '_' . self::ID_TOKEN;
47 
48 
50 
51  protected readonly ilLanguage $lng;
52  protected readonly ilObjUser $user;
53  protected readonly ilCtrl $ctrl;
54  protected readonly UIFactory $ui_factory;
55  protected readonly DataFactory $data_factory;
58 
59 
60  public function __construct(BookingDataProvider $provider)
61  {
62  global $DIC;
63 
64  $this->provider = $provider;
65 
66  $this->lng = $DIC->language();
67  $this->user = $DIC->user();
68  $this->ctrl = $DIC->ctrl();
69 
70  $this->http_request = $DIC->http()->request();
71  $this->ui_factory = $DIC->ui()->factory();
72  $this->data_factory = new DataFactory();
73  $this->ui_renderer = $DIC->ui()->renderer();
74  }
75 
76  public function getRows(
77  DataRowBuilder $row_builder,
78  array $visible_column_ids,
79  Range $range,
80  Order $order,
81  ?array $filter_data,
82  ?array $additional_parameters
83  ): Generator {
84  $records = $this->provider->limitData($range, $order);
85  foreach ($records as $row) {
86  $id = $row['id'];
87  $records_row = $row_builder->buildDataRow($id, $row);
88  if (count($row['booking_participant']->getItems()) === 0) {
89  $records_row = $records_row
90  ->withDisabledAction('confirmCancelBooking')
91  ->withDisabledAction('confirmDeleteBooking')
92  ->withDisabledAction('sendMail');
93  }
94  yield $records_row;
95  }
96  }
97 
98  public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
99  {
100  return count($this->provider->getData());
101  }
102 
103  public function get(): Data
104  {
105  return $this->ui_factory
106  ->table()
107  ->data(
108  $this->lng->txt('cal_ch_ch'),
109  $this->getColumns(),
110  $this
111  )
112  ->withId(self::class)
113  ->withActions($this->getActions())
114  ->withRequest($this->http_request);
115  }
116 
117 
121  protected function getActions(): array
122  {
123  $uri_command_handler = $this->data_factory->uri(
124  ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
125  ilConsultationHoursGUI::class,
126  'handleBookingTableActions'
127  )
128  );
129 
130  [
131  $url_builder,
132  $action_parameter_token,
133  $row_id_token
134  ] =
135  (new URLBuilder($uri_command_handler))->acquireParameters(
136  [self::TABLE_NS],
137  self::ACTION_TOKEN,
138  self::ID_TOKEN
139  );
140 
141  return [
142  'edit' => $this->ui_factory->table()->action()->standard(
143  $this->lng->txt('edit'),
144  $url_builder->withParameter($action_parameter_token, 'edit'),
145  $row_id_token
146  ),
147  'searchUsersForAppointments' => $this->ui_factory->table()->action()->standard(
148  $this->lng->txt('cal_ch_assign_participants'),
149  $url_builder->withParameter($action_parameter_token, 'searchUsersForAppointments'),
150  $row_id_token
151  ),
152  'confirmCancelBooking' => $this->ui_factory->table()->action()->single(
153  $this->lng->txt('cal_ch_cancel_booking'),
154  $url_builder->withParameter($action_parameter_token, 'confirmCancelBooking'),
155  $row_id_token
156  )->withAsync(true),
157  'confirmDeleteBooking' => $this->ui_factory->table()->action()->single(
158  $this->lng->txt('cal_ch_delete_booking'),
159  $url_builder->withParameter($action_parameter_token, 'confirmDeleteBooking'),
160  $row_id_token
161  )->withAsync(true),
162  'confirmDeleteAppointments' => $this->ui_factory->table()->action()->standard(
163  $this->lng->txt('delete'),
164  $url_builder->withParameter($action_parameter_token, 'confirmDeleteAppointments'),
165  $row_id_token
166  )->withAsync(true),
167  'sendMail' => $this->ui_factory->table()->action()->standard(
168  $this->lng->txt('cal_ch_send_mail'),
169  $url_builder->withParameter($action_parameter_token, 'sendMail'),
170  $row_id_token
171  )
172  ];
173  }
174 
178  protected function getColumns(): array
179  {
180  if ($this->user->getTimeFormat() === \ilCalendarSettings::TIME_FORMAT_12) {
181  $format = $this->data_factory->dateFormat()->withTime12($this->user->getDateFormat());
182  } else {
183  $format = $this->data_factory->dateFormat()->withTime24($this->user->getDateFormat());
184  }
185 
186  return [
187  'booking_start' => $this->ui_factory
188  ->table()
189  ->column()
190  ->date($this->lng->txt('cal_ch_booking_start'), $format)
191  ->withIsSortable(true),
192  'booking_duration' => $this->ui_factory
193  ->table()
194  ->column()
195  ->number($this->lng->txt('cal_ch_minutes'))
196  ->withIsSortable(true),
197  'booking_title' => $this->ui_factory
198  ->table()
199  ->column()
200  ->text($this->lng->txt('title'))
201  ->withIsSortable(true),
202  'booking_participant' => $this->ui_factory
203  ->table()
204  ->column()
205  ->linkListing($this->lng->txt('cal_ch_booking_participants')),
206  'booking_comment' => $this->ui_factory
207  ->table()
208  ->column()
209  ->linkListing($this->lng->txt('cal_ch_booking_col_comments')),
210  'booking_location' => $this->ui_factory
211  ->table()
212  ->column()
213  ->linkListing($this->lng->txt('cal_ch_target_object'))
214  ];
215 
216  }
217 
218  public function render(): string
219  {
220  return $this->ui_renderer->render(
221  [
222  $this->get()
223  ]
224  );
225  }
226 
227 }
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
buildDataRow(string $id, array $record)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
URLBuilder.
Definition: URLBuilder.php:39
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28
readonly ServerRequestInterface $http_request