ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailFolderTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 require_once 'Services/Mail/classes/class.ilMailUserCache.php';
6 
14 {
15  protected $lng = null;
16  protected $ctrl = null;
17 
18  protected $_folderNode = array();
19  protected $_parentObject = null;
20  protected $_currentFolderId = 0;
21  protected $_number_of_mails = 0;
22  protected $_selectedItems = array();
23  protected $_isTrashFolder = false;
24  protected $_isDraftsFolder = false;
25  protected $_isSentFolder = false;
26 
35  public function __construct($a_parent_obj, $a_current_folder_id, $a_parent_cmd = '')
36  {
41  global $lng, $ilCtrl;
42 
43  $this->lng = $lng;
44  $this->ctrl = $ilCtrl;
45 
46  $this->_currentFolderId = $a_current_folder_id;
47  $this->_parentObject = $a_parent_obj;
48 
49  $this->setId('mail_folder_tbl');
50  $this->setPrefix('mtable');
51 
52  parent::__construct($a_parent_obj, $a_parent_cmd);
53 
54  $this->setFormAction($this->ctrl->getFormAction($this->_parentObject, 'showFolder'));
55 
56  $this->setEnableTitle(true);
57  $this->setExternalSorting(true);
58  $this->setExternalSegmentation(true);
59  $this->setDefaultOrderField('send_time');
60  $this->setDefaultOrderDirection('desc');
61  $this->setSelectAllCheckbox('mail_id[]');
62  $this->setRowTemplate('tpl.mail_folder_row.html', 'Services/Mail');
63  }
64 
72  final public function prepareHTML()
73  {
74  global $ilUser;
75 
76  $this->addColumn('', '', '1px', true);
77  $this->addColumn($this->lng->txt('personal_picture'), '', '10%');
78  if($this->isDraftFolder() || $this->isSentFolder())
79  $this->addColumn($this->lng->txt('recipient'), 'rcp_to', '25%');
80  else
81  $this->addColumn($this->lng->txt('sender'), 'from', '25%');
82  $this->addColumn($this->lng->txt('subject'), 'm_subject', '40%');
83  $this->addColumn($this->lng->txt('date'), 'send_time', '20%');
84 
85  // init folder data
86  $mtree = new ilTree($ilUser->getId());
87  $mtree->setTableNames('mail_tree', 'mail_obj_data');
88  $this->_folderNode = $mtree->getNodeData($this->_currentFolderId);
89 
90  // fetch table data
91  $this->fetchTableData();
92 
93  // command buttons
94  $this->initCommandButtons();
95 
96  // mail actions
97  $this->initMultiCommands($this->_parentObject->mbox->getActions($this->_currentFolderId));
98 
99  return $this;
100  }
101 
109  public function isDraftFolder($a_bool = null)
110  {
111  if(null === $a_bool)
112  {
113  return $this->_isDraftsFolder;
114  }
115 
116  $this->_isDraftsFolder = $a_bool;
117 
118  return $this;
119  }
120 
128  public function isSentFolder($a_bool = null)
129  {
130  if(null === $a_bool)
131  {
132  return $this->_isSentFolder;
133  }
134 
135  $this->_isSentFolder = $a_bool;
136 
137  return $this;
138  }
139 
147  public function isTrashFolder($a_bool = null)
148  {
149  if(null === $a_bool)
150  {
151  return $this->_isTrashFolder;
152  }
153 
154  $this->_isTrashFolder = $a_bool;
155 
156  return $this;
157  }
158 
166  private function initCommandButtons()
167  {
168  if($this->_folderNode['m_type'] == 'trash' && $this->getNumerOfMails() > 0)
169  {
170  $this->addCommandButton('askForEmptyTrash', $this->lng->txt('mail_empty_trash'));
171  }
172 
173  return $this;
174  }
175 
183  private function initMultiCommands($actions)
184  {
185  foreach($actions as $key => $action)
186  {
187  if($key == 'moveMails')
188  {
189  $folders = $this->_parentObject->mbox->getSubFolders();
190  foreach($folders as $folder)
191  {
192  if($folder['type'] != 'trash' ||
193  !$this->isTrashFolder()
194  )
195  {
196  if($folder['type'] != 'user_folder')
197  {
198  $label = $action . ' ' . $this->lng->txt('mail_' . $folder['title']) .
199  ($folder['type'] == 'trash' ? ' (' . $this->lng->txt('delete') . ')' : '');
200  $this->addMultiCommand($folder['obj_id'], $label);
201  }
202  else
203  $this->addMultiCommand($folder['obj_id'], $action . ' ' . $folder['title']);
204  }
205  }
206  }
207  else
208  {
209  if($key != 'deleteMails' || $this->isTrashFolder())
210  $this->addMultiCommand($key, $action);
211  }
212  }
213 
214  return $this;
215  }
216 
224  public function setSelectedItems($a_selected_items)
225  {
226  $this->_selectedItems = $a_selected_items;
227 
228  return $this;
229  }
230 
237  public function getSelectedItems()
238  {
239  return $this->_selectedItems;
240  }
241 
248  protected function fetchTableData()
249  {
250  global $ilUser;
251 
252  $this->determineOffsetAndOrder();
253 
254  require_once 'Services/Mail/classes/class.ilMailBoxQuery.php';
255 
257  ilMailBoxQuery::$userId = $ilUser->getId();
258  ilMailBoxQuery::$limit = $this->getLimit();
263 
264  if(!count($data['set']) && $this->getOffset() > 0)
265  {
266  $this->resetOffset();
267 
268  ilMailBoxQuery::$limit = $this->getLimit();
271  }
272 
273  if(!$this->isDraftFolder() && !$this->isSentFolder())
274  {
275  $user_ids = array();
276  foreach($data['set'] as $mail)
277  {
278  if($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID)
279  {
280  $user_ids[$mail['sender_id']] = $mail['sender_id'];
281  }
282  }
283 
284  ilMailUserCache::preloadUserObjects($user_ids);
285  }
286 
287  $counter = 0;
288  foreach($data['set'] as $key => $mail)
289  {
290  ++$counter;
291 
292  if(is_array($this->getSelectedItems()) && in_array($mail['mail_id'], $this->getSelectedItems()))
293  {
294  $mail['checked'] = ' checked="checked" ';
295  }
296 
297  if($this->isDraftFolder() || $this->isSentFolder())
298  {
299  $mail['rcp_to'] = $mail['mail_login'] = $this->_parentObject->umail->formatNamesForOutput($mail['rcp_to']);
300  }
301  else
302  {
303  if($mail['sender_id'] == ANONYMOUS_USER_ID)
304  {
305  $mail['img_sender'] = ilUtil::getImagePath('HeaderIconAvatar.png');
306  $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = ilMail::_getIliasMailerName();
307  }
308  else
309  {
310  $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
311  if($user)
312  {
313  $mail['img_sender'] = $user->getPersonalPicturePath('xxsmall');
314  $mail['from'] = $mail['mail_login'] = $mail['alt_sender'] = $user->getPublicName();
315  }
316  else
317  {
318  $mail['from'] = $mail['mail_login'] = $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')';
319  }
320  }
321  }
322  $mail['mailclass'] = $mail['m_status'] == 'read' ? 'mailread' : 'mailunread';
323 
324  if($this->isDraftFolder())
325  {
326  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mail['mail_id']);
327  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'draft');
328  $mail['mail_link_read'] = $this->ctrl->getLinkTargetByClass('ilmailformgui');
329  $this->ctrl->clearParametersByClass('ilmailformgui');
330  }
331  else
332  {
333  $this->ctrl->setParameter($this->_parentObject, 'mail_id', $mail['mail_id']);
334  $mail['mail_link_read'] = $this->ctrl->getLinkTarget($this->_parentObject, 'showMail');
335  $this->ctrl->clearParameters($this->_parentObject);
336  }
337 
338  $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
339  $mail['mail_date'] = ilDatePresentation::formatDate(new ilDateTime($mail['send_time'], IL_CAL_DATETIME));
340 
341  $data['set'][$key] = $mail;
342  }
343 
344  $this->setData($data['set']);
345  $this->setMaxCount($data['cnt']);
346  $this->setNumerOfMails($data['cnt']);
347 
348  // table title
349  $txt_folder = '';
350  $img_folder = '';
351  if($this->_folderNode['m_type'] == 'user_folder')
352  {
353  $txt_folder = $this->_folderNode['title'];
354  $img_folder = 'icon_user_folder.png';
355  }
356  else
357  {
358  $txt_folder = $this->lng->txt('mail_' . $this->_folderNode['title']);
359  $img_folder = 'icon' . substr($this->_folderNode['title'], 1) . '.png';
360  }
361  $this->setTitleData($txt_folder, $data['cnt'], $data['cnt_unread'], $img_folder);
362 
363  return $this;
364  }
365 
376  protected function setTitleData($folderLabel, $mailCount, $unreadCount, $imgFolder)
377  {
378  $titleTemplate = new ilTemplate('tpl.mail_folder_title.html', true, true, 'Services/Mail');
379  $titleTemplate->setVariable('TXT_FOLDER', $folderLabel);
380  $titleTemplate->setVariable('MAIL_COUNT', $mailCount);
381  $titleTemplate->setVariable('TXT_MAIL_S', $this->lng->txt('mail_s'));
382  $titleTemplate->setVariable('MAIL_COUNT_UNREAD', $unreadCount);
383  $titleTemplate->setVariable('TXT_UNREAD', $this->lng->txt('unread'));
384 
385  parent::setTitle($titleTemplate->get(), $imgFolder);
386 
387  return $this;
388  }
389 
397  public function setNumerOfMails($a_number_of_mails)
398  {
399  $this->_number_of_mails = $a_number_of_mails;
400 
401  return $this;
402  }
403 
410  public function getNumerOfMails()
411  {
413  }
414 
421  public function fillRow($a_set)
422  {
423  foreach($a_set as $key => $value)
424  {
425  $this->tpl->setVariable(strtoupper($key), $value);
426  }
427  }
428 }