BxNtfsMenuPreview.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $aResults[] = $aItem;
  55. }
  56. $iPerPage = $this->_oModule->_oConfig->getPerPage('preview');
  57. if(count($aResults) > $iPerPage)
  58. $aResults = array_slice($aResults, 0, $iPerPage);
  59. $bFirst = true;
  60. foreach($aItems as $iKey => $aItem) {
  61. if($bFirst)
  62. $bFirst = !$this->_oModule->_oDb->markAsRead($this->_iOwnerId, $aItem['id']);
  63. $aItems[$iKey]['name'] = 'event';
  64. }
  65. return array_merge($aItems, $this->_oQuery->getMenuItems());
  66. }
  67. protected function _getMenuItemDefault ($aItem)
  68. {
  69. return $this->_oTemplate->parseHtmlByContent($this->_sTmplContentPreviewItem, $aItem);
  70. }
  71. protected function _getMenuItemEvent($aItem)
  72. {
  73. return $this->_oTemplate->getPost($aItem, $this->_aBrowseParams);
  74. }
  75. }
  76. /** @} */