ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilOnScreenChatMenuGUI.php
Go to the documentation of this file.
1 <?php
2 
10 {
14  protected $pub_ref_id;
15 
19  protected $accessible = false;
20 
24  protected $publicChatRoomAccess = false;
25 
29  protected $oscAccess = false;
30 
34  protected $ui;
35 
39  public function __construct()
40  {
41  global $DIC;
42 
43  $this->init();
44  $this->ui = $DIC->ui();
45  }
46 
50  protected function init()
51  {
52  global $DIC;
53 
54  require_once 'Modules/Chatroom/classes/class.ilObjChatroom.php';
55  $this->pub_ref_id = ilObjChatroom::_getPublicRefId();
56 
57  if (!$DIC->user() || $DIC->user()->isAnonymous()) {
58  $this->accessible = false;
59  return;
60  }
61 
62  $chatSettings = new ilSetting('chatroom');
63 
64  $this->publicChatRoomAccess = $DIC->rbac()->system()->checkAccessOfUser($DIC->user()->getId(), 'read', $this->pub_ref_id);
65  $this->oscAccess = $chatSettings->get('enable_osc');
66 
67  $this->accessible = $chatSettings->get('chat_enabled') && ($this->oscAccess || $this->publicChatRoomAccess);
68  }
69 
73  public function getMainMenuHTML()
74  {
75  global $DIC;
76 
77  if (!$this->accessible) {
78  return '';
79  }
80 
81  require_once 'Services/Link/classes/class.ilLinkifyUtil.php';
83 
84  require_once 'Services/JSON/classes/class.ilJsonUtil.php';
85  $DIC->language()->loadLanguageModule('chatroom');
86 
87  $config = array(
88  'conversationTemplate' => (new ilTemplate('tpl.chat-menu-item.html', false, false, 'Services/OnScreenChat'))->get(),
89  'roomTemplate' => (new ilTemplate('tpl.chat-menu-item-room.html', false, false, 'Services/OnScreenChat'))->get(),
90  'infoTemplate' => (new ilTemplate('tpl.chat-menu-item-info.html', false, false, 'Services/OnScreenChat'))->get(),
91  'userId' => $DIC->user()->getId()
92  );
93 
94  $config['rooms'] = array();
95 
96  if ($this->publicChatRoomAccess) {
97  $config['rooms'][] = array(
98  'name' => $DIC['ilObjDataCache']->lookupTitle($DIC['ilObjDataCache']->lookupObjId($this->pub_ref_id)),
99  'url' => './ilias.php?baseClass=ilRepositoryGUI&amp;cmd=view&amp;ref_id=' . $this->pub_ref_id,
100  'icon' => ilObject::_getIcon($DIC['ilObjDataCache']->lookupObjId($this->pub_ref_id), 'small', 'chtr')
101  );
102  }
103 
104  $config['showAcceptMessageChange'] = (
105  !ilUtil::yn2tf($DIC->user()->getPref('chat_osc_accept_msg')) &&
106  !(bool) $DIC['ilSetting']->get('usr_settings_hide_chat_osc_accept_msg', false) &&
107  !(bool) $DIC['ilSetting']->get('usr_settings_disable_chat_osc_accept_msg', false)
108  );
109  $config['showOnScreenChat'] = $this->oscAccess;
110 
111  $DIC->language()->loadLanguageModule('chatroom');
112  $DIC->language()->toJS(array(
113  'chat_osc_conversations', 'chat_osc_section_head_other_rooms',
114  'chat_osc_sure_to_leave_grp_conv', 'chat_osc_user_left_grp_conv',
115  'confirm', 'cancel', 'chat_osc_leave_grp_conv', 'chat_osc_no_conv'
116  ));
117  $DIC->language()->toJSMap(array(
118  'chat_osc_dont_accept_msg' => sprintf(
119  $DIC->language()->txt('chat_osc_dont_accept_msg'),
120  $DIC->ctrl()->getLinkTargetByClass(array('ilPersonalDesktopGUI', 'ilPersonalSettingsGUI', 'ilPersonalChatSettingsFormGUI'), 'showChatOptions')
121  )
122  ));
123 
124  $DIC['tpl']->addJavascript('./Services/OnScreenChat/js/onscreenchat-menu.js');
125  $DIC['tpl']->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
126 
127  $tpl = new ilTemplate('tpl.chat-menu.html', true, true, 'Services/OnScreenChat');
128 
129  $f = $this->ui->factory();
130  $renderer = $this->ui->renderer();
131 
132  $glyph = $f->glyph()->comment();
133  $glyph = $glyph->withCounter($f->counter()->status(0))->withCounter($f->counter()->novelty(0))->withOnLoadCode(function ($id) use (&$glyph_id) {
134  $glyph_id = $id;
135  return '';
136  });
137  $glyph_html = $renderer->render($glyph);
138 
139  $config['triggerId'] = $glyph_id;
140  $config['conversationNoveltyCounter'] = $renderer->render($f->counter()->novelty(0));
141 
142  $DIC['tpl']->addOnLoadCode("il.OnScreenChatMenu.setConfig(" . ilJsonUtil::encode($config) . ");");
143  $DIC['tpl']->addOnLoadCode("il.OnScreenChatMenu.init();");
144 
145  $tpl->setVariable('GLYPH', $glyph_html);
146  $tpl->setVariable('LOADER', ilUtil::getImagePath('loader.svg'));
147  return $tpl->get();
148  }
149 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
__construct()
ilOnScreenChatMenuGUI constructor.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
if(!array_key_exists('StateId', $_REQUEST)) $id
static encode($mixed, $suppress_native=false)
Class ilOnScreenChatMenuGUI.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
Create styles array
The data for the language used.
static yn2tf($a_yn)
convert "y"/"n" to true/false
static initLinkify($a_tpl=null)
Init Linkify.