ILIAS  Release_4_2_x_branch Revision 61807
 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 include_once 'Services/Table/classes/class.ilTable2GUI.php';
5 
16 {
17  protected $lng = null;
18  protected $ctrl = null;
19 
20  protected $_folderNode = array();
21  protected $_parentObject = null;
22  protected $_currentFolderId = 0;
23  protected $_number_of_mails = 0;
24  protected $_selectedItems = array();
25  protected $_isTrashFolder = false;
26  protected $_isDraftsFolder = false;
27  protected $_isSentFolder = false;
28 
39  public function __construct($a_parent_obj, $a_current_folder_id, $a_parent_cmd = '')
40  {
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 
74  final public function prepareHTML()
75  {
76  global $ilUser;
77 
78  $this->addColumn('', 'sort', '5%', true);
79  $this->addColumn($this->lng->txt('personal_picture'), '', '10%');
80  if($this->isDraftFolder() || $this->isSentFolder())
81  $this->addColumn($this->lng->txt('recipient'), 'rcp_to', '25%');
82  else
83  $this->addColumn($this->lng->txt('sender'), 'from', '25%');
84  $this->addColumn($this->lng->txt('subject'), 'm_subject', '40%');
85  $this->addColumn($this->lng->txt('date'), 'send_time', '20%');
86 
87  // init folder data
88  $mtree = new ilTree($ilUser->getId());
89  $mtree->setTableNames('mail_tree', 'mail_obj_data');
90  $this->_folderNode = $mtree->getNodeData($this->_currentFolderId);
91 
92  // command buttons
93  $this->initCommandButtons();
94 
95  // mail actions
96  $this->initMultiCommands($this->_parentObject->mbox->getActions($this->_currentFolderId));
97 
98  // fetch table data
99  $this->fetchTableData();
100 
101  return $this;
102  }
103 
113  public function isDraftFolder($a_bool = null)
114  {
115  if(null === $a_bool)
116  {
117  return $this->_isDraftsFolder;
118  }
119 
120  $this->_isDraftsFolder = $a_bool;
121 
122  return $this;
123  }
124 
134  public function isSentFolder($a_bool = null)
135  {
136  if(null === $a_bool)
137  {
138  return $this->_isSentFolder;
139  }
140 
141  $this->_isSentFolder = $a_bool;
142 
143  return $this;
144  }
145 
155  public function isTrashFolder($a_bool = null)
156  {
157  if(null === $a_bool)
158  {
159  return $this->_isTrashFolder;
160  }
161 
162  $this->_isTrashFolder = $a_bool;
163 
164  return $this;
165  }
166 
176  private function initCommandButtons()
177  {
178  if($this->_folderNode['m_type'] == 'trash')
179  {
180  $this->addCommandButton('askForEmptyTrash', $this->lng->txt('mail_empty_trash'));
181  }
182 
183  return $this;
184  }
185 
195  private function initMultiCommands($actions)
196  {
197  foreach($actions as $key => $action)
198  {
199  if($key == 'moveMails')
200  {
201  $folders = $this->_parentObject->mbox->getSubFolders();
202  foreach($folders as $folder)
203  {
204  if($folder['type'] != 'trash' ||
205  !$this->isTrashFolder())
206  {
207  if($folder['type'] != 'user_folder')
208  {
209  $label = $action.' '.$this->lng->txt('mail_'.$folder['title']).
210  ($folder['type'] == 'trash' ? ' ('.$this->lng->txt('delete').')' : '');
211  $this->addMultiCommand($folder['obj_id'], $label);
212  }
213  else
214  $this->addMultiCommand($folder['obj_id'], $action.' '.$folder['title']);
215  }
216  }
217  }
218  else
219  {
220  if($key != 'deleteMails' || $this->isTrashFolder())
221  $this->addMultiCommand($key, $action);
222  }
223  }
224 
225  return $this;
226  }
227 
237  private function getUserInstance($a_usr_id)
238  {
239  static $userObjectCache = array();
240 
241  if(isset($userObjectCache[$a_usr_id])) return $userObjectCache[$a_usr_id];
242 
243  $userObjectCache[$a_usr_id] = new ilObjUser($a_usr_id);
244 
245  return $userObjectCache[$a_usr_id];
246  }
247 
257  public function setSelectedItems($a_selected_items)
258  {
259  $this->_selectedItems = $a_selected_items;
260 
261  return $this;
262  }
263 
272  public function getSelectedItems()
273  {
274  return $this->_selectedItems;
275  }
276 
285  protected function fetchTableData()
286  {
287  global $ilUser;
288 
289  $this->determineOffsetAndOrder();
290 
291  require_once 'Services/Mail/classes/class.ilMailBoxQuery.php';
292 
294  ilMailBoxQuery::$userId = $ilUser->getId();
295  ilMailBoxQuery::$limit = $this->getLimit();
300 
301  if(!count($data['set']) && $this->getOffset() > 0)
302  {
303  $this->resetOffset();
304 
305  ilMailBoxQuery::$limit = $this->getLimit();
308  }
309 
310  $counter = 0;
311  foreach($data['set'] as $key => $mail)
312  {
313  ++$counter;
314 
315  if(is_array($this->getSelectedItems()) &&
316  in_array($mail['mail_id'], $this->getSelectedItems()))
317  {
318  $mail['checked'] = ' checked="checked" ';
319  }
320 
321  // GET FULLNAME OF SENDER
322  if($this->isDraftFolder() || $this->isSentFolder())
323  {
324  $mail['mail_login'] = $this->_parentObject->umail->formatNamesForOutput($mail['rcp_to']);
325  }
326  else
327  {
328  if($mail['sender_id'] != ANONYMOUS_USER_ID)
329  {
330  $tmp_user = $this->getUserInstance($mail['sender_id']);
331  if(in_array(ilObjUser::_lookupPref($mail['sender_id'], 'public_profile'), array('y', 'g')))
332  {
333  $mail['mail_from'] = $tmp_user->getFullname();
334  }
335  if(!($login = $tmp_user->getLogin()))
336  {
337  $login = $mail['import_name'].' ('.$this->lng->txt('user_deleted').')';
338  $mail['mail_login'] = $mail['import_name'].' ('.$this->lng->txt('user_deleted').')';
339  }
340 
341  $mail['img_sender'] = $tmp_user->getPersonalPicturePath('xxsmall');
342  $mail['mail_login'] = $mail['alt_sender'] = $login;
343  }
344  else
345  {
346  $tmp_user = $this->getUserInstance(ANONYMOUS_USER_ID);
347  $mail['img_sender'] = ilUtil::getImagePath('HeaderIcon50.png');
348  $mail['mail_login'] = $mail['alt_sender'] = ilMail::_getIliasMailerName();
349  }
350  }
351  $mail['mailclass'] = $mail['m_status'] == 'read' ? 'mailread' : 'mailunread';
352 
353  // IF ACTUAL FOLDER IS DRAFT BOX, DIRECT TO COMPOSE MESSAGE
354  if($this->isDraftFolder())
355  {
356  $this->ctrl->setParameterByClass('ilmailformgui', 'mail_id', $mail['mail_id']);
357  $this->ctrl->setParameterByClass('ilmailformgui', 'type', 'draft');
358  $mail['mail_link_read'] = $this->ctrl->getLinkTargetByClass('ilmailformgui');
359  $this->ctrl->clearParametersByClass('ilmailformgui');
360  }
361  else
362  {
363  $this->ctrl->setParameter($this->_parentObject, 'mail_id', $mail['mail_id']);
364  $this->ctrl->setParameter($this->_parentObject, 'cmd', 'showMail');
365  $mail['mail_link_read'] = $this->ctrl->getLinkTarget($this->_parentObject);
366  $this->ctrl->clearParameters($this->_parentObject);
367  }
368 
369  $mail['mail_subject'] = htmlspecialchars($mail['m_subject']);
370  $mail['mail_date'] = ilDatePresentation::formatDate(new ilDateTime($mail['send_time'], IL_CAL_DATETIME));
371 
372  $data['set'][$key] = $mail;
373  }
374 
375  $this->setData($data['set']);
376  $this->setMaxCount($data['cnt']);
377  $this->setNumerOfMails($data['cnt']);
378 
379  // table title
380  $txt_folder = '';
381  $img_folder = '';
382  if($this->_folderNode['m_type'] == 'user_folder')
383  {
384  $txt_folder = $this->_folderNode['title'];
385  $img_folder = 'icon_user_folder.gif';
386  }
387  else
388  {
389  $txt_folder = $this->lng->txt('mail_'.$this->_folderNode['title']);
390  $img_folder = 'icon'.substr($this->_folderNode['title'], 1).'.gif';
391  }
392  $this->setTitleData($txt_folder, $data['cnt'], $data['cnt_unread'], $img_folder);
393 
394  return $this;
395  }
396 
409  protected function setTitleData($folderLabel, $mailCount, $unreadCount, $imgFolder)
410  {
411  $titleTemplate = new ilTemplate('tpl.mail_folder_title.html', true, true, 'Services/Mail');
412  $titleTemplate->setVariable('TXT_FOLDER', $folderLabel);
413  $titleTemplate->setVariable('MAIL_COUNT', $mailCount);
414  $titleTemplate->setVariable('TXT_MAIL_S', $this->lng->txt('mail_s'));
415  $titleTemplate->setVariable('MAIL_COUNT_UNREAD', $unreadCount);
416  $titleTemplate->setVariable('TXT_UNREAD', $this->lng->txt('unread'));
417 
418  parent::setTitle($titleTemplate->get(), $imgFolder);
419 
420  return $this;
421  }
422 
432  public function setNumerOfMails($a_number_of_mails)
433  {
434  $this->_number_of_mails = $a_number_of_mails;
435 
436  return $this;
437  }
438 
447  public function getNumerOfMails()
448  {
450  }
451 
460  public function fillRow($a_set)
461  {
462  foreach($a_set as $key => $value)
463  {
464  $this->tpl->setVariable(strtoupper($key), $value);
465  }
466  }
467 }
468 ?>