ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBuddySystemRelationsTableGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 const APPLY_FILTER_CMD = 'applyContactsTableFilter';
12
14 const RESET_FILTER_CMD = 'resetContactsTableFilter';
15
17 const STATE_FILTER_ELM_ID = 'relation_state_type';
18
21
23 protected $hasAccessToMailSystem = false;
24
26 protected $isChatEnabled = false;
27
29 protected $user;
30
35 public function __construct($a_parent_obj, $a_parent_cmd)
36 {
37 global $DIC;
38
39 $this->containerTemplate = $DIC['tpl'];
40 $this->user = $DIC['ilUser'];
41
42 $this->setId('buddy_system_tbl');
43 parent::__construct($a_parent_obj, $a_parent_cmd);
44
45 $this->lng->loadLanguageModule('buddysystem');
46
47 $this->hasAccessToMailSystem = $DIC->rbac()->system()->checkAccess(
48 'internal_mail',
50 );
51
52 $chatSettings = new ilSetting('chatroom');
53 $this->isChatEnabled = (bool) $chatSettings->get("chat_enabled", false);
54
55 $this->setDefaultOrderDirection('ASC');
56 $this->setDefaultOrderField('public_name');
57
58 $this->setTitle($this->lng->txt('buddy_tbl_title_relations'));
59
60 if ($this->hasAccessToMailSystem || $this->isChatEnabled) {
61 $this->addColumn('', 'chb', '1%', true);
62 $this->setSelectAllCheckbox('usr_id');
63 if ($this->hasAccessToMailSystem) {
64 $this->addMultiCommand('mailToUsers', $this->lng->txt('send_mail_to'));
65 }
66 if ($this->isChatEnabled) {
67 $this->addMultiCommand('inviteToChat', $this->lng->txt('invite_to_chat'));
68 }
69 }
70
71 $this->addColumn($this->lng->txt('name'), 'public_name');
72 $this->addColumn($this->lng->txt('login'), 'login');
73 $this->addColumn('', '');
74
75 $this->setRowTemplate('tpl.buddy_system_relation_table_row.html', 'Services/Contact/BuddySystem');
76 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
77
78 $this->setFilterCommand(self::APPLY_FILTER_CMD);
79 $this->setResetCommand(self::RESET_FILTER_CMD);
80
81 $this->initFilter();
82 }
83
87 public function initFilter()
88 {
89 $this->filters = [];
90 $this->filter = [];
91
92 $relations_state_selection = new ilSelectInputGUI(
93 $this->lng->txt('buddy_tbl_filter_state'),
94 self::STATE_FILTER_ELM_ID
95 );
96
97 $options = [];
99 foreach ($state_factory->getValidStates() as $state) {
100 if ($state->isInitial()) {
101 continue;
102 }
103
104 $state_filter_mapper = $state_factory->getTableFilterStateMapper($state);
105 $options += $state_filter_mapper->optionsForState();
106 }
107 $relations_state_selection->setOptions(['' => $this->lng->txt('please_choose')] + $options);
108 $this->addFilterItem($relations_state_selection);
109 $relations_state_selection->readFromSession();
110 $this->filter['relation_state_type'] = $relations_state_selection->getValue();
111
112 $public_name = new ilTextInputGUI($this->lng->txt('name'), 'public_name');
113 $this->addFilterItem($public_name);
114 $public_name->readFromSession();
115 $this->filter['public_name'] = $public_name->getValue();
116 }
117
123 public function applyFilterValue(string $filterKey, $value) : void
124 {
125 foreach ([$this->getFilterItems(), $this->getFilterItems(true)] as $filterItems) {
126 foreach ($filterItems as $item) {
128 if ($item->getPostVar() === $filterKey) {
129 $item->setValueByArray([$filterKey => $value]);
130 $item->writeToSession();
131 break 2;
132 }
133 }
134 }
135 }
136
140 public function populate() : void
141 {
142 $this->setExternalSorting(false);
143 $this->setExternalSegmentation(false);
144
145 $data = [];
146
147 $relations = ilBuddyList::getInstanceByGlobalUser()->getRelations();
148
149 $state_filter = (string) $this->filter[self::STATE_FILTER_ELM_ID];
151 $relations = $relations->filter(function (ilBuddySystemRelation $relation) use ($state_filter, $state_factory) : bool {
152 $state_filter_mapper = $state_factory->getTableFilterStateMapper($relation->getState());
153 return $state_filter === '' || $state_filter_mapper->filterMatchesRelation($state_filter, $relation);
154 });
155
156 $public_names = ilUserUtil::getNamePresentation($relations->getKeys(), false, false, '', false, true, false);
157 $logins = ilUserUtil::getNamePresentation($relations->getKeys(), false, false, '', false, false, false);
158
159 $logins = array_map(function ($value) {
160 $matches = null;
161 preg_match_all('/\[([^\[]+?)\]/', $value, $matches);
162 return (
163 is_array($matches) &&
164 isset($matches[1]) &&
165 is_array($matches[1]) &&
166 isset($matches[1][count($matches[1]) - 1])
167 ) ? $matches[1][count($matches[1]) - 1] : '';
168 }, $logins);
169
170 $public_name_query = (string) $this->filter['public_name'];
171 $relations = $relations->filter(static function (ilBuddySystemRelation $relation) use (
172 $public_name_query,
173 $relations,
174 $public_names,
175 $logins
176 ) : bool {
177 $usrId = $relations->getKey($relation);
178
179 $hasMatchingName = (
180 0 === ilStr::strlen($public_name_query) ||
181 ilStr::strpos(
182 ilStr::strtolower($public_names[$usrId]),
183 ilStr::strtolower($public_name_query)
184 ) !== false ||
185 ilStr::strpos(ilStr::strtolower($logins[$usrId]), ilStr::strtolower($public_name_query)) !== false
186 );
187
188 if (!$hasMatchingName) {
189 return false;
190 }
191
192 return ilObjUser::_lookupActive($usrId);
193 });
194
195 foreach ($relations->toArray() as $usr_id => $relation) {
196 $data[] = [
197 'usr_id' => $usr_id,
198 'public_name' => $public_names[$usr_id],
199 'login' => $logins[$usr_id]
200 ];
201 }
202
203 $this->setData($data);
204 }
205
209 protected function fillRow($a_set)
210 {
211 if ($this->hasAccessToMailSystem) {
212 $a_set['chb'] = ilUtil::formCheckbox(0, 'usr_id[]', $a_set['usr_id']);
213 }
214
215 $public_profile = ilObjUser::_lookupPref($a_set['usr_id'], 'public_profile');
216 if ((!$this->user->isAnonymous() && $public_profile === 'y') || $public_profile === 'g') {
217 $this->ctrl->setParameterByClass('ilpublicuserprofilegui', 'user', $a_set['usr_id']);
218 $profile_target = $this->ctrl->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
219 $a_set['profile_link'] = $profile_target;
220 $a_set['linked_public_name'] = $a_set['public_name'];
221
222 $a_set['profile_link_login'] = $profile_target;
223 $a_set['linked_login'] = $a_set['login'];
224 } else {
225 $a_set['unlinked_public_name'] = $a_set['public_name'];
226 $a_set['unlinked_login'] = $a_set['login'];
227 }
228
229 $a_set['contact_actions'] = ilBuddySystemLinkButton::getInstanceByUserId((int) $a_set['usr_id'])->getHtml();
230 parent::fillRow($a_set);
231 }
232
236 public function render()
237 {
238 $listener_tpl = new ilTemplate(
239 'tpl.buddy_system_relation_table_listener.html',
240 true,
241 true,
242 'Services/Contact/BuddySystem'
243 );
244 $listener_tpl->setVariable('TABLE_ID', $this->getId());
245 $listener_tpl->setVariable('FILTER_ELM_ID', self::STATE_FILTER_ELM_ID);
246 $listener_tpl->setVariable(
247 'NO_ENTRIES_TEXT',
248 $this->getNoEntriesText() ? $this->getNoEntriesText() : $this->lng->txt('no_items')
249 );
250
251 return parent::render() . $listener_tpl->get();
252 }
253}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByGlobalUser()
Class ilBuddySystemRelation.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
static _lookupPref($a_usr_id, $a_keyword)
static _lookupActive($a_usr_id)
Check user account active.
This class represents a selection list property in a property form.
ILIAS Setting Class.
Class ilTable2GUI.
setExternalSorting($a_val)
Set external sorting.
getNoEntriesText()
Get text for an empty table.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
getFilterItems($a_optionals=false)
Get filter items.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
getId()
Get element id.
setData($a_data)
set table data @access public
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static formCheckbox($checked, $varname, $value, $disabled=false)
??? @access public
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc