BxNtfsMenuPreview.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Notifications Notifications
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxNtfsMenuPreview extends BxTemplMenuCustom
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sTmplContentPreviewItem;
  16. protected $_iOwnerId;
  17. protected $_aBrowseParams;
  18. public function __construct($aObject, $oTemplate = false)
  19. {
  20. $this->_sModule = 'bx_notifications';
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. if(!$oTemplate)
  23. $oTemplate = $this->_oModule->_oTemplate;
  24. parent::__construct($aObject, $oTemplate);
  25. if(empty($this->_sTmplContentPreviewItem))
  26. $this->_sTmplContentPreviewItem = $this->_oTemplate->getHtml('menu_preview_item.html');
  27. $this->_iOwnerId = $this->_oModule->getUserId();
  28. $this->_aBrowseParams = array(
  29. 'last_read' => $this->_oModule->_oDb->getLastRead($this->_iOwnerId)
  30. );
  31. }
  32. public function getMenuItems ()
  33. {
  34. $aItems = parent::getMenuItems();
  35. if(empty($aItems) || !is_array($aItems))
  36. return MsgBox(_t('_Empty'));
  37. return $aItems;
  38. }
  39. public function getCode ()
  40. {
  41. return $this->_oTemplate->getAddedCss('', true) . $this->_oTemplate->parseHtmlByName('menu_preview.html', array(
  42. 'content' => parent::getCode()
  43. ));
  44. }
  45. protected function getMenuItemsRaw ()
  46. {
  47. $aItems = $this->_oModule->serviceGetNotifications($this->_iOwnerId);
  48. if(empty($aItems) || !is_array($aItems))
  49. return array();
  50. $aResults = array();
  51. foreach($aItems as $iKey => $aItem) {
  52. if(!$this->_oModule->_oTemplate->getPost($aItem))
  53. continue;
  54. $aItem['name'] = 'event';
  55. $aResults[] = $aItem;
  56. }
  57. $iPerPage = $this->_oModule->_oConfig->getPerPage('preview');
  58. if(count($aResults) > $iPerPage)
  59. $aResults = array_slice($aResults, 0, $iPerPage);
  60. $aFirst = reset($aItems);
  61. $this->_oModule->_oDb->markAsRead($this->_iOwnerId, $aFirst['id']);
  62. return array_merge($aResults, $this->_oQuery->getMenuItems());
  63. }
  64. protected function _getMenuItemDefault ($aItem)
  65. {
  66. return $this->_oTemplate->parseHtmlByContent($this->_sTmplContentPreviewItem, $aItem);
  67. }
  68. protected function _getMenuItemEvent($aItem)
  69. {
  70. return $this->_oTemplate->getPost($aItem, $this->_aBrowseParams);
  71. }
  72. }
  73. /** @} */