| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseProfile Base classes for profile modules
- * @ingroup UnaModules
- *
- * @{
- */
- /**
- * View entry all actions menu
- */
- class BxBaseModProfileMenuViewActionsAll extends BxBaseModGeneralMenuViewActions
- {
- protected $_oProfile;
- protected $_aProfileInfo;
- protected $_aConnectionToFunctionCheck;
- public function __construct($aObject, $oTemplate = false)
- {
- parent::__construct($aObject, $oTemplate);
- $this->_aConnectionToFunctionCheck = $this->_oModule->_oConfig->getConnectionToFunctionCheck();
- if(empty($this->_iContentId) && bx_get('profile_id') !== false)
- $this->setContentId(BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId());
- }
-
- public function setContentId($iContentId)
- {
- parent::setContentId($iContentId);
- $this->_oProfile = BxDolProfile::getInstanceByContentAndType($this->_iContentId, $this->_sModule);
- if(!$this->_oProfile)
- return;
- $this->_aProfileInfo = $this->_oProfile->getInfo();
- $this->addMarkers($this->_aProfileInfo);
- $this->addMarkers(array(
- 'profile_id' => $this->_oProfile->id()
- ));
- }
- protected function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile)
- {
- return '';
- }
- protected function _getMenuItemConnection($aItem, $aParams = [])
- {
- $sObject = !empty($aParams['object']) ? $aParams['object'] : 'sys_profiles_friends';
- $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
- if(empty($iId))
- $iId = $this->_aProfileInfo['id'];
- $oObject = !empty($sObject) ? BxDolConnection::getObjectInstance($sObject) : false;
- if(!$oObject)
- return '';
- $aObjectOptions = [
- 'dynamic_mode' => $this->_bDynamicMode,
- 'show_do_as_button' => $this->_bShowAsButton,
- 'show_do_label' => $this->_bShowTitle
- ];
- if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
- $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
- if($this->_bIsApi)
- return [
- 'id' => $aItem['id'],
- 'name' => $aItem['name'],
- 'display_type' => 'element',
- 'data' => $oObject->getElementApi($aObjectOptions)
- ];
- $sResult = $oObject->getElement($iId, false, $aObjectOptions);
- if(empty($sResult))
- return '';
- return [$sResult, $this->_sClassMiSa];
- }
- protected function _getMenuItemConnectionApi($sConnection, $sAction, &$aItem)
- {
- if(!isLogged() || (isset($this->_aConnectionToFunctionCheck[$sConnection]) && $this->_oModule->{$this->_aConnectionToFunctionCheck[$sConnection][$sAction]}($this->_aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED))
- return false;
- $iInitiatorProfile = bx_get_logged_profile_id();
- $iContentProfile = $this->_oProfile->id();
- $sTitle = $this->_oModule->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile);
-
- if(empty($sTitle))
- $sTitle = $this->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile);
- if(empty($sTitle))
- return false;
-
- return [
- 'id' => $aItem['id'],
- 'name' => $aItem['name'],
- 'title' => $sTitle,
- 'display_type' => 'element',
- 'data' => [
- 'type' => 'connections',
- 'o' => $sConnection,
- 'a' => $sAction,
- 'iid' => $iInitiatorProfile,
- 'cid' => $iContentProfile,
- 'title' => $sTitle,
- 'primary' => !empty($aItem['primary']),
- ]
- ];
- }
- protected function _getMenuItemProfileFriends($aItem, $aParams = [])
- {
- return $this->_getMenuItemConnection($aItem, array_merge($aParams, [
- 'object' => 'sys_profiles_friends'
- ]));
- }
- protected function _getMenuItemProfileSubscriptions($aItem, $aParams = [])
- {
- return $this->_getMenuItemConnection($aItem, array_merge($aParams, [
- 'object' => 'sys_profiles_subscriptions'
- ]));
- }
- protected function _getMenuItemProfileFriendAdd($aItem)
- {
- if($this->_bIsApi)
- return $this->_getMenuItemConnectionApi('sys_profiles_friends', 'add', $aItem);
- return $this->_getMenuItemByNameActions($aItem);
- }
- protected function _getMenuItemProfileFriendRemove($aItem)
- {
- if($this->_bIsApi)
- return $this->_getMenuItemConnectionApi('sys_profiles_friends', 'remove', $aItem);
- return $this->_getMenuItemByNameActions($aItem);
- }
- protected function _getMenuItemProfileRelationAdd($aItem)
- {
- return $this->_getMenuItemByNameActions($aItem);
- }
- protected function _getMenuItemProfileRelationRemove($aItem)
- {
- return $this->_getMenuItemByNameActions($aItem);
- }
- protected function _getMenuItemProfileSubscribeAdd($aItem)
- {
- if($this->_bIsApi)
- return $this->_getMenuItemConnectionApi('sys_profiles_subscriptions', 'add', $aItem);
-
- return $this->_getMenuItemByNameActions($aItem);
- }
- protected function _getMenuItemProfileSubscribeRemove($aItem)
- {
- if($this->_bIsApi)
- return $this->_getMenuItemConnectionApi('sys_profiles_subscriptions', 'remove', $aItem);
- return $this->_getMenuItemByNameActions($aItem);
- }
- protected function _getMenuItemProfileSetBadges($aItem)
- {
- $aItem = $this->_getMenuItemByNameActions($aItem);
- if (!$aItem || !$this->_bIsApi)
- return $aItem;
-
- $oBadges = BxDolBadges::getInstance();
- $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => $this->_iContentId, 'module' => $this->_sModule));
-
- $aBadgesList = array_map(function ($aBadge) {
- return [
- "value" => $aBadge['id'],
- "label" => $aBadge['text']
- ];
- }, $aBadges);
-
- $filteredBadges = array_filter($aBadges, function ($aBadge) {
- return isset($aBadge['badge_id']);
- });
- $badgeIds = array_values(array_map(function ($aBadge2) {
- return $aBadge2['id'];
- }, $filteredBadges));
- return array_merge($aItem, [
- 'display_type' => 'callback',
- 'content_type' => 'badges',
- 'data' => [
- 'content_id' => $this->_iContentId,
- 'module' => $this->_sModule,
- 'values' => $aBadgesList,
- 'value' => $badgeIds
- ]
- ]);
- }
-
- protected function _getMenuItemProfileSetAclLevel($aItem)
- {
- $aItem = $this->_getMenuItemByNameActions($aItem);
- if (!$aItem || !$this->_bIsApi)
- return $aItem;
-
- $oAcl = BxDolAcl::getInstance();
- $aAclLevels = $oAcl->getMembershipsBy(array('type' => 'all_active_not_automatic_pair'));
- $aProfileAclLevel = $oAcl->getMemberMembershipInfo($this->_oProfile->id());
- $aValues = [];
- foreach ($aAclLevels as $k => $s)
- $aValues[] = ['value' => $k, 'label' => _t($s)];
- return array_merge($aItem, [
- 'display_type' => 'callback',
- 'content_type' => 'memberships',
- 'data' => [
- 'profile_id' => $this->_oProfile->id(),
- 'values' => $aValues,
- 'value' => $aProfileAclLevel['id']
- ]
- ]);
- }
- protected function _getMenuItemView($aItem, $aParams = array())
- {
- return parent::_getMenuItemView($aItem, array_merge($aParams, [
- 'object_options' => ['show_counter' => false]
- ]));
- }
- protected function _getMenuItemComment($aItem, $aParams = array())
- {
- return parent::_getMenuItemComment($aItem, array_merge($aParams, [
- 'object_options' => ['show_counter' => false]
- ]));
- }
- protected function _getMenuItemVote($aItem, $aParams = array())
- {
- return parent::_getMenuItemVote($aItem, array_merge($aParams, [
- 'object_options' => ['show_counter' => false]
- ]));
- }
- protected function _getMenuItemReaction($aItem, $aParams = array())
- {
- return parent::_getMenuItemReaction($aItem, array_merge($aParams, [
- 'object_options' => ['show_counter' => false]
- ]));
- }
- protected function _getMenuItemScore($aItem, $aParams = array())
- {
- return parent::_getMenuItemScore($aItem, array_merge($aParams, [
- 'object_options' => ['show_counter' => false]
- ]));
- }
- protected function _getMenuItemMessenger($aItem, $aParams = array())
- {
- $aItem = BxTemplMenu::_getMenuItem($aItem);
- if($aItem === false)
- return false;
- if(!$this->_bIsApi)
- return $this->_getMenuItemDefault($aItem);
- $sModule = 'bx_messenger';
- $sMethod = 'find_convo';
- if(!bx_is_srv($sModule, $sMethod))
- return false;
- return [
- 'id' => $aItem['id'],
- 'name' => $aItem['name'],
- 'title' => $aItem['title'],
- 'display_type' => 'callback',
- 'data' => [
- 'request_url' => $sModule . '/get_convo_url/Services¶ms[]=' . json_encode(['recipient' => $this->_oProfile->id()]),
- 'on_callback' => 'redirect'
- ],
- 'primary' => $aItem['primary'],
- ];
- }
- }
- /** @} */
|