1
0

BxBaseModProfileMenuViewActionsAll.php 10 KB

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