ILIAS  release_8 Revision v8.23
class.ilChatUserActionProvider.php
Go to the documentation of this file.
1 <?php
2 
24 {
26  protected static array $user_access = array();
28  protected static array $accepts_messages_cache = array();
29  protected int $pub_ref_id = 0;
30  protected bool $chat_enabled = false;
31  protected bool $osc_enabled = false;
32 
33  public function __construct()
34  {
36 
37  $this->pub_ref_id = ilObjChatroom::_getPublicRefId();
38 
39  $chatSettings = new ilSetting('chatroom');
40  $this->chat_enabled = (bool) $chatSettings->get('chat_enabled');
41  $this->osc_enabled = (bool) $chatSettings->get('enable_osc');
42 
43  $this->lng->loadLanguageModule('chatroom');
44  }
45 
46  public function getComponentId(): string
47  {
48  return "chtr";
49  }
50 
54  public function getActionTypes(): array
55  {
56  return array(
57  "invite" => $this->lng->txt('chat_user_action_invite_public_room'),
58  "invite_osd" => $this->lng->txt('chat_user_action_invite_osd')
59  );
60  }
61 
62  protected function checkUserChatAccess(int $a_user_id): bool
63  {
64  if (!array_key_exists($a_user_id, self::$user_access)) {
65  self::$user_access[$a_user_id] = $GLOBALS['DIC']->rbac()->system()->checkAccessOfUser($a_user_id, 'read', $this->pub_ref_id);
66  }
67 
68  return self::$user_access[$a_user_id];
69  }
70 
71  protected function acceptsMessages(int $a_user_id): bool
72  {
73  if (!array_key_exists($a_user_id, self::$accepts_messages_cache)) {
74  self::$accepts_messages_cache[$a_user_id] = ilUtil::yn2tf(
75  ilObjUser::_lookupPref($a_user_id, 'chat_osc_accept_msg') ?? 'n'
76  );
77  }
78 
79  return (bool) self::$accepts_messages_cache[$a_user_id];
80  }
81 
85  public function collectActionsForTargetUser(int $a_target_user): ilUserActionCollection
86  {
88 
89  if (!$this->chat_enabled) {
90  return $coll;
91  }
92 
93  if ($this->checkUserChatAccess($this->getUserId()) && $a_target_user != $this->getUserId()) {
94  if ($this->checkUserChatAccess($a_target_user)) {
95  $f = new ilUserAction();
96  $f->setType("invite");
97  $f->setText($this->lng->txt('chat_invite_public_room'));
98  $f->setHref('./ilias.php?baseClass=ilRepositoryGUI&amp;ref_id=' . $this->pub_ref_id . '&amp;usr_id=' . $a_target_user . '&amp;cmd=view-invitePD');
99  $coll->addAction($f);
100  }
101  }
102 
103  if ($this->osc_enabled && $a_target_user != $this->getUserId()) {
104  $f = new ilUserAction();
105  $f->setHref('#');
106  $f->setType("invite_osd");
107  if ($this->acceptsMessages($a_target_user)) {
108  $f->setText($this->lng->txt('chat_osc_start_conversation'));
109  $f->setData(array(
110  'onscreenchat-userid' => $a_target_user,
111  'onscreenchat-username' => ilObjUser::_lookupLogin($a_target_user)
112  ));
113  } else {
114  $f->setText($this->lng->txt('chat_osc_doesnt_accept_msg'));
115  $f->setData(array(
116  'onscreenchat-inact-userid' => $a_target_user
117  ));
118  }
119  $coll->addAction($f);
120  }
121 
122  return $coll;
123  }
124 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
collectActionsForTargetUser(int $a_target_user)
Collect all actions.
static _lookupPref(int $a_usr_id, string $a_keyword)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
static yn2tf(string $a_yn)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupLogin(int $a_user_id)