BxBaseModProfileMenuViewMeta.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * View entry meta menu
  13. */
  14. class BxBaseModProfileMenuViewMeta extends BxTemplMenuUnitMeta
  15. {
  16. protected $_sModule;
  17. protected $_oModule;
  18. protected $_bShowZeros;
  19. protected $_iContentId;
  20. protected $_aContentInfo;
  21. protected $_bContentPublic;
  22. protected $_oContentProfile;
  23. protected $_aContentProfileInfo;
  24. public function __construct($aObject, $oTemplate = false)
  25. {
  26. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  27. parent::__construct($aObject, $oTemplate);
  28. $this->_bShowZeros = false;
  29. $this->_iContentId = 0;
  30. $this->_aContentInfo = [];
  31. $this->_bContentPublic = false;
  32. $this->_oContentProfile = null;
  33. $this->_aContentProfileInfo = [];
  34. }
  35. public function setContentId($iContentId)
  36. {
  37. $this->_iContentId = $iContentId;
  38. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
  39. if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
  40. return;
  41. $this->_oContentProfile = BxDolProfile::getInstanceByContentAndType($this->_iContentId, $this->_sModule);
  42. if(!$this->_oContentProfile)
  43. return;
  44. $this->_aContentProfileInfo = $this->_oContentProfile->getInfo();
  45. $this->addMarkers($this->_aContentProfileInfo);
  46. $this->addMarkers(array(
  47. 'profile_id' => $this->_oContentProfile->id()
  48. ));
  49. }
  50. public function setContentPublic($bContentPublic)
  51. {
  52. $this->_bContentPublic = $bContentPublic;
  53. }
  54. public function getCode()
  55. {
  56. if(empty($this->_iContentId))
  57. $this->_retrieveContentId();
  58. return parent::getCode();
  59. }
  60. protected function _getMenuItemMembership($aItem)
  61. {
  62. if(!$this->_bContentPublic || !$this->_oContentProfile)
  63. return false;
  64. $aMembership = BxDolAcl::getInstance()->getMemberMembershipInfo($this->_oContentProfile->id());
  65. return $aMembership ? $this->getUnitMetaItemText(_t($aMembership['name'])) : false;
  66. }
  67. protected function _getMenuItemBadges($aItem)
  68. {
  69. $sResult = $this->_oModule->serviceGetBadges($this->_iContentId);
  70. if(!empty($sResult))
  71. $sResult = $this->getUnitMetaItemText($sResult, ['class' => 'bx-base-bages-container']);
  72. return $sResult;
  73. }
  74. protected function _getMenuItemViews($aItem)
  75. {
  76. $CNF = &$this->_oModule->_oConfig->CNF;
  77. if(empty($CNF['OBJECT_VIEWS']) || empty($CNF['FIELD_VIEWS']) || (empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]) && !$this->_bShowZeros))
  78. return false;
  79. return $this->getUnitMetaItemText(_t('_view_n_views', $this->_aContentInfo[$CNF['FIELD_VIEWS']]));
  80. }
  81. protected function _getMenuItemVotes($aItem)
  82. {
  83. $CNF = &$this->_oModule->_oConfig->CNF;
  84. if(empty($CNF['OBJECT_VOTES']) || empty($CNF['FIELD_VOTES']) || (empty($this->_aContentInfo[$CNF['FIELD_VOTES']]) && !$this->_bShowZeros))
  85. return false;
  86. return $this->getUnitMetaItemText(_t('_vote_n_votes', $this->_aContentInfo[$CNF['FIELD_VOTES']]));
  87. }
  88. protected function _getMenuItemReactions($aItem)
  89. {
  90. $CNF = &$this->_oModule->_oConfig->CNF;
  91. if(empty($CNF['OBJECT_REACTIONS']))
  92. return false;
  93. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  94. if(!$oVotes)
  95. return false;
  96. return $this->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => false)));
  97. }
  98. protected function _getMenuItemScores($aItem)
  99. {
  100. $CNF = &$this->_oModule->_oConfig->CNF;
  101. if(empty($CNF['OBJECT_SCORES']))
  102. return false;
  103. $oScores = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  104. if(!$oScores)
  105. return false;
  106. return $this->getUnitMetaItemCustom($oScores->getElementInline(array('show_counter' => false)));
  107. }
  108. protected function _getMenuItemComments($aItem)
  109. {
  110. $CNF = &$this->_oModule->_oConfig->CNF;
  111. if(empty($CNF['OBJECT_COMMENTS']) || empty($CNF['FIELD_COMMENTS']) || (empty($this->_aContentInfo[$CNF['FIELD_COMMENTS']]) && !$this->_bShowZeros))
  112. return false;
  113. $oComments = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
  114. if(!$oComments || !$oComments->isEnabled())
  115. return false;
  116. return $this->getUnitMetaItemLink(_t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]), array(
  117. 'href' => $oComments->getListUrl()
  118. ));
  119. }
  120. protected function _retrieveContentId()
  121. {
  122. if(bx_get('id') !== false)
  123. $this->setContentId(bx_process_input(bx_get('id'), BX_DATA_INT));
  124. if(empty($this->_iContentId) && bx_get('profile_id') !== false)
  125. $this->setContentId(BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId());
  126. }
  127. }
  128. /** @} */