19declare(strict_types=1);
40 private readonly \ILIAS\HTTP\GlobalHttpState
$http;
63 string $format_mail_class = ilFormatMail::class,
64 string $relations_table_class = RelationsTable::class
68 $this->tpl =
$DIC[
'tpl'];
69 $this->
ctrl = $DIC[
'ilCtrl'];
70 $this->
lng = $DIC[
'lng'];
71 $this->tabs_gui =
$DIC[
'ilTabs'];
72 $this->
help = $DIC[
'ilHelp'];
73 $this->
toolbar = $DIC[
'ilToolbar'];
74 $this->
user = $DIC[
'ilUser'];
75 $this->
error = $DIC[
'ilErr'];
76 $this->rbacsystem =
$DIC[
'rbacsystem'];
77 $this->
http = $DIC->http();
79 $this->ui_factory =
$DIC->ui()->factory();
80 $this->ui_renderer =
$DIC->ui()->renderer();
82 $this->
ctrl->saveParameter($this,
"mobj_id");
84 $this->umail =
new $format_mail_class($this->
user->getId());
85 $this->relations_table =
new $relations_table_class(
91 $this->
lng->loadLanguageModule(
'buddysystem');
110 $forward_class = $this->
ctrl->getNextClass($this) ??
'';
112 $this->umail->persistToStage($this->
user->getId(), [],
'',
'',
'',
'',
'',
false);
114 switch (strtolower($forward_class)) {
115 case strtolower(ilMailSearchCoursesGUI::class):
118 $this->
ctrl->setReturn($this,
"showContacts");
122 case strtolower(ilMailSearchGroupsGUI::class):
125 $this->
ctrl->setReturn($this,
"showContacts");
129 case strtolower(ilMailingListsGUI::class):
132 $this->
ctrl->setReturn($this,
"showContacts");
136 case strtolower(ilUsersGalleryGUI::class):
138 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
141 $this->tabs_gui->activateSubTab(
'buddy_view_gallery');
144 $this->tpl->printToStdout();
147 case strtolower(PublicProfileGUI::class):
149 $this->
http->wrapper()->query()->retrieve(
'user', $this->refinery->kindlyTo()->int())
151 $profile_gui->setBackUrl($this->
ctrl->getLinkTarget($this,
'showContacts'));
152 $this->
ctrl->forwardCommand($profile_gui);
153 $this->tpl->printToStdout();
159 if (!($cmd = $this->
ctrl->getCmd())) {
161 $cmd =
'showContacts';
163 $this->
ctrl->redirectByClass(ilMailSearchCoursesGUI::class);
176 $galleryCmdClasses = array_map(
'strtolower', [ilUsersGalleryGUI::class, self::class]);
177 if ($this->tabs_gui->hasTabs()) {
179 $this->tabs_gui->addSubTab(
181 $this->
lng->txt(
'my_contacts'),
182 $this->ctrl->getLinkTarget($this)
185 if (in_array(strtolower($this->
ctrl->getCmdClass() ??
''), $galleryCmdClasses,
true)) {
186 $mode_options = array_combine(
188 fn(
string $mode):
string => $this->
lng->txt($mode),
189 array_keys($this->view_mode_options)
192 function (
string $mode):
string {
193 $this->
ctrl->setParameter($this,
'contacts_view', $mode);
194 $url = $this->
ctrl->getFormAction($this,
'changeContactsView');
195 $this->
ctrl->setParameter($this,
'contacts_view',
null);
199 array_keys($this->view_mode_options)
203 $active_mode = strtolower($this->
ctrl->getCmdClass() ??
'') === strtolower(ilUsersGalleryGUI::class)
207 $sortViewControl = $this->ui_factory
209 ->mode($mode_options, $this->
lng->txt($active_mode))
210 ->withActive($this->
lng->txt($active_mode));
211 $this->
toolbar->addComponent($sortViewControl);
218 $this->tabs_gui->addSubTab(
219 'mail_my_mailing_lists',
220 $this->
lng->txt(
'mail_my_mailing_lists'),
221 $this->ctrl->getLinkTargetByClass(ilMailingListsGUI::class)
226 $this->tabs_gui->addSubTab(
228 $this->
lng->txt(
'mail_my_courses'),
229 $this->ctrl->getLinkTargetByClass(ilMailSearchCoursesGUI::class)
231 $this->tabs_gui->addSubTab(
233 $this->
lng->txt(
'mail_my_groups'),
234 $this->ctrl->getLinkTargetByClass(ilMailSearchGroupsGUI::class)
236 $this->has_sub_tabs =
true;
240 $this->
help->setScreenIdComponent(
'contacts');
243 $this->tabs_gui->addTab(
245 $this->
lng->txt(
'my_contacts'),
246 $this->ctrl->getLinkTarget($this)
249 if (in_array(strtolower($this->
ctrl->getCmdClass() ??
''), $galleryCmdClasses,
true)) {
250 $this->tabs_gui->addSubTab(
252 $this->
lng->txt(
'buddy_view_table'),
253 $this->ctrl->getLinkTarget($this)
255 $this->tabs_gui->addSubTab(
256 'buddy_view_gallery',
257 $this->
lng->txt(
'buddy_view_gallery'),
258 $this->ctrl->getLinkTargetByClass(ilUsersGalleryGUI::class)
266 $this->tabs_gui->addTab(
267 'mail_my_mailing_lists',
268 $this->
lng->txt(
'mail_my_mailing_lists'),
269 $this->ctrl->getLinkTargetByClass(ilMailingListsGUI::class)
274 $this->tabs_gui->addTab(
276 $this->
lng->txt(
'mail_my_courses'),
277 $this->ctrl->getLinkTargetByClass(ilMailSearchCoursesGUI::class)
279 $this->tabs_gui->addTab(
281 $this->
lng->txt(
'mail_my_groups'),
282 $this->ctrl->getLinkTargetByClass(ilMailSearchGroupsGUI::class)
289 if ($this->has_sub_tabs) {
290 $this->tabs_gui->activateSubTab($a_id);
292 $this->tabs_gui->activateTab($a_id);
302 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
305 $contacts_view = $this->
http->wrapper()->query()->retrieve(
308 $this->refinery->kindlyTo()->string(),
309 $this->refinery->always(self::CONTACTS_VIEW_TABLE)
313 switch ($contacts_view) {
315 $this->
ctrl->redirectByClass(ilUsersGalleryGUI::class);
320 $this->
ctrl->redirect($this);
327 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
330 $this->tabs_gui->activateSubTab(
'buddy_view_table');
335 $chat_allowed = (bool) (
new ilSetting(
'chatroom'))->
get(
'chat_enabled',
'0');
336 $mail_allowed = $this->rbacsystem->checkAccess(
341 $content = array_merge($content, $this->relations_table->build(array_merge(
342 $chat_allowed ? [
'chat' => $action(
'standard',
'invite_to_chat',
'inviteToChat')] : [],
343 $mail_allowed ? [
'mail' => $action(
'standard',
'send_mail',
'mailToUsers')] : [],
344 ), $this->
ctrl->getLinkTarget($this,
'showContacts'), $action));
346 $this->tpl->setContent($this->ui_renderer->render($content));
347 $this->tpl->printToStdout();
352 $get = $this->
http->wrapper()->query()->retrieve(...);
354 $user_ids = $get(
'contact_user_ids', $this->
refinery->byTrying([
355 $this->refinery->null(),
356 $this->refinery->kindlyTo()->listOf($this->refinery->byTrying([
357 $this->refinery->kindlyTo()->int(),
359 $this->refinery->custom()->transformation(
360 fn($s): array => is_array($s) && join(
'', $s) ===
'ALL_OBJECTS' ?
361 array_column(RelationsTable::data(),
'user_id') :
362 throw new Exception(
'Nope')
366 $action = $get(
'contact_action', $this->
refinery->kindlyTo()->string());
368 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'select_one'),
true);
369 $this->
ctrl->redirect($this);
372 if (in_array($action, [
'inviteToChat',
'mailToUsers'],
true)) {
373 $this->$action($user_ids);
388 'You cannot perform a state transition for a non existing user (id: %s)',
398 throw new ilException(
'The requested user does not want to get contact requests');
404 $this->tpl->setOnScreenMessage(
'failure', sprintf($this->
lng->txt($e->getMessage()), $login),
true);
405 }
catch (Exception) {
406 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'buddy_bs_action_not_possible'),
true);
409 $this->
ctrl->redirect($this,
'showContacts');
418 $this->
error->raiseError($this->
lng->txt(
'msg_no_perm_read'), $this->error->MESSAGE);
422 $mail_data = $this->umail->retrieveFromStage();
423 foreach ($usr_ids as $usr_id) {
425 if (!$this->umail->existsRecipient($login, (
string) $mail_data[
'rcp_to'])) {
429 $logins = array_filter($logins);
431 if ($logins !== []) {
432 $mail_data = $this->umail->appendSearchResult($logins,
'to');
433 $this->umail->persistToStage(
434 (
int) $mail_data[
'user_id'],
435 $mail_data[
'attachments'],
436 $mail_data[
'rcp_to'],
437 $mail_data[
'rcp_cc'],
438 $mail_data[
'rcp_bcc'],
439 $mail_data[
'm_subject'],
440 $mail_data[
'm_message'],
441 $mail_data[
'use_placeholders'],
442 $mail_data[
'tpl_ctx_id'],
443 $mail_data[
'tpl_ctx_params']
447 $this->
ctrl->redirectToURL(
'ilias.php?baseClass=ilMailGUI&type=search_res');
453 $usr_ids = $this->
http->wrapper()->post()->retrieve(
'usr_ids', $this->
refinery->in()->series([
454 $this->refinery->kindlyTo()->string(),
455 $this->refinery->custom()->transformation(fn(
string $s) => explode(
',', $s)),
456 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
457 $this->refinery->custom()->constraint(fn(array
$a) =>
$a !== [], fn() =>
'Empty array.'),
459 }
catch (Exception) {
460 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'select_one'),
true);
461 $this->
ctrl->redirect($this);
465 $room_id = $this->
http->wrapper()->post()->retrieve(
'room_id', $this->
refinery->kindlyTo()->int());
466 }
catch (Exception) {
467 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'select_one'));
477 $ref_id = $room->getRefIdByRoomId($room_id);
479 foreach ($usr_ids as $usr_id) {
482 $no_login[] = $usr_id;
485 $room->isUserBanned($usr_id)
487 $no_access[] = $login;
489 $valid_users[] = $usr_id;
494 $this->
asErrorMessage($no_access, $this->
lng->txt(
'chat_users_without_permission')),
495 $this->asErrorMessage($no_login, $this->lng->txt(
'chat_users_without_login')),
499 $this->tpl->setOnScreenMessage(
'failure',
$message);
504 foreach ($valid_users as
$id) {
505 $room->sendInvitationNotification(
507 $this->
user->getId(),
513 $this->
ctrl->setParameter($this,
'inv_room_ref_id',
$ref_id);
514 $this->
ctrl->setParameter($this,
'inv_usr_ids', implode(
',', $valid_users));
516 $this->
ctrl->redirect($this);
524 $this->tabs_gui->activateSubTab(
'buddy_view_table');
527 $this->
lng->loadLanguageModule(
'chatroom');
529 $chat_rooms = (
new ilChatroom())->getAccessibleRoomIdByTitleMap($this->
user->getId());
531 $options = array_filter(
539 $this->tpl->setTitle($this->
lng->txt(
'mail_invite_users_to_chat'));
540 $this->tpl->setContent($this->
inviteToChatForm($options, $usr_ids)->getHTML());
541 $this->tpl->printToStdout();
554 fn($s) =>
'<li>' . htmlspecialchars((
string) $s) .
'</li>',
572 $form->setTitle($this->
lng->txt(
'mail_invite_users_to_chat'));
573 $form->addCommandButton(
'submitInvitation', $this->
lng->txt(
'submit'));
574 $form->addCommandButton(
'showContacts', $this->
lng->txt(
'cancel'));
575 $form->setFormAction($this->
ctrl->getFormAction($this,
'showContacts'));
578 $sel->setOptions($options);
579 $form->addItem($sel);
582 $hidden->setValue(implode(
',', $usr_ids));
583 $form->addItem($hidden);
593 $has = $this->
http->wrapper()->query()->has(...);
594 if (!$has(
'inv_room_ref_id') || !$has(
'inv_usr_ids')) {
598 $inv_room_ref_id = $this->
http->wrapper()->query()->retrieve(
602 $inv_usr_ids = $this->
http->wrapper()->query()->retrieve(
605 $this->refinery->kindlyTo()->string(),
606 $this->refinery->custom()->transformation(fn(
string $s): array => explode(
',', $s)),
607 $this->
refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
608 $this->refinery->custom()->constraint(fn(array
$a):
bool =>
$a !== [], fn():
string =>
'Empty array.'),
617 $this->ui_factory->messageBox()->success(
618 $this->
lng->txt(
'chat_users_have_been_invited') . $this->ui_renderer->render(
619 $this->ui_factory->listing()->unordered($userlist)
622 $this->ui_factory->button()->standard($this->lng->txt(
'goto_invitation_chat'),
$url)
632 $url =
new URLBuilder(
new URI(rtrim(ILIAS_HTTP_PATH,
'/') .
'/' . $this->
ctrl->getLinkTarget($this,
'updateState')));
633 [
$url, $p,
$token] =
$url->acquireParameters([
'contact'],
'action',
'user_ids');
635 return fn(
string $type,
string $lang_var,
string $param):
Action => $this->ui_factory->table()->action()->$type(
636 $this->
lng->txt($lang_var),
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
The scope of this class is split ilias-conform URI's into components.
GUI class for public user profile presentation.
static getInstanceByGlobalUser(?ilObjUser $user=null)
Class ilBuddySystemException.
Class ilBuddySystemRelationStateAlreadyGivenException.
Class ilBuddySystemRelationStateTransitionException.
static checkPermissionsOfUser(int $usr_id, $permissions, int $ref_id)
Checks user permissions in question for a given user id in relation to a given ref_id.
static byRoomId(int $room_id, bool $initObject=false)
Error Handling & global info handling.
Base class for ILIAS Exception handling.
static _getStaticLink(?int $a_ref_id, string $a_type='', bool $a_fallback_goto=true, string $append="")
static getMailObjectRefId()
static _isAnonymous(int $usr_id)
static _lookupPref(int $a_usr_id, string $a_keyword)
static _lookupLogin(int $a_user_id)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@ilCtrl_Calls ilUsersGalleryGUI: ILIAS\User\Profile\PublicProfileGUI @ilCtrl_isCalledBy ilUsersGaller...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static yn2tf(string $a_yn)
A component is the most general form of an entity in the UI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples