BxBaseModProfileMenuViewActionsAll.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * View entry all actions menu
  13. */
  14. class BxBaseModProfileMenuViewActionsAll extends BxBaseModGeneralMenuViewActions
  15. {
  16. protected $_oProfile;
  17. protected $_aProfileInfo;
  18. protected $_aConnectionToFunctionCheck;
  19. public function __construct($aObject, $oTemplate = false)
  20. {
  21. parent::__construct($aObject, $oTemplate);
  22. $this->_aConnectionToFunctionCheck = $this->_oModule->_oConfig->getConnectionToFunctionCheck();
  23. if(empty($this->_iContentId) && bx_get('profile_id') !== false)
  24. $this->setContentId(BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId());
  25. }
  26. public function setContentId($iContentId)
  27. {
  28. parent::setContentId($iContentId);
  29. $this->_oProfile = BxDolProfile::getInstanceByContentAndType($this->_iContentId, $this->_sModule);
  30. if(!$this->_oProfile)
  31. return;
  32. $this->_aProfileInfo = $this->_oProfile->getInfo();
  33. $this->addMarkers($this->_aProfileInfo);
  34. $this->addMarkers(array(
  35. 'profile_id' => $this->_oProfile->id()
  36. ));
  37. }
  38. protected function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile)
  39. {
  40. return '';
  41. }
  42. protected function _getMenuItemConnection($aItem, $aParams = [])
  43. {
  44. $sObject = !empty($aParams['object']) ? $aParams['object'] : 'sys_profiles_friends';
  45. $iId = !empty($aParams['id']) ? (int)$aParams['id'] : '';
  46. if(empty($iId))
  47. $iId = $this->_aProfileInfo['id'];
  48. $oObject = !empty($sObject) ? BxDolConnection::getObjectInstance($sObject) : false;
  49. if(!$oObject)
  50. return '';
  51. $aObjectOptions = [
  52. 'dynamic_mode' => $this->_bDynamicMode,
  53. 'show_do_as_button' => $this->_bShowAsButton,
  54. 'show_do_label' => $this->_bShowTitle
  55. ];
  56. if(!empty($aParams['object_options']) && is_array($aParams['object_options']))
  57. $aObjectOptions = array_merge($aObjectOptions, $aParams['object_options']);
  58. if($this->_bIsApi)
  59. return [
  60. 'id' => $aItem['id'],
  61. 'name' => $aItem['name'],
  62. 'display_type' => 'element',
  63. 'data' => $oObject->getElementApi($aObjectOptions)
  64. ];
  65. $sResult = $oObject->getElement($iId, false, $aObjectOptions);
  66. if(empty($sResult))
  67. return '';
  68. return [$sResult, $this->_sClassMiSa];
  69. }
  70. protected function _getMenuItemConnectionApi($sConnection, $sAction, &$aItem)
  71. {
  72. if(!isLogged() || (isset($this->_aConnectionToFunctionCheck[$sConnection]) && $this->_oModule->{$this->_aConnectionToFunctionCheck[$sConnection][$sAction]}($this->_aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED))
  73. return false;
  74. $iInitiatorProfile = bx_get_logged_profile_id();
  75. $iContentProfile = $this->_oProfile->id();
  76. $sTitle = $this->_oModule->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile);
  77. if(empty($sTitle))
  78. $sTitle = $this->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile);
  79. if(empty($sTitle))
  80. return false;
  81. return [
  82. 'id' => $aItem['id'],
  83. 'name' => $aItem['name'],
  84. 'title' => $sTitle,
  85. 'display_type' => 'element',
  86. 'data' => [
  87. 'type' => 'connections',
  88. 'o' => $sConnection,
  89. 'a' => $sAction,
  90. 'iid' => $iInitiatorProfile,
  91. 'cid' => $iContentProfile,
  92. 'title' => $sTitle,
  93. 'primary' => !empty($aItem['primary']),
  94. ]
  95. ];
  96. }
  97. protected function _getMenuItemProfileFriends($aItem, $aParams = [])
  98. {
  99. return $this->_getMenuItemConnection($aItem, array_merge($aParams, [
  100. 'object' => 'sys_profiles_friends'
  101. ]));
  102. }
  103. protected function _getMenuItemProfileSubscriptions($aItem, $aParams = [])
  104. {
  105. return $this->_getMenuItemConnection($aItem, array_merge($aParams, [
  106. 'object' => 'sys_profiles_subscriptions'
  107. ]));
  108. }
  109. protected function _getMenuItemProfileFriendAdd($aItem)
  110. {
  111. if($this->_bIsApi)
  112. return $this->_getMenuItemConnectionApi('sys_profiles_friends', 'add', $aItem);
  113. return $this->_getMenuItemByNameActions($aItem);
  114. }
  115. protected function _getMenuItemProfileFriendRemove($aItem)
  116. {
  117. if($this->_bIsApi)
  118. return $this->_getMenuItemConnectionApi('sys_profiles_friends', 'remove', $aItem);
  119. return $this->_getMenuItemByNameActions($aItem);
  120. }
  121. protected function _getMenuItemProfileRelationAdd($aItem)
  122. {
  123. return $this->_getMenuItemByNameActions($aItem);
  124. }
  125. protected function _getMenuItemProfileRelationRemove($aItem)
  126. {
  127. return $this->_getMenuItemByNameActions($aItem);
  128. }
  129. protected function _getMenuItemProfileSubscribeAdd($aItem)
  130. {
  131. if($this->_bIsApi)
  132. return $this->_getMenuItemConnectionApi('sys_profiles_subscriptions', 'add', $aItem);
  133. return $this->_getMenuItemByNameActions($aItem);
  134. }
  135. protected function _getMenuItemProfileSubscribeRemove($aItem)
  136. {
  137. if($this->_bIsApi)
  138. return $this->_getMenuItemConnectionApi('sys_profiles_subscriptions', 'remove', $aItem);
  139. return $this->_getMenuItemByNameActions($aItem);
  140. }
  141. protected function _getMenuItemProfileSetBadges($aItem)
  142. {
  143. $aItem = $this->_getMenuItemByNameActions($aItem);
  144. if (!$aItem || !$this->_bIsApi)
  145. return $aItem;
  146. $oBadges = BxDolBadges::getInstance();
  147. $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => $this->_iContentId, 'module' => $this->_sModule));
  148. $aBadgesList = array_map(function ($aBadge) {
  149. return [
  150. "value" => $aBadge['id'],
  151. "label" => $aBadge['text']
  152. ];
  153. }, $aBadges);
  154. $filteredBadges = array_filter($aBadges, function ($aBadge) {
  155. return isset($aBadge['badge_id']);
  156. });
  157. $badgeIds = array_values(array_map(function ($aBadge2) {
  158. return $aBadge2['id'];
  159. }, $filteredBadges));
  160. return array_merge($aItem, [
  161. 'display_type' => 'callback',
  162. 'content_type' => 'badges',
  163. 'data' => [
  164. 'content_id' => $this->_iContentId,
  165. 'module' => $this->_sModule,
  166. 'values' => $aBadgesList,
  167. 'value' => $badgeIds
  168. ]
  169. ]);
  170. }
  171. protected function _getMenuItemProfileSetAclLevel($aItem)
  172. {
  173. $aItem = $this->_getMenuItemByNameActions($aItem);
  174. if (!$aItem || !$this->_bIsApi)
  175. return $aItem;
  176. $oAcl = BxDolAcl::getInstance();
  177. $aAclLevels = $oAcl->getMembershipsBy(array('type' => 'all_active_not_automatic_pair'));
  178. $aProfileAclLevel = $oAcl->getMemberMembershipInfo($this->_oProfile->id());
  179. $aValues = [];
  180. foreach ($aAclLevels as $k => $s)
  181. $aValues[] = ['value' => $k, 'label' => _t($s)];
  182. return array_merge($aItem, [
  183. 'display_type' => 'callback',
  184. 'content_type' => 'memberships',
  185. 'data' => [
  186. 'profile_id' => $this->_oProfile->id(),
  187. 'values' => $aValues,
  188. 'value' => $aProfileAclLevel['id']
  189. ]
  190. ]);
  191. }
  192. protected function _getMenuItemView($aItem, $aParams = array())
  193. {
  194. return parent::_getMenuItemView($aItem, array_merge($aParams, [
  195. 'object_options' => ['show_counter' => false]
  196. ]));
  197. }
  198. protected function _getMenuItemComment($aItem, $aParams = array())
  199. {
  200. return parent::_getMenuItemComment($aItem, array_merge($aParams, [
  201. 'object_options' => ['show_counter' => false]
  202. ]));
  203. }
  204. protected function _getMenuItemVote($aItem, $aParams = array())
  205. {
  206. return parent::_getMenuItemVote($aItem, array_merge($aParams, [
  207. 'object_options' => ['show_counter' => false]
  208. ]));
  209. }
  210. protected function _getMenuItemReaction($aItem, $aParams = array())
  211. {
  212. return parent::_getMenuItemReaction($aItem, array_merge($aParams, [
  213. 'object_options' => ['show_counter' => false]
  214. ]));
  215. }
  216. protected function _getMenuItemScore($aItem, $aParams = array())
  217. {
  218. return parent::_getMenuItemScore($aItem, array_merge($aParams, [
  219. 'object_options' => ['show_counter' => false]
  220. ]));
  221. }
  222. protected function _getMenuItemMessenger($aItem, $aParams = array())
  223. {
  224. $aItem = BxTemplMenu::_getMenuItem($aItem);
  225. if($aItem === false)
  226. return false;
  227. if(!$this->_bIsApi)
  228. return $this->_getMenuItemDefault($aItem);
  229. $sModule = 'bx_messenger';
  230. $sMethod = 'find_convo';
  231. if(!bx_is_srv($sModule, $sMethod))
  232. return false;
  233. return [
  234. 'id' => $aItem['id'],
  235. 'name' => $aItem['name'],
  236. 'title' => $aItem['title'],
  237. 'display_type' => 'callback',
  238. 'data' => [
  239. 'request_url' => $sModule . '/get_convo_url/Services&params[]=' . json_encode(['recipient' => $this->_oProfile->id()]),
  240. 'on_callback' => 'redirect'
  241. ],
  242. 'primary' => $aItem['primary'],
  243. ];
  244. }
  245. }
  246. /** @} */