BxBaseConnection.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxBaseConnection
  11. */
  12. class BxBaseConnection extends BxDolConnection
  13. {
  14. protected $_oTemplate;
  15. protected $_oFunctions;
  16. protected $_sStylePrefix;
  17. protected $_sJsObjName;
  18. protected $_sHp;
  19. protected $_aHtmlIds;
  20. protected $_aT;
  21. protected $_sTmplContentElement;
  22. protected $_sTmplContentCounter;
  23. protected $_aElementDefaults;
  24. public function __construct($aObject)
  25. {
  26. parent::__construct($aObject);
  27. $this->_oTemplate = BxDolTemplate::getInstance();
  28. $this->_oFunctions = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate);
  29. $this->_sStylePrefix = 'bx-conn';
  30. $this->_sJsObjName = 'oConn' . bx_gen_method_name($this->_sObject, ['_' , '-']) . '';
  31. $this->_sHp = str_replace('_', '-', $this->_sObject);
  32. $this->_aHtmlIds = [
  33. 'main' => 'bx-conn-' . $this->_sHp . '-',
  34. 'do_popup' => 'bx-conn-do-popup-' . $this->_sHp . '-',
  35. 'do_menu' => 'bx-conn-do-menu-' . $this->_sHp . '-',
  36. 'counter' => 'bx-conn-counter-' . $this->_sHp . '-',
  37. 'by_popup' => 'bx-conn-by-popup-' . $this->_sHp . '-',
  38. ];
  39. $this->_aT = [
  40. 'do_by' => '_sys_conn_do_by'
  41. ];
  42. $this->_sTmplContentElement = $this->_oTemplate->getHtml('connection_element.html');
  43. $this->_sTmplContentCounter = $this->_oTemplate->getHtml('connection_counter.html');
  44. $this->_aElementDefaults = [
  45. 'uniq_id' => '',
  46. 'dynamic_mode' => true,
  47. 'show_do_as_button_small' => false,
  48. 'show_do_as_button' => false,
  49. 'show_do_icon' => true,
  50. 'show_do_label' => true,
  51. 'show_counter' => false,
  52. 'show_counter_label_with_profiles' => true,
  53. 'show_script' => true
  54. ];
  55. }
  56. public function actionGetConnected ($iStart = 0, $iPerPage = 0)
  57. {
  58. $sContentType = bx_process_input(bx_get('content_type'));
  59. $iProfileId = (int)bx_get('id');
  60. $bIsMutual = (bool)bx_get('mutual');
  61. $aRequestParamsData = $this->_getRequestParamsData();
  62. return $this->_getConnected ($sContentType, $iProfileId, $bIsMutual, $iStart, $iPerPage, $aRequestParamsData);
  63. }
  64. public function actionGetUsers ($iStart = 0, $iPerPage = 0)
  65. {
  66. $sContentType = bx_process_input(bx_get('content_type'));
  67. $iProfileId = (int)bx_get('id');
  68. $bIsMutual = (bool)bx_get('mutual');
  69. $iStart = (int)bx_get('start');
  70. $iPerPage = (int)bx_get('per_page');
  71. $aRequestParamsData = $this->_getRequestParamsData();
  72. return [
  73. 'content' => $this->_getConnected($sContentType, $iProfileId, $bIsMutual, $iStart, $iPerPage, $aRequestParamsData),
  74. 'eval' => $this->getJsObjectName($iProfileId, $aRequestParamsData) . '.onGetUsers(oData)'
  75. ];
  76. }
  77. public function getJsObjectName($iProfileId, $aParams = [])
  78. {
  79. return $this->_sJsObjName . (!empty($aParams['uniq_id']) ? $aParams['uniq_id'] : '') . $iProfileId;
  80. }
  81. public function getElement($iContent, $iInitiator = false, $aParams = [])
  82. {
  83. $aParams = $this->_prepareParamsData($aParams);
  84. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  85. $bShowDo = !isset($aParams['show_do']) || (bool)$aParams['show_do'] === true;
  86. $bShowDoAsButtonSmall = isset($aParams['show_do_as_button_small']) && (bool)$aParams['show_do_as_button_small'] === true;
  87. $bShowDoAsButton = !$bShowDoAsButtonSmall && isset($aParams['show_do_as_button']) && (bool)$aParams['show_do_as_button'] === true;
  88. $bShowDoLabel = isset($aParams['show_do_label']) && (bool)$aParams['show_do_label'] === true;
  89. $bShowCounter = isset($aParams['show_counter']) && (bool)$aParams['show_counter'] === true;
  90. if(!$iInitiator)
  91. $iInitiator = bx_get_logged_profile_id();
  92. if($iInitiator && $iInitiator == $iContent)
  93. return '';
  94. $aActions = $this->_getActions($iInitiator, $iContent, $aParams);
  95. $iCount = $this->_getCounterCount($iContent, $this->_bMutual, $aParams);
  96. if((empty($aActions['items']) || !is_array($aActions['items'])) && (!$bShowCounter || !$iCount))
  97. return '';
  98. $sJsObject = $this->getJsObjectName($iContent, $aParams);
  99. $sClassDo = '';
  100. if($bShowDoAsButton)
  101. $sClassDo = ' bx-btn';
  102. else if ($bShowDoAsButtonSmall)
  103. $sClassDo = ' bx-btn bx-btn-small';
  104. $aTmplVarsAction = $aTmplVarsActions = [];
  105. if(count($aActions['items']) == 1) {
  106. $aAction = reset($aActions['items']);
  107. $aTmplVarsAction = array_merge([
  108. 'style_prefix' => $this->_sStylePrefix,
  109. 'js_object' => $sJsObject,
  110. 'class' => $sClassDo,
  111. 'action' => $aAction['name'],
  112. 'profile_id' => $iContent,
  113. 'title' => $bShowDoLabel && !empty($aAction['title']) ? _t($aAction['title']) : ''
  114. ], $this->_getTmplVarsAction($aAction, $aParams));
  115. }
  116. else {
  117. $sHtmlIdDoPopup = $this->_aHtmlIds['do_popup'] . $iContent;
  118. $sHtmlIdDoMenu = $this->_aHtmlIds['do_menu'] . $iContent;
  119. $aMenuItems = [];
  120. foreach($aActions['items'] as $aItem)
  121. if(!empty($aItem) && is_array($aItem)) {
  122. if(!isset($aItem['link'], $aItem['onclick']))
  123. $aMenuItems[] = [
  124. 'id' => $aItem['name'],
  125. 'name' => $aItem['name'],
  126. 'icon' => $this->_getActionIcon($aItem, $aParams),
  127. 'link' => 'javascript:void(0)',
  128. 'onclick' => "javascript:" . $sJsObject . ".connect(this, '" . $aItem['name'] . "', " . $iContent . ")",
  129. 'target' => '_self',
  130. 'title' => !empty($aItem['title']) ? _t($aItem['title']) : '',
  131. 'active' => 1
  132. ];
  133. else
  134. $aMenuItems[] = $aItem;
  135. }
  136. $oMenu = new BxTemplMenu(['template' => 'menu_vertical.html', 'menu_id'=> $sHtmlIdDoMenu, 'menu_items' => $aMenuItems]);
  137. $aTmplVarsActions = array_merge([
  138. 'style_prefix' => $this->_sStylePrefix,
  139. 'js_object' => $sJsObject,
  140. 'class' => $sClassDo,
  141. 'profile_id' => $iContent,
  142. 'do_popup' => $this->_oFunctions->transBox($sHtmlIdDoPopup, $oMenu->getCode(), true),
  143. ], $this->_getTmplVarsAction([
  144. 'name' => $aActions['name'],
  145. 'title' => $bShowDoLabel && !empty($aActions['title']) ? $aActions['title'] : ''
  146. ], $aParams));
  147. }
  148. $bTmplVarsAction = !empty($aTmplVarsAction) && is_array($aTmplVarsAction);
  149. $bTmplVarsActions = !empty($aTmplVarsActions) && is_array($aTmplVarsActions);
  150. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentElement(), [
  151. 'style_prefix' => $this->_sStylePrefix,
  152. 'html_id' => $this->_aHtmlIds['main'] . $iContent,
  153. 'class' => $this->_sStylePrefix . ($bShowDoAsButton ? '-button' : '-link') . ($bShowDoAsButtonSmall ? '-button-small' : ''),
  154. 'bx_if:show_do' => [
  155. 'condition' => $bShowDo && ($bTmplVarsAction || $bTmplVarsActions),
  156. 'content' => [
  157. 'style_prefix' => $this->_sStylePrefix,
  158. 'bx_if:show_action' => [
  159. 'condition' => $bTmplVarsAction,
  160. 'content' => $aTmplVarsAction
  161. ],
  162. 'bx_if:show_actions' => [
  163. 'condition' => $bTmplVarsActions,
  164. 'content' => $aTmplVarsActions
  165. ],
  166. ]
  167. ],
  168. 'bx_if:show_counter' => [
  169. 'condition' => $bShowCounter && $iCount,
  170. 'content' => [
  171. 'style_prefix' => $this->_sStylePrefix,
  172. 'counter' => $this->getCounter($iContent, $this->_bMutual, array_merge($aParams, ['count' => $iCount]))
  173. ]
  174. ],
  175. 'script' => $this->_getJsScript($iContent, $this->_bMutual, $aParams)
  176. ]);
  177. }
  178. public function getElementAPI($iContent, $iInitiator = false, $aParams = [])
  179. {
  180. if(!($this->_bIsApi = bx_is_api()))
  181. return;
  182. if(!$iInitiator && (!($iInitiator = bx_get_logged_profile_id()) || $iInitiator == $iContent))
  183. return [];
  184. $aActions = $this->_getActions($iInitiator, $iContent, $aParams);
  185. if((empty($aActions['items']) || !is_array($aActions['items'])))
  186. return [];
  187. $aName = $aActions['name'] ?? '';
  188. $sTitle = $aActions['title'] ?? '';
  189. $aActions = $aActions['items'];
  190. if(count($aActions) == 1) {
  191. list($aName, $sTitle) = array_values(reset($aActions));
  192. $aActions = [];
  193. }
  194. else {
  195. foreach($aActions as $iKey => $aAction)
  196. if(!$aAction || !isset($aAction['name'], $aAction['title']))
  197. unset($aActions[$iKey]);
  198. else
  199. $aActions[$iKey]['title'] = _t($aAction['title']);
  200. }
  201. return [
  202. 'type' => 'connections_ext',
  203. 'o' => $this->_sObject,
  204. 'iid' => $iInitiator,
  205. 'cid' => $iContent,
  206. 'name' => $aName,
  207. 'title' => _t($sTitle),
  208. 'actions' => $aActions,
  209. ];
  210. }
  211. public function getCounter($iProfileId, $bIsMutual = false, $aParams = [])
  212. {
  213. $aParams = $this->_prepareParamsData($aParams);
  214. if(!$iProfileId)
  215. $iProfileId = bx_get_logged_profile_id();
  216. if($this->_aObject['type'] != 'mutual')
  217. $bIsMutual = false;
  218. $iCount = !empty($aParams['count']) ? $aParams['count'] : $this->_getCounterCount($iProfileId, $bIsMutual, $aParams);
  219. if(!$iCount)
  220. return '';
  221. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  222. $bShowDoAsButtonSmall = isset($aParams['show_do_as_button_small']) && (bool)$aParams['show_do_as_button_small'] === true;
  223. $bShowDoAsButton = !$bShowDoAsButtonSmall && isset($aParams['show_do_as_button']) && (bool)$aParams['show_do_as_button'] === true;
  224. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  225. $sJsObject = $this->getJsObjectName($iProfileId, $aParams);
  226. $sClass = $this->_sStylePrefix . '-counter';
  227. if($bShowDoAsButtonSmall)
  228. $sClass .= ' bx-btn-small-height';
  229. if($bShowDoAsButton)
  230. $sClass .= ' bx-btn-height';
  231. $sHtmlIdCounter = $this->_aHtmlIds['counter'] . $iProfileId;
  232. $sContent = $this->_getCounterLabel($iCount, $iProfileId, $bIsMutual, $aParams);
  233. $this->_oTemplate->addCss(['connection.css']);
  234. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounter(), [
  235. 'html_id' => $sHtmlIdCounter,
  236. 'style_prefix' => $this->_sStylePrefix,
  237. 'bx_if:show_text' => [
  238. 'condition' => false,
  239. 'content' => [
  240. 'class' => $sClass,
  241. 'bx_repeat:attrs' => [
  242. ['key' => 'id', 'value' => $sHtmlIdCounter],
  243. ],
  244. 'content' => $sContent
  245. ]
  246. ],
  247. 'bx_if:show_link' => [
  248. 'condition' => true,
  249. 'content' => [
  250. 'class' => $sClass,
  251. 'bx_repeat:attrs' => [
  252. ['key' => 'id', 'value' => $sHtmlIdCounter],
  253. ['key' => 'href', 'value' => 'javascript:void(0)'],
  254. ['key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this)'],
  255. ['key' => 'title', 'value' => _t('_sys_conn_do_by')]
  256. ],
  257. 'content' => $sContent
  258. ]
  259. ],
  260. 'script' => $bShowScript ? $this->_getJsScript($iProfileId, $bIsMutual, $aParams) : ''
  261. ]);
  262. }
  263. public function getCounterAPI($iProfileId, $bIsMutual = false, $aParams = [])
  264. {
  265. $sContentType = ($sKey = 'content_type') && isset($aParams[$sKey]) ? $aParams[$sKey] : BX_CONNECTIONS_CONTENT_TYPE_INITIATORS;
  266. $iCount = $this->{'getConnected' . ($sContentType == BX_CONNECTIONS_CONTENT_TYPE_INITIATORS ? 'Initiators' : 'Content') . 'Count'}($iProfileId, $bIsMutual);
  267. return [
  268. 'count' => $iCount,
  269. 'countf' => _t(isset($aParams['caption']) ? $aParams['caption'] : $this->_aT['counter'], $iCount)
  270. ];
  271. }
  272. public function getConnectedListAPI($iProfileId, $bIsMutual, $sContentType, $iCount = BX_CONNECTIONS_LIST_COUNTER)
  273. {
  274. $aProfiles = [];
  275. $aIds = $this->{BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType ? 'getConnectedInitiators' : 'getConnectedContent'}($iProfileId, $bIsMutual, 0, $iCount);
  276. foreach($aIds as $iId)
  277. if(($oProfile = BxDolProfile::getInstanceMagic($iId)) !== false)
  278. $aProfiles[] = $oProfile->getUnitAPI(0, ['template' => 'unit_wo_info']);
  279. return $aProfiles;
  280. }
  281. public function getCommonListAPI($iProfileId1, $iProfileId2, $bIsMutual, $iCount = BX_CONNECTIONS_LIST_COUNTER)
  282. {
  283. $aProfiles = [];
  284. $aIds = $this->getCommonContent($iProfileId1, $iProfileId2, $bIsMutual, 0, $iCount);
  285. foreach($aIds as $iId)
  286. if(($oProfile = BxDolProfile::getInstanceMagic($iId)) !== false)
  287. $aProfiles[] = $oProfile->getUnitAPI(0, ['template' => 'unit_wo_info']);
  288. return $aProfiles;
  289. }
  290. protected function _action($iInitiator, $iContent, $sMethod, $sErrorKey, $isMutual = false, $isInvert = false)
  291. {
  292. $aResult = parent::_action($iInitiator, $iContent, $sMethod, $sErrorKey, $isMutual, $isInvert);
  293. if(!$aResult['err'] && ($sOut = bx_get('out')) !== false && $sOut == 'eval') {
  294. $aRequestParamsData = $this->_getRequestParamsData();
  295. $aResult = array_merge($aResult, [
  296. 'data' => $this->getElement($this->_iContent, $this->_iInitiator, $aRequestParamsData),
  297. 'eval' => $this->getJsObjectName($this->_iContent, $aRequestParamsData) . '.onConnect(oData)',
  298. ]);
  299. }
  300. return $aResult;
  301. }
  302. protected function _getJsScript($iContentId, $bIsMutual = false, $aParams = [])
  303. {
  304. $sJsObject = $this->getJsObjectName($iContentId, $aParams);
  305. $aParamsJs = [
  306. 'sSystem' => $this->_sObject,
  307. 'iContentId' => $iContentId,
  308. 'bIsMutual' => $bIsMutual ? 1 : 0,
  309. 'sObjName' => $sJsObject,
  310. 'sRootUrl' => BX_DOL_URL_ROOT,
  311. 'sStylePrefix' => $this->_sStylePrefix,
  312. 'aHtmlIds' => $this->_aHtmlIds,
  313. 'aRequestParams' => $this->_prepareRequestParamsData($aParams)
  314. ];
  315. if(($sKey = 'content_type') && !empty($aParams[$sKey]))
  316. $aParamsJs['sContentType'] = $aParams[$sKey];
  317. $sCode = "if(window['" . $sJsObject . "'] == undefined) var " . $sJsObject . " = new BxDolConnection(" . json_encode($aParamsJs) . ");";
  318. return $this->_oTemplate->_wrapInTagJsCode($sCode);
  319. }
  320. protected function _getCounterCount($iProfileId, $bIsMutual, $aParams = [])
  321. {
  322. $sContentType = ($sKey = 'content_type') && isset($aParams[$sKey]) ? $aParams[$sKey] : BX_CONNECTIONS_CONTENT_TYPE_INITIATORS;
  323. return $this->{'getConnected' . ($sContentType == BX_CONNECTIONS_CONTENT_TYPE_INITIATORS ? 'Initiators' : 'Content') . 'Count'}($iProfileId, $bIsMutual);
  324. }
  325. protected function _getCounterLabel($iCount, $iProfileId, $bIsMutual, $aParams)
  326. {
  327. if ('mutual' != $this->_aObject['type'])
  328. $bIsMutual = false;
  329. $sContentType = ($sKey = 'content_type') && isset($aParams[$sKey]) ? $aParams[$sKey] : BX_CONNECTIONS_CONTENT_TYPE_INITIATORS;
  330. $bShowWithProfiles = isset($aParams['show_counter_label_with_profiles']) && $aParams['show_counter_label_with_profiles'] === true;
  331. $bShowWithIcon = (!isset($aParams['show_counter_label_icon']) || $aParams['show_counter_label_icon'] === true) && !$bShowWithProfiles;
  332. $aTmplVarsWithProfiles = [];
  333. if($bShowWithProfiles) {
  334. $aTmplVarsWithProfiles = [
  335. 'style_prefix' => $this->_sStylePrefix,
  336. 'bx_repeat:profiles' => []
  337. ];
  338. $aIds = $this->{'getConnected' . (BX_CONNECTIONS_CONTENT_TYPE_INITIATORS == $sContentType ? 'Initiators' : 'Content')}($iProfileId, $bIsMutual, 0, BX_CONNECTIONS_LIST_COUNTER);
  339. foreach($aIds as $iId)
  340. if(($oProfile = BxDolProfile::getInstanceMagic($iId)) !== false)
  341. $aTmplVarsWithProfiles['bx_repeat:profiles'][] = [
  342. 'style_prefix' => $this->_sStylePrefix,
  343. 'unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info_links', 'size' => 'icon']])
  344. ];
  345. }
  346. return $this->_oTemplate->parseHtmlByName('connection_counter_label.html', array(
  347. 'style_prefix' => $this->_sStylePrefix,
  348. 'bx_if:show_icon' => array(
  349. 'condition' => $bShowWithIcon,
  350. 'content' => array(
  351. 'style_prefix' => $this->_sStylePrefix,
  352. 'name' => isset($aParams['custom_icon']) && $aParams['custom_icon'] != '' ? $aParams['custom_icon'] : $this->_oFunctions->getFontIconAsHtml($this->_getIconDo())
  353. )
  354. ),
  355. 'bx_if:show_profiles' => array(
  356. 'condition' => $bShowWithProfiles,
  357. 'content' => $aTmplVarsWithProfiles
  358. ),
  359. 'bx_if:show_text' => array(
  360. 'condition' => !isset($aParams['show_counter_label_text']) || $aParams['show_counter_label_text'] === true,
  361. 'content' => array(
  362. 'style_prefix' => $this->_sStylePrefix,
  363. 'text' => _t(isset($aParams['caption']) ? $aParams['caption'] : $this->_aT['counter'], $iCount)
  364. )
  365. )
  366. ));
  367. }
  368. protected function _getIconDo()
  369. {
  370. if ($this->_sObject == 'sys_profiles_subscriptions')
  371. return 'user-friends';
  372. if (strpos($this->_sObject, 'fan'))
  373. return 'users';
  374. }
  375. public function _getConnected ($sContentType, $iProfileId, $bIsMutual, $iStart = 0, $iPerPage = 0, $aParams = [])
  376. {
  377. if ('mutual' != $this->_aObject['type'])
  378. $bIsMutual = false;
  379. if(empty($iPerPage))
  380. $iPerPage = $this->_aObject['per_page_default'];
  381. $aUsers = $this->getConnectionsAsArray($sContentType, $iProfileId, null, $bIsMutual, $iStart, $iPerPage + 1);
  382. $oPaginate = new BxTemplPaginate([
  383. 'on_change_page' => $this->getJsObjectName($iProfileId, $aParams) . '.getUsers(this, {start}, {per_page})',
  384. 'start' => $iStart,
  385. 'per_page' => $iPerPage,
  386. ]);
  387. $oPaginate->setNumFromDataArray($aUsers);
  388. foreach($aUsers as $iProfile) {
  389. $oProfile = BxDolProfile::getInstanceMagic($iProfile);
  390. $aTmplUsers[] = [
  391. 'style_prefix' => $this->_sStylePrefix,
  392. 'user_unit' => $oProfile->getUnit(0, ['template' => 'unit_wo_info']),
  393. 'user_url' => $oProfile->getUrl(),
  394. 'user_title' => bx_html_attribute($oProfile->getDisplayName()),
  395. 'user_name' => $oProfile->getDisplayName()
  396. ];
  397. }
  398. if(empty($aTmplUsers))
  399. $aTmplUsers = MsgBox(_t('_Empty'));
  400. return $this->_oTemplate->parseHtmlByName('connected_by_list.html', [
  401. 'style_prefix' => $this->_sStylePrefix,
  402. 'bx_repeat:list' => $aTmplUsers,
  403. 'paginate' => $oPaginate->getSimplePaginate()
  404. ]);
  405. }
  406. protected function _getAuthorInfo($iAuthorId = 0)
  407. {
  408. $oProfile = $this->_getAuthorObject($iAuthorId);
  409. return array(
  410. $oProfile->getDisplayName(),
  411. $oProfile->getUrl(),
  412. $oProfile->getThumb(),
  413. $oProfile->getUnit(),
  414. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  415. );
  416. }
  417. protected function _getActions($iInitiator, $iContent, $aParams = [])
  418. {
  419. return [];
  420. }
  421. protected function _getActionIcon($aAction, $aParams = [])
  422. {
  423. return !empty($aAction['name']) ? $this->{'_getActionIconAs' . bx_gen_method_name($this->_useIconAs($aParams))}($aAction['name']) : '';
  424. }
  425. protected function _useIconAs($aParams = [])
  426. {
  427. if(!empty($aParams['use_icon_as']) && in_array($aParams['use_icon_as'], ['icon', 'emoji', 'image']))
  428. return $aParams['use_icon_as'];
  429. return 'icon';
  430. }
  431. protected function _getTmplContentElement()
  432. {
  433. return $this->_sTmplContentElement;
  434. }
  435. protected function _getTmplContentCounter()
  436. {
  437. return $this->_sTmplContentCounter;
  438. }
  439. protected function _getTmplVarsAction($aAction, $aParams = [])
  440. {
  441. $sIcon = $this->_getActionIcon($aAction, $aParams);
  442. return [
  443. 'bx_if:show_icon' => [
  444. 'condition' => !empty($sIcon),
  445. 'content' => [
  446. 'style_prefix' => $this->_sStylePrefix,
  447. 'icon' => $this->_oTemplate->getImageAuto($sIcon)
  448. ]
  449. ],
  450. 'bx_if:show_text' => [
  451. 'condition' => !empty($aAction['title']),
  452. 'content' => [
  453. 'style_prefix' => $this->_sStylePrefix,
  454. 'text' => _t($aAction['title'])
  455. ]
  456. ]
  457. ];
  458. }
  459. protected function _prepareParamsData($aParams)
  460. {
  461. $aResult = $this->_aElementDefaults;
  462. if(!empty($aParams) && is_array($aParams))
  463. $aResult = array_merge($aResult, $aParams);
  464. return $aResult;
  465. }
  466. protected function _getRequestParamsData($aKeys = [])
  467. {
  468. $sParams = bx_get('params');
  469. if($sParams === false)
  470. return [];
  471. $aParams = [];
  472. parse_str(bx_process_input($sParams), $aParams);
  473. return $aParams;
  474. }
  475. protected function _prepareRequestParamsData($aParams, $aParamsAdd = [])
  476. {
  477. $aRequestParams = array_intersect_key($aParams, $this->_aElementDefaults);
  478. $aRequestParams = array_merge($aRequestParams, $aParamsAdd);
  479. foreach($aRequestParams as $sKey => $mixedValue)
  480. if(is_bool($mixedValue))
  481. $aRequestParams[$sKey] = (int)$mixedValue;
  482. return $aRequestParams;
  483. }
  484. }