BxBaseCmtsMenuActions.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. ));
  38. }
  39. protected function _getMenuItemItemVote($aItem)
  40. {
  41. $oVote = $this->_oCmts->getVoteObject($this->_aCmt['cmt_unique_id']);
  42. if(!$oVote)
  43. return false;
  44. $aVotesParams = array('dynamic_mode' => $this->_bDynamicMode);
  45. if($this->_bShowTitles)
  46. $aVotesParams['show_do_vote_label'] = true;
  47. return $oVote->getElementInline($aVotesParams);
  48. }
  49. protected function _getMenuItemItemReaction($aItem)
  50. {
  51. $oReaction = $this->_oCmts->getReactionObject($this->_aCmt['cmt_unique_id']);
  52. if(!$oReaction)
  53. return false;
  54. $aReactionParams = array('dynamic_mode' => $this->_bDynamicMode);
  55. if($this->_bShowTitles)
  56. $aReactionParams['show_do_vote_label'] = true;
  57. return $oReaction->getElementInline($aReactionParams);
  58. }
  59. protected function _getMenuItemItemScore($aItem)
  60. {
  61. $oScore = $this->_oCmts->getScoreObject($this->_aCmt['cmt_unique_id']);
  62. if(!$oScore)
  63. return false;
  64. $aScoresParams = array('dynamic_mode' => $this->_bDynamicMode);
  65. if($this->_bShowTitles)
  66. $aScoresParams['show_do_vote_label'] = true;
  67. return $oScore->getElementInline($aScoresParams);
  68. }
  69. protected function _getMenuItemItemReport($aItem)
  70. {
  71. $oReport = $this->_oCmts->getReportObject($this->_aCmt['cmt_unique_id']);
  72. if(!$oReport)
  73. return false;
  74. $aReportParams = array('dynamic_mode' => $this->_bDynamicMode);
  75. if($this->_bShowTitles)
  76. $aReportParams['show_do_report_label'] = true;
  77. return $oReport->getElementInline($aReportParams);
  78. }
  79. /**
  80. * Check if menu items is visible.
  81. * @param $a menu item array
  82. * @return boolean
  83. */
  84. protected function _isVisible ($a)
  85. {
  86. if(!parent::_isVisible($a))
  87. return false;
  88. $sCheckFuncName = '';
  89. $aCheckFuncParams = array();
  90. switch ($a['name']) {
  91. case 'item-reply':
  92. $sCheckFuncName = 'isReplyAllowed';
  93. if(!empty($this->_aCmt))
  94. $aCheckFuncParams = array($this->_aCmt);
  95. break;
  96. case 'item-vote':
  97. $sCheckFuncName = 'isVoteAllowed';
  98. if(!empty($this->_aCmt))
  99. $aCheckFuncParams = array($this->_aCmt);
  100. break;
  101. case 'item-score':
  102. $sCheckFuncName = 'isScoreAllowed';
  103. if(!empty($this->_aCmt))
  104. $aCheckFuncParams = array($this->_aCmt);
  105. break;
  106. case 'item-report':
  107. $sCheckFuncName = 'isReportAllowed';
  108. if(!empty($this->_aCmt))
  109. $aCheckFuncParams = array($this->_aCmt);
  110. break;
  111. case 'item-edit':
  112. $sCheckFuncName = 'isEditAllowed';
  113. if(!empty($this->_aCmt))
  114. $aCheckFuncParams = array($this->_aCmt);
  115. break;
  116. case 'item-delete':
  117. $sCheckFuncName = 'isRemoveAllowed';
  118. if(!empty($this->_aCmt))
  119. $aCheckFuncParams = array($this->_aCmt);
  120. break;
  121. case 'item-more':
  122. $sCheckFuncName = 'isMoreAllowed';
  123. if(!empty($this->_aCmt))
  124. $aCheckFuncParams = array($this->_aCmt);
  125. break;
  126. }
  127. if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
  128. return true;
  129. return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
  130. }
  131. }
  132. /** @} */