BxBaseCmtsMenuActions.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 BxBaseCmtsMenuActions extends BxTemplMenuCustom
  14. {
  15. protected $_oCmts;
  16. protected $_aCmt;
  17. protected $_aBp;
  18. protected $_aDp;
  19. protected $_bShowTitles;
  20. public function __construct ($aObject, $oTemplate)
  21. {
  22. parent::__construct ($aObject, $oTemplate);
  23. $this->_aBp = [];
  24. $this->_aDp = [];
  25. $this->_bShowTitles = false;
  26. }
  27. public function setCmtsData($oCmts, $iCmtId, $aBp = [], $aDp = [])
  28. {
  29. if(empty($oCmts) || empty($iCmtId))
  30. return;
  31. $this->_oCmts = $oCmts;
  32. $this->_aCmt = $oCmts->getCommentRow($iCmtId);
  33. $this->_aBp = $aBp;
  34. $this->_aDp = $aDp;
  35. $sJsObject = $oCmts->getJsObjectName();
  36. $this->addMarkers(array(
  37. 'js_object' => $sJsObject,
  38. 'cmt_system' => $this->_oCmts->getSystemName(),
  39. 'cmt_object_id' => $this->_oCmts->getId(),
  40. 'cmt_id' => $iCmtId,
  41. 'content_id' => $iCmtId,
  42. 'reply_onclick' => $sJsObject . '.toggleReply(this, ' . $iCmtId . ')',
  43. 'quote_onclick' => $sJsObject . '.toggleQuote(this, ' . $iCmtId . ')'
  44. ));
  45. }
  46. public function getMenuItems()
  47. {
  48. if((int)$this->_aCmt['cmt_pinned'] > 0 && !empty($this->_aBp['pinned']))
  49. $this->_aObject['menu_items'] = [
  50. 'item-unpin' => [
  51. 'name' => 'item-unpin',
  52. 'title' => '_sys_menu_item_title_cmts_item_unpin',
  53. 'link' => 'javascript:void(0)',
  54. 'onclick' => 'javascript:{js_object}.cmtPin(this, {content_id}, 0)',
  55. 'icon' => 'thumbtack'
  56. ]
  57. ];
  58. return parent::getMenuItems();
  59. }
  60. protected function _getMenuItemItemVote($aItem)
  61. {
  62. $oVote = $this->_oCmts->getVoteObject($this->_aCmt['cmt_unique_id']);
  63. if(!$oVote)
  64. return false;
  65. $aVotesParams = array('dynamic_mode' => $this->_bDynamicMode);
  66. if($this->_bShowTitles)
  67. $aVotesParams['show_do_vote_label'] = true;
  68. return $oVote->getElementInline($aVotesParams);
  69. }
  70. protected function _getMenuItemItemReaction($aItem)
  71. {
  72. $oReaction = $this->_oCmts->getReactionObject($this->_aCmt['cmt_unique_id']);
  73. if(!$oReaction)
  74. return false;
  75. $aReactionParams = array('dynamic_mode' => $this->_bDynamicMode);
  76. if($this->_bShowTitles)
  77. $aReactionParams['show_do_vote_label'] = true;
  78. return $oReaction->getElementInline($aReactionParams);
  79. }
  80. protected function _getMenuItemItemScore($aItem)
  81. {
  82. $oScore = $this->_oCmts->getScoreObject($this->_aCmt['cmt_unique_id']);
  83. if(!$oScore)
  84. return false;
  85. $aScoresParams = array('dynamic_mode' => $this->_bDynamicMode);
  86. if($this->_bShowTitles)
  87. $aScoresParams['show_do_vote_label'] = true;
  88. return $oScore->getElementInline($aScoresParams);
  89. }
  90. protected function _getMenuItemItemReport($aItem)
  91. {
  92. $oReport = $this->_oCmts->getReportObject($this->_aCmt['cmt_unique_id']);
  93. if(!$oReport)
  94. return false;
  95. $aReportParams = array('dynamic_mode' => $this->_bDynamicMode);
  96. if($this->_bShowTitles)
  97. $aReportParams['show_do_report_label'] = true;
  98. return $oReport->getElementInline($aReportParams);
  99. }
  100. /**
  101. * Check if menu items is visible.
  102. * @param $a menu item array
  103. * @return boolean
  104. */
  105. protected function _isVisible ($a)
  106. {
  107. if(!parent::_isVisible($a))
  108. return false;
  109. if((int)$this->_aCmt['cmt_pinned'] > 0 && !empty($this->_aBp['pinned']) && $a['name'] != 'item-unpin')
  110. return false;
  111. $sCheckFuncName = '';
  112. $aCheckFuncParams = array();
  113. switch ($a['name']) {
  114. case 'item-reply':
  115. $sCheckFuncName = 'isReplyAllowed';
  116. if(!empty($this->_aCmt))
  117. $aCheckFuncParams = array($this->_aCmt);
  118. break;
  119. case 'item-quote':
  120. $sCheckFuncName = 'isQuoteAllowed';
  121. if(!empty($this->_aCmt))
  122. $aCheckFuncParams = array($this->_aCmt);
  123. break;
  124. case 'item-vote':
  125. $sCheckFuncName = 'isVoteAllowed';
  126. if(!empty($this->_aCmt))
  127. $aCheckFuncParams = array($this->_aCmt);
  128. break;
  129. case 'item-score':
  130. $sCheckFuncName = 'isScoreAllowed';
  131. if(!empty($this->_aCmt))
  132. $aCheckFuncParams = array($this->_aCmt);
  133. break;
  134. case 'item-report':
  135. $sCheckFuncName = 'isReportAllowed';
  136. if(!empty($this->_aCmt))
  137. $aCheckFuncParams = array($this->_aCmt);
  138. break;
  139. case 'item-pin':
  140. $sCheckFuncName = 'isPinAllowed';
  141. if(!empty($this->_aCmt))
  142. $aCheckFuncParams = array($this->_aCmt);
  143. break;
  144. case 'item-unpin':
  145. $sCheckFuncName = 'isUnpinAllowed';
  146. if(!empty($this->_aCmt))
  147. $aCheckFuncParams = array($this->_aCmt);
  148. break;
  149. case 'item-edit':
  150. $sCheckFuncName = 'isEditAllowed';
  151. if(!empty($this->_aCmt))
  152. $aCheckFuncParams = array($this->_aCmt);
  153. break;
  154. case 'item-delete':
  155. $sCheckFuncName = 'isRemoveAllowed';
  156. if(!empty($this->_aCmt))
  157. $aCheckFuncParams = array($this->_aCmt);
  158. break;
  159. case 'item-more':
  160. $sCheckFuncName = 'isMoreAllowed';
  161. if(!empty($this->_aCmt))
  162. $aCheckFuncParams = array($this->_aCmt);
  163. break;
  164. }
  165. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  166. return true;
  167. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  168. }
  169. }
  170. /** @} */