ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilBuddySystemRelationsTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Table/classes/class.ilTable2GUI.php';
5require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
6require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemLinkButton.php';
7
13{
17 const APPLY_FILTER_CMD = 'applyContactsTableFilter';
18
22 const RESET_FILTER_CMD = 'resetContactsTableFilter';
23
27 const STATE_FILTER_ELM_ID = 'relation_state_type';
28
32 protected $ctrl;
33
37 protected $container_tpl;
38
42 protected $access_to_mail_system = false;
43
47 protected $chat_enabled = false;
48
52 protected $user;
53
58 public function __construct($a_parent_obj, $a_parent_cmd)
59 {
64 global $DIC;
65
66 $this->ctrl = $DIC['ilCtrl'];
67 $this->container_tpl = $DIC['tpl'];
68 $this->user = $DIC['ilUser'];
69
70 $this->setId('buddy_system_tbl');
71 parent::__construct($a_parent_obj, $a_parent_cmd);
72
73 $this->lng->loadLanguageModule('buddysystem');
74
75 $this->access_to_mail_system = $DIC->rbac()->system()->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId());
76
77 $chatSettings = new ilSetting('chatroom');
78 $this->chat_enabled = $chatSettings->get("chat_enabled", false);
79
80 $this->setDefaultOrderDirection('ASC');
81 $this->setDefaultOrderField('public_name');
82
83 $this->setTitle($this->lng->txt('buddy_tbl_title_relations'));
84
85 if ($this->access_to_mail_system || $this->chat_enabled) {
86 $this->addColumn('', 'chb', '1%', true);
87 $this->setSelectAllCheckbox('usr_id');
88 if ($this->access_to_mail_system) {
89 $this->addMultiCommand('mailToUsers', $this->lng->txt('send_mail_to'));
90 }
91 if ($this->chat_enabled) {
92 $this->addMultiCommand('inviteToChat', $this->lng->txt('invite_to_chat'));
93 }
94 }
95
96 $this->addColumn($this->lng->txt('name'), 'public_name');
97 $this->addColumn($this->lng->txt('login'), 'login');
98 $this->addColumn('', '');
99
100 $this->setRowTemplate('tpl.buddy_system_relation_table_row.html', 'Services/Contact/BuddySystem');
101 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
102
103 $this->setFilterCommand(self::APPLY_FILTER_CMD);
104 $this->setResetCommand(self::RESET_FILTER_CMD);
105
106 $this->initFilter();
107 }
108
112 public function initFilter()
113 {
114 $this->filters = array();
115 $this->filter = array();
116
117 require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
118
119 require_once'Services/Form/classes/class.ilSelectInputGUI.php';
120 $relations_state_selection = new ilSelectInputGUI($this->lng->txt('buddy_tbl_filter_state'), self::STATE_FILTER_ELM_ID);
121
122 $options = array();
123 $state = ilBuddySystemRelationStateFactory::getInstance()->getStatesAsOptionArray(false);
124 foreach ($state as $key => $option) {
125 $options[$key] = $option;
126 }
127 $relations_state_selection->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
128 $this->addFilterItem($relations_state_selection);
129 $relations_state_selection->readFromSession();
130 $this->filter['relation_state_type'] = $relations_state_selection->getValue();
131
132 require_once 'Services/Form/classes/class.ilTextInputGUI.php';
133 $public_name = new ilTextInputGUI($this->lng->txt('name'), 'public_name');
134 $this->addFilterItem($public_name);
135 $public_name->readFromSession();
136 $this->filter['public_name'] = $public_name->getValue();
137 }
138
142 public function populate()
143 {
144 $this->setExternalSorting(false);
145 $this->setExternalSegmentation(false);
146
147 $data = array();
148
149 $relations = ilBuddyList::getInstanceByGlobalUser()->getRelations();
150
151 $state_filter = $this->filter[self::STATE_FILTER_ELM_ID];
152 $relations = $relations->filter(function (ilBuddySystemRelation $relation) use ($state_filter) {
153 return !strlen($state_filter) || strtolower(get_class($relation->getState())) == strtolower($state_filter);
154 });
155
156 require_once 'Services/User/classes/class.ilUserUtil.php';
157 $public_names = ilUserUtil::getNamePresentation($relations->getKeys(), false, false, '', false, true, false);
158 $logins = ilUserUtil::getNamePresentation($relations->getKeys(), false, false, '', false, false, false);
159
160 $logins = array_map(function ($value) {
161 $matches = null;
162 preg_match_all('/\[([^\[]+?)\]/', $value, $matches);
163 return (
164 is_array($matches) &&
165 isset($matches[1]) &&
166 is_array($matches[1]) &&
167 isset($matches[1][count($matches[1]) - 1])
168 ) ? $matches[1][count($matches[1]) - 1] : '';
169 }, $logins);
170
171 $public_name_query = (string) $this->filter['public_name'];
172 $relations = $relations->filter(static function (ilBuddySystemRelation $relation) use (
173 $public_name_query,
174 $relations,
175 $public_names,
176 $logins
177 ) : bool {
178 $usrId = $relations->getKey($relation);
179
180 $hasMatchingName = (
181 0 === ilStr::strlen($public_name_query) ||
182 ilStr::strpos(
183 ilStr::strtolower($public_names[$usrId]),
184 ilStr::strtolower($public_name_query)
185 ) !== false ||
186 ilStr::strpos(ilStr::strtolower($logins[$usrId]), ilStr::strtolower($public_name_query)) !== false
187 );
188
189 if (!$hasMatchingName) {
190 return false;
191 }
192
193 return ilObjUser::_lookupActive($usrId);
194 });
195
196 foreach ($relations->toArray() as $usr_id => $relation) {
197 $data[] = array(
198 'usr_id' => $usr_id,
199 'public_name' => $public_names[$usr_id],
200 'login' => $logins[$usr_id]
201 );
202 }
203
204 $this->setData($data);
205 }
206
212 protected function fillRow($a_set)
213 {
214 if ($this->access_to_mail_system) {
215 $a_set['chb'] = ilUtil::formCheckbox(0, 'usr_id[]', $a_set['usr_id']);
216 }
217
218 $public_profile = ilObjUser::_lookupPref($a_set['usr_id'], 'public_profile');
219 if ((!$this->user->isAnonymous() && $public_profile === 'y') || $public_profile === 'g') {
220 $this->ctrl->setParameterByClass('ilpublicuserprofilegui', 'user', $a_set['usr_id']);
221 $profile_target = $this->ctrl->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
222 $a_set['profile_link'] = $profile_target;
223 $a_set['linked_public_name'] = $a_set['public_name'];
224
225 $a_set['profile_link_login'] = $profile_target;
226 $a_set['linked_login'] = $a_set['login'];
227 } else {
228 $a_set['unlinked_public_name'] = $a_set['public_name'];
229 $a_set['unlinked_login'] = $a_set['login'];
230 }
231
232 $a_set['contact_actions'] = ilBuddySystemLinkButton::getInstanceByUserId($a_set['usr_id'])->getHtml();
233 parent::fillRow($a_set);
234 }
235
239 public function render()
240 {
241 $listener_tpl = new ilTemplate('tpl.buddy_system_relation_table_listener.html', true, true, 'Services/Contact/BuddySystem');
242 $listener_tpl->setVariable('TABLE_ID', $this->getId());
243 $listener_tpl->setVariable('FILTER_ELM_ID', self::STATE_FILTER_ELM_ID);
244 $listener_tpl->setVariable('NO_ENTRIES_TEXT', $this->getNoEntriesText() ? $this->getNoEntriesText() : $this->lng->txt("no_items"));
245
246 return parent::render() . $listener_tpl->get();
247 }
248}
user()
Definition: user.php:4
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByGlobalUser()
Class ilBuddySystemRelation.
fillRow($a_set)
Standard Version of Fill Row.
initFilter()
{Init filter.Overwrite this to initialize all filter input property objects.}
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.
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.
__construct($a_parent_obj, $a_parent_cmd="", $a_template_context="")
ilTable2GUI constructor.
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
$key
Definition: croninfo.php:18
global $DIC
Definition: saml.php:7