BxBaseCmtsMenuActions.php 3.9 KB

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