1
0

BxBaseCmtsMenuActions.php 5.5 KB

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