BxBaseCmtsMenuActions.php 4.2 KB

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