BxBaseModProfileMenuViewActionsAll.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 _getMenuItemProfileRelations($aItem, $aParams = [])
  104. {
  105. return $this->_getMenuItemConnection($aItem, array_merge($aParams, [
  106. 'object' => 'sys_profiles_relations'
  107. ]));
  108. }
  109. protected function _getMenuItemProfileSubscriptions($aItem, $aParams = [])
  110. {
  111. return $this->_getMenuItemConnection($aItem, array_merge($aParams, [
  112. 'object' => 'sys_profiles_subscriptions'
  113. ]));
  114. }
  115. protected function _getMenuItemProfileFriendAdd($aItem)
  116. {
  117. if($this->_bIsApi)
  118. return $this->_getMenuItemConnectionApi('sys_profiles_friends', 'add', $aItem);
  119. return $this->_getMenuItemByNameActions($aItem);
  120. }
  121. protected function _getMenuItemProfileFriendRemove($aItem)
  122. {
  123. if($this->_bIsApi)
  124. return $this->_getMenuItemConnectionApi('sys_profiles_friends', 'remove', $aItem);
  125. return $this->_getMenuItemByNameActions($aItem);
  126. }
  127. protected function _getMenuItemProfileRelationAdd($aItem)
  128. {
  129. return $this->_getMenuItemByNameActions($aItem);
  130. }
  131. protected function _getMenuItemProfileRelationRemove($aItem)
  132. {
  133. return $this->_getMenuItemByNameActions($aItem);
  134. }
  135. protected function _getMenuItemProfileSubscribeAdd($aItem)
  136. {
  137. if($this->_bIsApi)
  138. return $this->_getMenuItemConnectionApi('sys_profiles_subscriptions', 'add', $aItem);
  139. return $this->_getMenuItemByNameActions($aItem);
  140. }
  141. protected function _getMenuItemProfileSubscribeRemove($aItem)
  142. {
  143. if($this->_bIsApi)
  144. return $this->_getMenuItemConnectionApi('sys_profiles_subscriptions', 'remove', $aItem);
  145. return $this->_getMenuItemByNameActions($aItem);
  146. }
  147. protected function _getMenuItemProfileSetBadges($aItem)
  148. {
  149. $aItem = $this->_getMenuItemByNameActions($aItem);
  150. if (!$aItem || !$this->_bIsApi)
  151. return $aItem;
  152. $oBadges = BxDolBadges::getInstance();
  153. $aBadges = $oBadges->getData(array('type' => 'by_module&object', 'object_id' => $this->_iContentId, 'module' => $this->_sModule));
  154. $aBadgesList = array_map(function ($aBadge) {
  155. return [
  156. "value" => $aBadge['id'],
  157. "label" => $aBadge['text'],
  158. "icon" => $aBadge['icon'],
  159. "color" => $aBadge['color'],
  160. "is_icon_only" => $aBadge['is_icon_only']
  161. ];
  162. }, $aBadges);
  163. $filteredBadges = array_filter($aBadges, function ($aBadge) {
  164. return isset($aBadge['badge_id']);
  165. });
  166. $badgeIds = array_values(array_map(function ($aBadge2) {
  167. return $aBadge2['id'];
  168. }, $filteredBadges));
  169. return array_merge($aItem, [
  170. 'display_type' => 'callback',
  171. 'content_type' => 'badges',
  172. 'data' => [
  173. 'content_id' => $this->_iContentId,
  174. 'module' => $this->_sModule,
  175. 'values' => $aBadgesList,
  176. 'value' => $badgeIds
  177. ]
  178. ]);
  179. }
  180. protected function _getMenuItemProfileSetAclLevel($aItem)
  181. {
  182. $aItem = $this->_getMenuItemByNameActions($aItem);
  183. if (!$aItem || !$this->_bIsApi)
  184. return $aItem;
  185. $oAcl = BxDolAcl::getInstance();
  186. $aAclLevels = $oAcl->getMembershipsBy(array('type' => 'all_active_not_automatic_pair'));
  187. $aProfileAclLevel = $oAcl->getMemberMembershipInfo($this->_oProfile->id());
  188. $aValues = [];
  189. foreach ($aAclLevels as $k => $s)
  190. $aValues[] = ['value' => $k, 'label' => _t($s)];
  191. return array_merge($aItem, [
  192. 'display_type' => 'callback',
  193. 'content_type' => 'memberships',
  194. 'data' => [
  195. 'profile_id' => $this->_oProfile->id(),
  196. 'values' => $aValues,
  197. 'value' => $aProfileAclLevel['id']
  198. ]
  199. ]);
  200. }
  201. protected function _getMenuItemView($aItem, $aParams = array())
  202. {
  203. return parent::_getMenuItemView($aItem, array_merge($aParams, [
  204. 'object_options' => ['show_counter' => false]
  205. ]));
  206. }
  207. protected function _getMenuItemComment($aItem, $aParams = array())
  208. {
  209. return parent::_getMenuItemComment($aItem, array_merge($aParams, [
  210. 'object_options' => ['show_counter' => false]
  211. ]));
  212. }
  213. protected function _getMenuItemVote($aItem, $aParams = array())
  214. {
  215. return parent::_getMenuItemVote($aItem, array_merge($aParams, [
  216. 'object_options' => ['show_counter' => false]
  217. ]));
  218. }
  219. protected function _getMenuItemReaction($aItem, $aParams = array())
  220. {
  221. return parent::_getMenuItemReaction($aItem, array_merge($aParams, [
  222. 'object_options' => ['show_counter' => false]
  223. ]));
  224. }
  225. protected function _getMenuItemScore($aItem, $aParams = array())
  226. {
  227. return parent::_getMenuItemScore($aItem, array_merge($aParams, [
  228. 'object_options' => ['show_counter' => false]
  229. ]));
  230. }
  231. protected function _getMenuItemMessenger($aItem, $aParams = array())
  232. {
  233. $aItem = BxTemplMenu::_getMenuItem($aItem);
  234. if($aItem === false)
  235. return false;
  236. if(!$this->_bIsApi)
  237. return $this->_getMenuItemDefault($aItem);
  238. $sModule = 'bx_messenger';
  239. $sMethod = 'find_convo';
  240. if(!bx_is_srv($sModule, $sMethod))
  241. return false;
  242. return [
  243. 'id' => $aItem['id'],
  244. 'name' => $aItem['name'],
  245. 'title' => $aItem['title'],
  246. 'display_type' => 'callback',
  247. 'data' => [
  248. 'request_url' => $sModule . '/get_convo_url/Services&params[]=' . json_encode(['recipient' => $this->_oProfile->id()]),
  249. 'on_callback' => 'redirect'
  250. ],
  251. 'primary' => $aItem['primary'],
  252. ];
  253. }
  254. }
  255. /** @} */