BxNtfsMenuPreview.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. $sCode = parent::getCode();
  42. $sCode = $this->_oTemplate->parseHtmlByName('menu_preview.html', array(
  43. 'content' => $sCode
  44. ));
  45. $sCode .= $this->_oTemplate->getCss(true);
  46. return $sCode;
  47. }
  48. protected function getMenuItemsRaw ()
  49. {
  50. $aItems = $this->_oModule->serviceGetNotifications($this->_iOwnerId);
  51. if(empty($aItems) || !is_array($aItems))
  52. return array();
  53. $aResults = array();
  54. foreach($aItems as $iKey => $aItem) {
  55. if(!$this->_oModule->_oTemplate->getPost($aItem))
  56. continue;
  57. $aResults[] = $aItem;
  58. }
  59. $iPerPage = $this->_oModule->_oConfig->getPerPage('preview');
  60. if(count($aResults) > $iPerPage)
  61. $aResults = array_slice($aResults, 0, $iPerPage);
  62. $bFirst = true;
  63. foreach($aItems as $iKey => $aItem) {
  64. if($bFirst)
  65. $bFirst = !$this->_oModule->_oDb->markAsRead($this->_iOwnerId, $aItem['id']);
  66. $aItems[$iKey]['name'] = 'event';
  67. }
  68. return array_merge($aItems, $this->_oQuery->getMenuItems());
  69. }
  70. protected function _getMenuItemDefault ($aItem)
  71. {
  72. return $this->_oTemplate->parseHtmlByContent($this->_sTmplContentPreviewItem, $aItem);
  73. }
  74. protected function _getMenuItemEvent($aItem)
  75. {
  76. return $this->_oTemplate->getPost($aItem, $this->_aBrowseParams);
  77. }
  78. }
  79. /** @} */