BxBaseCmtsMenuUnitMeta.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Menu representation.
  11. * @see BxDolMenu
  12. */
  13. class BxBaseCmtsMenuUnitMeta extends BxTemplMenuUnitMeta
  14. {
  15. protected $_oCmts;
  16. protected $_aCmtsSystem;
  17. protected $_aCmt;
  18. public function __construct ($aObject, $oTemplate)
  19. {
  20. parent::__construct ($aObject, $oTemplate);
  21. }
  22. public function setCmtsData($oCmts, $iCmtId)
  23. {
  24. if(empty($oCmts) || empty($iCmtId))
  25. return;
  26. $this->_oCmts = $oCmts;
  27. $this->_aCmtsSystem = $oCmts->getSystemInfo();
  28. $this->_aCmt = $oCmts->getCommentRow($iCmtId);
  29. $this->_sStylePrefix = (!empty($this->_aCmtsSystem['root_style_prefix']) ? $this->_aCmtsSystem['root_style_prefix'] : 'cmt') . '-meta';
  30. $this->addMarkers(array(
  31. 'cmt_system' => $this->_oCmts->getSystemName(),
  32. 'cmt_object_id' => $this->_oCmts->getId(),
  33. 'cmt_id' => $iCmtId,
  34. 'content_id' => $iCmtId,
  35. ));
  36. }
  37. protected function _getMenuItemAuthor($aItem)
  38. {
  39. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $this->_oCmts->getAuthorInfo($this->_aCmt['cmt_author_id']);
  40. if(!empty($sAuthorLink))
  41. return $this->getUnitMetaItemLink($sAuthorName, array(
  42. 'href' => $sAuthorLink,
  43. 'class' => $this->_sStylePrefix . '-username',
  44. 'title' => bx_html_attribute($sAuthorName),
  45. ));
  46. else
  47. return $this->getUnitMetaItemText($sAuthorName, array(
  48. 'class' => $this->_sStylePrefix . '-username'
  49. ));
  50. }
  51. protected function _getMenuItemDate($aItem)
  52. {
  53. $sAgo = bx_time_js($this->_aCmt['cmt_time']);
  54. if(!empty($this->_aCmtsSystem['trigger_field_title']))
  55. return $this->getUnitMetaItemLink($sAgo, array(
  56. 'href' => $this->_oCmts->getViewUrl($this->_aCmt['cmt_id']),
  57. 'class' => $this->_sStylePrefix . '-ago'
  58. ));
  59. else
  60. return $this->getUnitMetaItemText($sAgo, array(
  61. 'class' => $this->_sStylePrefix . '-ago'
  62. ));
  63. }
  64. protected function _getMenuItemMembership($aItem)
  65. {
  66. $iUserId = bx_get_logged_profile_id();
  67. $iAuthorId = (int)$this->_aCmt['cmt_author_id'];
  68. if($iAuthorId < 0 && (abs($iAuthorId) == $iUserId || $this->_oCmts->isModerator()))
  69. $iAuthorId *= -1;
  70. $aMembership = BxDolAcl::getInstance()->getMemberMembershipInfo($iAuthorId);
  71. if(empty($aMembership) || !is_array($aMembership))
  72. return '';
  73. return $this->getUnitMetaItemText(_t($aMembership['name']), array(
  74. 'class' => $this->_sStylePrefix . '-membership'
  75. ));
  76. }
  77. protected function _getMenuItemDefault($aItem)
  78. {
  79. $sResult = false;
  80. bx_alert('comment', 'menu_custom_item', 0, 0, array(
  81. 'res' => &$sResult,
  82. 'menu' => $this->_sObject,
  83. 'menu_object' => $this,
  84. 'item' => $aItem,
  85. 'content_id' => $this->_aCmt['cmt_id'],
  86. 'content_data' => $this->_aCmt,
  87. 'cmts_object' => $this->_oCmts
  88. ));
  89. if (false !== $sResult)
  90. return $sResult;
  91. return parent::_getMenuItemDefault($aItem);
  92. }
  93. }
  94. /** @} */