ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddyList.php';
6 require_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 
53  public function __construct($a_parent_obj, $a_parent_cmd)
54  {
60  global $ilCtrl, $tpl, $rbacsystem;
61 
62  $this->ctrl = $ilCtrl;
63  $this->container_tpl = $tpl;
64 
65  $this->setId('buddy_system_tbl');
66  parent::__construct($a_parent_obj, $a_parent_cmd);
67 
68  $this->lng->loadLanguageModule('buddysystem');
69 
70  $this->access_to_mail_system = $rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId());
71 
72  $chatSettings = new ilSetting('chatroom');
73  $this->chat_enabled = $chatSettings->get("chat_enabled", false);
74 
75  $this->setDefaultOrderDirection('ASC');
76  $this->setDefaultOrderField('public_name');
77 
78  $this->setTitle($this->lng->txt('buddy_tbl_title_relations'));
79 
80  if($this->access_to_mail_system || $this->chat_enabled)
81  {
82  $this->addColumn('', 'chb', '1%', true);
83  $this->setSelectAllCheckbox('usr_id');
84  if($this->access_to_mail_system)
85  {
86  $this->addMultiCommand('mailToUsers', $this->lng->txt('send_mail_to'));
87  }
88  if($this->chat_enabled)
89  {
90  $this->addMultiCommand('inviteToChat', $this->lng->txt('invite_to_chat'));
91  }
92  }
93 
94  $this->addColumn($this->lng->txt('name'), 'public_name');
95  $this->addColumn($this->lng->txt('login'), 'login');
96  $this->addColumn('', '');
97 
98  $this->setRowTemplate('tpl.buddy_system_relation_table_row.html', 'Services/Contact/BuddySystem');
99  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
100 
101  $this->setFilterCommand(self::APPLY_FILTER_CMD);
102  $this->setResetCommand(self::RESET_FILTER_CMD);
103 
104  $this->initFilter();
105  }
106 
110  public function initFilter()
111  {
112  $this->filters = array();
113  $this->filter = array();
114 
115  require_once 'Services/Contact/BuddySystem/classes/states/class.ilBuddySystemRelationStateFactory.php';
116 
117  require_once'Services/Form/classes/class.ilSelectInputGUI.php';
118  $relations_state_selection = new ilSelectInputGUI($this->lng->txt('buddy_tbl_filter_state'), self::STATE_FILTER_ELM_ID);
119 
120  $options = array();
121  $state = ilBuddySystemRelationStateFactory::getInstance()->getStatesAsOptionArray(false);
122  foreach($state as $key => $option)
123  {
124  $options[$key] = $option;
125  }
126  $relations_state_selection->setOptions(array('' => $this->lng->txt('please_choose')) + $options);
127  $this->addFilterItem($relations_state_selection);
128  $relations_state_selection->readFromSession();
129  $this->filter['relation_state_type'] = $relations_state_selection->getValue();
130 
131  require_once 'Services/Form/classes/class.ilTextInputGUI.php';
132  $public_name = new ilTextInputGUI($this->lng->txt('name'), 'public_name');
133  $this->addFilterItem($public_name);
134  $public_name->readFromSession();
135  $this->filter['public_name'] = $public_name->getValue();
136  }
137 
141  public function populate()
142  {
143  $this->setExternalSorting(false);
144  $this->setExternalSegmentation(false);
145 
146  $data = array();
147 
148  $relations = ilBuddyList::getInstanceByGlobalUser()->getRelations();
149 
150  $state_filter = $this->filter[self::STATE_FILTER_ELM_ID];
151  $relations = $relations->filter(function(ilBuddySystemRelation $relation) use ($state_filter) {
152  return !strlen($state_filter) || strtolower(get_class($relation->getState())) == strtolower($state_filter);
153  });
154 
155  require_once 'Services/User/classes/class.ilUserUtil.php';
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 = $this->filter['public_name'];
171  $relations = $relations->filter(function(ilBuddySystemRelation $relation) use ($public_name, $relations, $public_names, $logins) {
172  return (
173  !strlen($public_name) ||
174  strpos(strtolower($public_names[$relations->getKey($relation)]), strtolower($public_name)) !== false ||
175  strpos(strtolower($logins[$relations->getKey($relation)]), strtolower($public_name)) !== false
176  );
177  });
178 
179  foreach($relations->toArray() as $usr_id => $relation)
180  {
181  $data[] = array(
182  'usr_id' => $usr_id,
183  'public_name' => $public_names[$usr_id],
184  'login' => $logins[$usr_id]
185  );
186  }
187 
188  $this->setData($data);
189  }
190 
196  protected function fillRow($a_set)
197  {
201  global $ilUser;
202 
203  if($this->access_to_mail_system)
204  {
205  $a_set['chb'] = ilUtil::formCheckbox(0, 'usr_id[]', $a_set['usr_id']);
206  }
207 
208  $public_profile = ilObjUser::_lookupPref($a_set['usr_id'], 'public_profile');
209  if(!$ilUser->isAnonymous() && $public_profile == 'y' || $public_profile == 'g')
210  {
211  $this->ctrl->setParameterByClass('ilpublicuserprofilegui', 'user', $a_set['usr_id']);
212  $profile_target = $this->ctrl->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
213  $a_set['profile_link'] = $profile_target;
214  $a_set['linked_public_name'] = $a_set['public_name'];
215 
216  $a_set['profile_link_login'] = $profile_target;
217  $a_set['linked_login'] = $a_set['login'];
218  }
219  else
220  {
221  $a_set['unlinked_public_name'] = $a_set['public_name'];
222  $a_set['unlinked_login'] = $a_set['login'];
223  }
224 
225  $a_set['contact_actions'] = ilBuddySystemLinkButton::getInstanceByUserId($a_set['usr_id'])->getHtml();
226  parent::fillRow($a_set);
227  }
228 
232  public function render()
233  {
234  $listener_tpl = new ilTemplate('tpl.buddy_system_relation_table_listener.html', true, true, 'Services/Contact/BuddySystem');
235  $listener_tpl->setVariable('TABLE_ID', $this->getId());
236  $listener_tpl->setVariable('FILTER_ELM_ID', self::STATE_FILTER_ELM_ID);
237  $listener_tpl->setVariable('NO_ENTRIES_TEXT', $this->getNoEntriesText() ? $this->getNoEntriesText() : $this->lng->txt("no_items"));
238 
239  return parent::render() . $listener_tpl->get();
240  }
241 }
ILIAS Setting Class.
setExternalSorting($a_val)
Set external sorting.
__construct($a_parent_obj, $a_parent_cmd="", $a_template_context="")
Constructor.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
This class represents a selection list property in a property form.
setExternalSegmentation($a_val)
Set external segmentation.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
_lookupPref($a_usr_id, $a_keyword)
setId($a_val)
Set id.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
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)
Default behaviour is:
Class ilTable2GUI.
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
if(!is_array($argv)) $options
special template class to simplify handling of ITX/PEAR
addMultiCommand($a_cmd, $a_text)
Add Command button.
This class represents a text property in a property form.
setOptions($a_options)
Set Options.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
getNoEntriesText()
Get text for an empty table.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $ilUser
Definition: imgupload.php:15
Class ilBuddySystemRelation.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable...
fillRow($a_set)
Standard Version of Fill Row.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
getId()
Get element id.
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.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public
setFilterCommand($a_val, $a_caption=null)
Set filter command.