| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- /**
- * Menu representation.
- * @see BxDolMenu
- */
- class BxBaseCmtsMenuActions extends BxTemplMenuCustom
- {
- protected static $_sModeActions = 'actions';
- protected static $_sModeCounters = 'counters';
- protected $_oCmts;
- protected $_aCmt;
- protected $_aBp;
- protected $_aDp;
- protected $_sMode;
- protected $_bShowTitles;
- protected $_bShowCounters;
- protected $_bShowCountersIcons;
- public function __construct ($aObject, $oTemplate)
- {
- parent::__construct ($aObject, $oTemplate);
- $this->_aBp = [];
- $this->_aDp = [];
- $this->_sMode = strpos($this->_sObject, '_actions') !== false ? self::$_sModeActions : self::$_sModeCounters;
- $this->_bShowTitles = true;
- $this->_bShowCounters = false;
- $this->_bShowCountersIcons = true;
- }
- public function setCmtsData($oCmts, $iCmtId, $aBp = [], $aDp = [])
- {
- if(empty($oCmts) || empty($iCmtId))
- return;
- $this->_oCmts = $oCmts;
- $this->_aCmt = $oCmts->getCommentRow($iCmtId);
- $this->_aBp = $aBp;
- $this->_aDp = $aDp;
- $sJsObject = $oCmts->getJsObjectName();
- $this->addMarkers(array(
- 'js_object' => $sJsObject,
- 'cmt_system' => $this->_oCmts->getSystemName(),
- 'cmt_object_id' => $this->_oCmts->getId(),
- 'cmt_id' => $iCmtId,
- 'content_id' => $iCmtId,
- 'reply_onclick' => $sJsObject . '.toggleReply(this, ' . $iCmtId . ')',
- 'quote_onclick' => $sJsObject . '.toggleQuote(this, ' . $iCmtId . ')'
- ));
- }
- public function getMenuItems()
- {
- if((int)$this->_aCmt['cmt_pinned'] > 0 && !empty($this->_aBp['pinned']))
- $this->_aObject['menu_items'] = [
- 'item-unpin' => [
- 'name' => 'item-unpin',
- 'title' => '_sys_menu_item_title_cmts_item_unpin',
- 'link' => 'javascript:void(0)',
- 'onclick' => 'javascript:{js_object}.cmtPin(this, {content_id}, 0)',
- 'icon' => 'thumbtack'
- ]
- ];
- return parent::getMenuItems();
- }
- protected function _getMenuItemItemVote($aItem)
- {
- $oVote = $this->_oCmts->getVoteObject($this->_aCmt['cmt_unique_id']);
- if(!$oVote)
- return false;
- $aVotesParams = [
- 'dynamic_mode' => $this->_bDynamicMode,
- 'show_do_vote_label' => $this->_bShowTitles,
- 'show_counter' => $this->_bShowCounters,
- 'show_counter_label_icon' => $this->_bShowCountersIcons,
- ];
- switch($this->_sMode) {
- case self::$_sModeActions:
- $sVotesMethod = 'getElementInline';
- break;
- case self::$_sModeCounters:
- $sVotesMethod = 'getCounter';
- break;
- }
- return $oVote->$sVotesMethod($aVotesParams);
- }
- protected function _getMenuItemItemReaction($aItem)
- {
- $oReaction = $this->_oCmts->getReactionObject($this->_aCmt['cmt_unique_id']);
- if(!$oReaction)
- return false;
- $aReactionsParams = [
- 'dynamic_mode' => $this->_bDynamicMode,
- 'show_do_vote_label' => $this->_bShowTitles,
- 'show_counter' => $this->_bShowCounters,
- 'show_counter_style' => 'compound',
- 'show_counter_label_icon' => $this->_bShowCountersIcons,
- ];
- switch($this->_sMode) {
- case self::$_sModeActions:
- $sReactionsMethod = 'getElementInline';
- break;
- case self::$_sModeCounters:
- $sReactionsMethod = 'getCounter';
- break;
- }
- return $oReaction->$sReactionsMethod($aReactionsParams);
- }
- protected function _getMenuItemItemScore($aItem)
- {
- $oScore = $this->_oCmts->getScoreObject($this->_aCmt['cmt_unique_id']);
- if(!$oScore)
- return false;
- $aScoresParams = array(
- 'dynamic_mode' => $this->_bDynamicMode,
- 'show_do_vote_label' => $this->_bShowTitles,
- 'show_counter' => $this->_bShowCounters,
- 'show_counter_label_icon' => $this->_bShowCountersIcons,
- );
- switch($this->_sMode) {
- case self::$_sModeActions:
- $sScoresMethod = 'getElementInline';
- break;
- case self::$_sModeCounters:
- $sScoresMethod = 'getCounter';
- break;
- }
- return $oScore->$sScoresMethod($aScoresParams);
- }
- protected function _getMenuItemItemReport($aItem)
- {
- $oReport = $this->_oCmts->getReportObject($this->_aCmt['cmt_unique_id']);
- if(!$oReport)
- return false;
- $aReportParams = [
- 'dynamic_mode' => $this->_bDynamicMode,
- 'show_do_report_label' => $this->_bShowTitles,
- 'show_counter' => $this->_bShowCounters,
- ];
- return $oReport->getElementInline($aReportParams);
- }
- /**
- * Check if menu items is visible.
- * @param $a menu item array
- * @return boolean
- */
- protected function _isVisible ($a)
- {
- if(!parent::_isVisible($a))
- return false;
- if((int)$this->_aCmt['cmt_pinned'] > 0 && !empty($this->_aBp['pinned']) && $a['name'] != 'item-unpin')
- return false;
- $sCheckFuncName = '';
- $aCheckFuncParams = array();
- switch ($a['name']) {
- case 'item-reply':
- $sCheckFuncName = 'isReplyAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-quote':
- $sCheckFuncName = 'isQuoteAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-vote':
- $sCheckFuncName = 'isVoteAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-score':
- $sCheckFuncName = 'isScoreAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-report':
- $sCheckFuncName = 'isReportAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-pin':
- $sCheckFuncName = 'isPinAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-unpin':
- $sCheckFuncName = 'isUnpinAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-edit':
- $sCheckFuncName = 'isEditAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-delete':
- $sCheckFuncName = 'isRemoveAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- case 'item-more':
- $sCheckFuncName = 'isMoreAllowed';
- if(!empty($this->_aCmt))
- $aCheckFuncParams = array($this->_aCmt);
- break;
- }
- if(!$sCheckFuncName || !method_exists($this->_oCmts, $sCheckFuncName))
- return true;
- return call_user_func_array(array($this->_oCmts, $sCheckFuncName), $aCheckFuncParams);
- }
- }
- /** @} */
|