BxForumMenuSnippetMeta.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 Forum Forum
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxForumMenuSnippetMeta extends BxBaseModTextMenuSnippetMeta
  12. {
  13. public function __construct($aObject, $oTemplate = false)
  14. {
  15. $this->_sModule = 'bx_forum';
  16. parent::__construct($aObject, $oTemplate);
  17. }
  18. protected function _getMenuItemReplyAuthor($aItem)
  19. {
  20. if($this->_bIsApi) //--- API: Isn't supported
  21. return false;
  22. $CNF = &$this->_oModule->_oConfig->CNF;
  23. if(empty($this->_aContentInfo[$CNF['FIELD_LR_COMMENT_ID']]))
  24. return '';
  25. $oProfile = BxDolProfile::getInstanceMagic($this->_aContentInfo[$CNF['FIELD_LR_AUTHOR']]);
  26. return $this->getUnitMetaItemCustom($oProfile->getUnit(0, array('template' => array(
  27. 'name' => 'unit',
  28. 'size' => 'icon'
  29. ))));
  30. }
  31. protected function _getMenuItemReplyDate($aItem)
  32. {
  33. if($this->_bIsApi) //--- API: Isn't supported
  34. return false;
  35. $CNF = &$this->_oModule->_oConfig->CNF;
  36. if(empty($this->_aContentInfo[$CNF['FIELD_LR_COMMENT_ID']]))
  37. return '';
  38. return $this->getUnitMetaItemText(bx_time_js($this->_aContentInfo[$CNF['FIELD_LR_ADDED']], BX_FORMAT_DATE));
  39. }
  40. protected function _getMenuItemReplyText($aItem)
  41. {
  42. if($this->_bIsApi) //--- API: Isn't supported
  43. return false;
  44. $CNF = &$this->_oModule->_oConfig->CNF;
  45. if(empty($this->_aContentInfo[$CNF['FIELD_LR_COMMENT_ID']]))
  46. return '';
  47. $iComment = $this->_aContentInfo[$CNF['FIELD_LR_COMMENT_ID']];
  48. $aComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']])->getCommentRow($iComment);
  49. if(empty($aComment) || !is_array($aComment))
  50. return '';
  51. return $this->getUnitMetaItemText(strmaxtextlen($aComment['cmt_text'], 100), array('class' => $this->_sModule . '-gpm-reply-text'));
  52. }
  53. protected function _getMenuItemAuthor($aItem)
  54. {
  55. if($this->_bIsApi) //--- API: Isn't supported
  56. return false;
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. $oProfile = BxDolProfile::getInstanceMagic($this->_aContentInfo[$CNF['FIELD_AUTHOR']]);
  59. return $this->getUnitMetaItemExtended($oProfile->getDisplayName(), $oProfile->getThumb(), $oProfile->getUrl());
  60. }
  61. protected function _getMenuItemCategory($aItem)
  62. {
  63. $CNF = &$this->_oModule->_oConfig->CNF;
  64. if(empty($CNF['OBJECT_CATEGORY']) || empty($CNF['FIELD_CATEGORY']) || empty($this->_aContentInfo[$CNF['FIELD_CATEGORY']]))
  65. return false;
  66. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  67. if(!$oCategory)
  68. return false;
  69. $sTitle = $oCategory->getCategoryTitle($this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
  70. $sLink = $oCategory->getCategoryUrl($this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
  71. if($this->_bIsApi)
  72. return $this->_getMenuItemAPI($aItem, 'text', [
  73. 'title' => $sTitle,
  74. 'link' => $sLink
  75. ]);
  76. $aCategoryData = $this->_oModule->_oDb->getCategories([
  77. 'type' => 'by_category',
  78. 'category' => $this->_aContentInfo[$CNF['FIELD_CATEGORY']]
  79. ]);
  80. return $this->getUnitMetaItemExtended($sTitle, (isset($aCategoryData['icon']) ? $aCategoryData['icon'] : 'folder'), $sLink);
  81. }
  82. protected function _getMenuItemScores($aItem, $aParams = [])
  83. {
  84. return parent::_getMenuItemScores($aItem, [
  85. 'show_as_object' => true
  86. ]);
  87. }
  88. protected function _getMenuItemComments($aItem, $aParams = [])
  89. {
  90. if($this->_bIsApi) //--- API: Object base comments are used by default
  91. return $this->_getMenuItemCommentsObject($aItem, $aParams);
  92. $CNF = &$this->_oModule->_oConfig->CNF;
  93. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  94. return false;
  95. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  96. if(!$oComments || !$oComments->isEnabled())
  97. return false;
  98. return $this->getUnitMetaItemExtended(_t('_bx_forum_page_block_title_entry_comments', $oComments->getCommentsCountAll()), $aItem['icon'], '');
  99. }
  100. protected function _getMenuItemBadges($aItem)
  101. {
  102. if($this->_bIsApi) //--- API: Isn't supported
  103. return false;
  104. $CNF = &$this->_oModule->_oConfig->CNF;
  105. return $this->getUnitMetaItemExtended($this->_oModule->serviceGetBadges($this->_aContentInfo[$CNF['FIELD_ID']], false, true), '', '', false, true);
  106. }
  107. protected function _getMenuItemSticked($aItem)
  108. {
  109. if($this->_bIsApi) //--- API: Isn't supported
  110. return false;
  111. $CNF = &$this->_oModule->_oConfig->CNF;
  112. if((int)$this->_aContentInfo[$CNF['FIELD_STICK']] == 0)
  113. return false;
  114. return $this->getUnitMetaItemExtended(_t($aItem['title']), $aItem['icon'], '');
  115. }
  116. protected function _getMenuItemLocked($aItem)
  117. {
  118. if($this->_bIsApi) //--- API: Isn't supported
  119. return false;
  120. $CNF = &$this->_oModule->_oConfig->CNF;
  121. if((int)$this->_aContentInfo[$CNF['FIELD_LOCK']] == 0)
  122. return false;
  123. return $this->getUnitMetaItemExtended(_t($aItem['title']), $aItem['icon'], '');
  124. }
  125. protected function _getMenuItemStatus($aItem)
  126. {
  127. if($this->_bIsApi) //--- API: Isn't supported
  128. return false;
  129. $CNF = &$this->_oModule->_oConfig->CNF;
  130. $sStatus = '';
  131. if ($this->_aContentInfo['resolvable']){
  132. if ($this->_aContentInfo['resolved']){
  133. $sStatus .= _t('_bx_forum_grid_filter_resolved_resolved');
  134. }
  135. else{
  136. $sStatus .= _t('_bx_forum_grid_filter_resolved_unresolved');
  137. }
  138. return $this->getUnitMetaItemExtended($this->_oModule->_oTemplate->parseHtmlByName('status.html', ['status' => $sStatus, 'status_class' => $this->_aContentInfo['resolved']]), '' ,'', true, true);
  139. }
  140. return '';
  141. }
  142. }
  143. /** @} */