BxBaseCmtsMenuActions.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. $sCheckFuncName = '';
  90. $aCheckFuncParams = array();
  91. switch ($a['name']) {
  92. case 'item-reply':
  93. $sCheckFuncName = 'isReplyAllowed';
  94. if(!empty($this->_aCmt))
  95. $aCheckFuncParams = array($this->_aCmt);
  96. break;
  97. case 'item-quote':
  98. $sCheckFuncName = 'isQuoteAllowed';
  99. if(!empty($this->_aCmt))
  100. $aCheckFuncParams = array($this->_aCmt);
  101. break;
  102. case 'item-vote':
  103. $sCheckFuncName = 'isVoteAllowed';
  104. if(!empty($this->_aCmt))
  105. $aCheckFuncParams = array($this->_aCmt);
  106. break;
  107. case 'item-score':
  108. $sCheckFuncName = 'isScoreAllowed';
  109. if(!empty($this->_aCmt))
  110. $aCheckFuncParams = array($this->_aCmt);
  111. break;
  112. case 'item-report':
  113. $sCheckFuncName = 'isReportAllowed';
  114. if(!empty($this->_aCmt))
  115. $aCheckFuncParams = array($this->_aCmt);
  116. break;
  117. case 'item-edit':
  118. $sCheckFuncName = 'isEditAllowed';
  119. if(!empty($this->_aCmt))
  120. $aCheckFuncParams = array($this->_aCmt);
  121. break;
  122. case 'item-delete':
  123. $sCheckFuncName = 'isRemoveAllowed';
  124. if(!empty($this->_aCmt))
  125. $aCheckFuncParams = array($this->_aCmt);
  126. break;
  127. case 'item-more':
  128. $sCheckFuncName = 'isMoreAllowed';
  129. if(!empty($this->_aCmt))
  130. $aCheckFuncParams = array($this->_aCmt);
  131. break;
  132. }
  133. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  134. return true;
  135. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  136. }
  137. }
  138. /** @} */