BxBaseVoteReactions.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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 BxDolVote, BxDolVoteLikes
  11. */
  12. class BxBaseVoteReactions extends BxDolVoteReactions
  13. {
  14. protected $_sTmplNameBySummary;
  15. protected $_sTmplContentCounterWrapper = '';
  16. public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  17. {
  18. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  19. $this->_sJsClsName .= 'Reactions';
  20. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  21. $this->_aHtmlIds = array_merge($this->_aHtmlIds, array(
  22. 'main' => 'bx-vr-' . $sHtmlId,
  23. 'do_menu' => 'bx-vr-do-menu-' . $sHtmlId,
  24. 'do_popup' => 'bx-vr-do-popup-' . $sHtmlId
  25. ));
  26. $this->_aElementDefaults = [
  27. 'show_do_vote_as_button' => false,
  28. 'show_do_vote_as_button_small' => false,
  29. 'show_do_vote_icon' => true,
  30. 'show_do_vote_label' => false,
  31. 'show_counter' => false,
  32. 'show_counter_only' => true,
  33. 'show_counter_empty' => true,
  34. 'show_counter_style' => self::$_sCounterStyleDivided, //--- Alloved styles are 'simple', 'divided' and 'compound'
  35. 'show_legend' => false,
  36. 'show_script' => true
  37. ];
  38. $this->_aElementDefaultsApi = array_merge($this->_aElementDefaults, [
  39. 'show_counter' => true,
  40. ]);
  41. $this->_sTmplNameBySummary = 'vote_by_summary_reactions.html';
  42. $this->_sTmplNameByList = 'vote_by_list_reactions.html';
  43. $this->_sTmplContentDoActionLabel = $this->_oTemplate->getHtml('vote_do_vote_label_reactions.html');
  44. $this->_sTmplContentCounterLabel = $this->_oTemplate->getHtml('vote_counter_label_reactions.html');
  45. $this->_sTmplContentCounterWrapper = $this->_oTemplate->getHtml('vote_counter_wrapper_reactions.html');
  46. }
  47. public function getJsClick($iValue = 0)
  48. {
  49. if(empty($iValue))
  50. $iValue = $this->getValue();
  51. $sResult = '';
  52. if($this->_bQuickMode)
  53. $sResult = $this->getJsClickDo($this->_aDataList[$this->_sDefault]['name'], $iValue);
  54. else
  55. $sResult = $this->getJsObjectName() . '.toggleDoPopup(this, ' . $iValue . ')';
  56. return $sResult;
  57. }
  58. public function getJsClickDo($sReaction, $iValue = 0)
  59. {
  60. if(empty($iValue))
  61. $iValue = $this->getValue();
  62. return $this->getJsObjectName() . '.vote(this, ' . $iValue . ', \'' . $sReaction . '\')';
  63. }
  64. public function getJsClickCounter($aParams = array())
  65. {
  66. $sJsObject = $this->getJsObjectName();
  67. $sJsMethod = 'toggleByPopup';
  68. if(isset($aParams['show_counter_style']) && in_array($aParams['show_counter_style'], array(self::$_sCounterStyleCompound, self::$_sCounterStyleSimple)))
  69. return $sJsObject . '.' . $sJsMethod . '(this)';
  70. $sReaction = !empty($aParams['reaction']) ? $aParams['reaction'] : $this->_sDefault;
  71. return $sJsObject . '.' . $sJsMethod . '(this, \'' . $sReaction . '\')';
  72. }
  73. public function getCounter($aParams = [])
  74. {
  75. $aParams = array_merge($this->_aElementDefaults, $aParams);
  76. $sDefault = $aParams['show_counter_style'];
  77. $sCounterStyle = !empty($aParams['show_counter_style']) ? $aParams['show_counter_style'] : $sDefault;
  78. $sMethodPrefix = '_getCounter';
  79. $sMethod = $sMethodPrefix . bx_gen_method_name($sCounterStyle);
  80. if(!method_exists($this, $sMethod))
  81. $sMethod = $sMethodPrefix . bx_gen_method_name($sDefault);
  82. return $this->$sMethod($aParams);
  83. }
  84. public function getCounterAPI($aParams = [])
  85. {
  86. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  87. $bVote = $this->_isVote();
  88. $aVote = $this->_getVote();
  89. $aReactions = $this->getReactions();
  90. $aItems = [];
  91. foreach($aReactions as $sName) {
  92. $iCount = (int)$aVote['count_' . $sName];
  93. $aItems[] = [
  94. 'name' => $sName,
  95. 'count' => $iCount,
  96. 'sum' => $aVote['sum_' . $sName],
  97. 'rate' => $aVote['rate_' . $sName],
  98. 'icon' => $this->getIcon($sName, false),
  99. 'emoji' => $this->getEmoji($sName),
  100. 'title' => _t($this->_aDataList[$sName]['title']),
  101. ];
  102. }
  103. $sStyle = !empty($aParams['show_counter_style']) ? $aParams['show_counter_style'] : $this->_aElementDefaults['show_counter_style'];
  104. return ['type' => $sStyle, 'items' => $aItems];
  105. }
  106. public function _getCounterSimple($aParams = array())
  107. {
  108. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  109. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && (bool)$aParams['show_counter_empty'] === true;
  110. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  111. $bVote = $this->_isVote();
  112. $aVote = $this->_getVote();
  113. $aReactions = $this->getReactions();
  114. $sClass = isset($aParams['class_counter']) ? $aParams['class_counter'] : '';
  115. if(isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true)
  116. $sClass .= ' bx-btn-small-height';
  117. else if(isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true)
  118. $sClass .= ' bx-btn-height';
  119. $aParams['id_counter'] = '';
  120. $iResultC = $iResultS = 0;
  121. foreach($aReactions as $sName) {
  122. $iResultC += (int)$aVote['count_' . $sName];
  123. $iResultS += (int)$aVote['sum_' . $sName];
  124. }
  125. $aParams = array_merge($aParams, array(
  126. 'show_counter_active' => false,
  127. 'show_counter_label_icon' => false,
  128. 'show_counter_label_text' => true,
  129. 'class_counter' => ' total-count ' . $sClass,
  130. 'reaction' => '',
  131. 'vote' => array(
  132. 'count' => $iResultC,
  133. 'sum' => $iResultS,
  134. 'rate' => $iResultC > 0 ? round($iResultS / $iResultC, 2) : 0,
  135. )
  136. ));
  137. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterWrapper(), array(
  138. 'html_id' => $this->_aHtmlIds['counter'],
  139. 'style_prefix' => $this->_sStylePrefix,
  140. 'class' => $this->_aHtmlIds['counter'] . (!$bVote && !$bShowCounterEmpty ? ' bx-vc-hidden' : ''),
  141. 'type' => $this->_sType,
  142. 'style' => self::$_sCounterStyleSimple,
  143. 'bx_if:show_link' => array(
  144. 'condition' => true,
  145. 'content' => array(
  146. 'href' => 'javascript:void(0)',
  147. 'onclick' => 'javascript:' . $this->getJsClickCounter($aParams),
  148. 'title' => bx_html_attribute($this->_getTitleDoBy($aParams)),
  149. 'counter' => parent::getCounter(array_merge($aParams, array('show_script' => false))),
  150. )
  151. ),
  152. 'bx_if:show_text' => array(
  153. 'condition' => false,
  154. 'content' => array()
  155. ),
  156. 'script' => $bShowScript ? $this->getJsScript($aParams) : ''
  157. ));
  158. }
  159. public function _getCounterDivided($aParams = array())
  160. {
  161. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  162. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && (bool)$aParams['show_counter_empty'] === true;
  163. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  164. $bVote = $this->_isVote();
  165. $aVote = $this->_getVote();
  166. $aReactions = $this->getReactions();
  167. $sClass = isset($aParams['class_counter']) ? $aParams['class_counter'] : '';
  168. if(isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true)
  169. $sClass .= ' bx-btn-small-height';
  170. else if(isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true)
  171. $sClass .= ' bx-btn-height';
  172. $sClass .= ' bx-def-margin-sec-right';
  173. $aParams['id_counter'] = '';
  174. $sResult = '';
  175. foreach($aReactions as $sName) {
  176. $iCount = (int)$aVote['count_' . $sName];
  177. $aParams['class_counter'] = ($iCount == 0 && (!$bShowCounterEmpty || $sName != $this->_sDefault || $bVote) ? ' bx-vc-hidden' : '') . ' ' . $sName . ' ' . $sClass;
  178. $aParams['reaction'] = $sName;
  179. $aParams['vote'] = array(
  180. 'count' => $iCount,
  181. 'sum' => $aVote['sum_' . $sName],
  182. 'rate' => $aVote['rate_' . $sName],
  183. );
  184. $sResult .= parent::getCounter(array_merge($aParams, array('show_script' => false)));
  185. }
  186. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterWrapper(), array(
  187. 'html_id' => $this->_aHtmlIds['counter'],
  188. 'style_prefix' => $this->_sStylePrefix,
  189. 'class' => $this->_aHtmlIds['counter'] . (!$bVote && !$bShowCounterEmpty ? ' bx-vc-hidden' : ''),
  190. 'type' => $this->_sType,
  191. 'style' => self::$_sCounterStyleDivided,
  192. 'bx_if:show_link' => array(
  193. 'condition' => false,
  194. 'content' => array()
  195. ),
  196. 'bx_if:show_text' => array(
  197. 'condition' => true,
  198. 'content' => array(
  199. 'counter' => $sResult,
  200. )
  201. ),
  202. 'script' => $bShowScript ? $this->getJsScript($aParams) : ''
  203. ));
  204. }
  205. public function _getCounterCompound($aParams = array())
  206. {
  207. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  208. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && (bool)$aParams['show_counter_empty'] === true;
  209. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  210. $bVote = $this->_isVote();
  211. $aVote = $this->_getVote();
  212. $aReactions = $this->getReactions();
  213. $sClass = isset($aParams['class_counter']) ? $aParams['class_counter'] : '';
  214. if(isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true)
  215. $sClass .= ' bx-btn-small-height';
  216. else if(isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true)
  217. $sClass .= ' bx-btn-height';
  218. $aParams['id_counter'] = '';
  219. $sResult = '';
  220. $iResultC = $iResultS = 0;
  221. foreach($aReactions as $sName) {
  222. $iCount = (int)$aVote['count_' . $sName];
  223. $aParams = array_merge($aParams, array(
  224. 'show_counter_active' => false,
  225. 'show_counter_label_icon' => true,
  226. 'show_counter_label_text' => false,
  227. 'class_counter' => ($iCount == 0 && (!$bShowCounterEmpty || $sName != $this->_sDefault || $bVote) ? ' bx-vc-hidden' : '') . ' ' . $sName . ' ' . $sClass,
  228. 'reaction' => $sName,
  229. 'vote' => array(
  230. 'count' => $iCount,
  231. 'sum' => $aVote['sum_' . $sName],
  232. 'rate' => $aVote['rate_' . $sName],
  233. )
  234. ));
  235. $iResultC += $iCount;
  236. $iResultS += (int)$aVote['sum_' . $sName];
  237. $sResult .= trim(parent::getCounter(array_merge($aParams, [
  238. 'show_script' => false
  239. ])));
  240. }
  241. $aParams = array_merge($aParams, array(
  242. 'show_counter_active' => false,
  243. 'show_counter_label_icon' => false,
  244. 'show_counter_label_text' => true,
  245. 'class_counter' => ' total-count ' . $sClass,
  246. 'reaction' => '',
  247. 'vote' => array(
  248. 'count' => $iResultC,
  249. 'sum' => $iResultS,
  250. 'rate' => $iResultC > 0 ? round($iResultS / $iResultC, 2) : 0,
  251. )
  252. ));
  253. $sResult .= parent::getCounter(array_merge($aParams, array('show_script' => false)));
  254. $sClassWrapper = 'sys-action-counter';
  255. if(isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true)
  256. $sClassWrapper .= ' sys-ac-only';
  257. $sClassWrapper .= ' ' . $this->_aHtmlIds['counter'] . (!$bVote && !$bShowCounterEmpty ? ' bx-vc-hidden' : '');
  258. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterWrapper(), array(
  259. 'html_id' => $this->_aHtmlIds['counter'],
  260. 'style_prefix' => $this->_sStylePrefix,
  261. 'class' => $sClassWrapper,
  262. 'type' => $this->_sType,
  263. 'style' => self::$_sCounterStyleCompound,
  264. 'bx_if:show_link' => array(
  265. 'condition' => true,
  266. 'content' => array(
  267. 'href' => 'javascript:void(0)',
  268. 'onclick' => 'javascript:' . $this->getJsClickCounter($aParams),
  269. 'title' => bx_html_attribute($this->_getTitleDoBy($aParams)),
  270. 'counter' => $sResult,
  271. )
  272. ),
  273. 'bx_if:show_text' => array(
  274. 'condition' => false,
  275. 'content' => array()
  276. ),
  277. 'script' => $bShowScript ? $this->getJsScript($aParams) : ''
  278. ));
  279. }
  280. public function getElement($aParams = array())
  281. {
  282. $sClass = $this->_sStylePrefix . '-' . $this->_sType;
  283. if(isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true)
  284. $sClass .= '-button-small';
  285. else if(isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true)
  286. $sClass .= '-button';
  287. $aParams['class_element'] = isset($aParams['class_element']) ? $aParams['class_element'] : '';
  288. $aParams['class_element'] .= ' ' . $sClass;
  289. return parent::getElement($aParams);
  290. }
  291. public function getElementAPI($aParams = [])
  292. {
  293. $aResult = parent::getElementAPI($aParams);
  294. if(($oDoVoteMenu = $this->_getDoVoteMenu()) !== false)
  295. $aResult['action']['menu'] = $oDoVoteMenu->getCodeAPI();
  296. return $aResult;
  297. }
  298. /**
  299. * Internal methods.
  300. */
  301. protected function _prepareParamsData($aParams)
  302. {
  303. return parent::_prepareParamsData(array_merge([
  304. 'bQuickMode' => $this->_bQuickMode
  305. ], $aParams));
  306. }
  307. protected function _isShowDoVote($aParams, $isAllowedVote, $bCount)
  308. {
  309. $bResult = parent::_isShowDoVote($aParams, $isAllowedVote, $bCount);
  310. if(!$bResult)
  311. return $bResult;
  312. return $isAllowedVote || $bCount;
  313. }
  314. protected function _getDoVote($aParams = array(), $isAllowedVote = true)
  315. {
  316. $bUndo = $this->isUndo();
  317. $bVoted = isset($aParams['is_voted']) && (bool)$aParams['is_voted'] === true;
  318. $bShowDoVoteAsButtonSmall = isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true;
  319. $bShowDoVoteAsButton = !$bShowDoVoteAsButtonSmall && isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true;
  320. $bDisabled = !$isAllowedVote || ($bVoted && !$bUndo);
  321. $sClass = '';
  322. if($bShowDoVoteAsButton)
  323. $sClass = ' bx-btn';
  324. else if ($bShowDoVoteAsButtonSmall)
  325. $sClass = ' bx-btn bx-btn-small';
  326. $iValue = 0;
  327. $sReaction = '';
  328. $sJsClick = '';
  329. if(!$bDisabled) {
  330. if($bVoted && $bUndo) {
  331. $sClass = ' ' . $this->_sStylePrefix . '-voted' . $sClass;
  332. $iValue = $aParams['track']['value'];
  333. $sReaction = $aParams['track']['reaction'];
  334. $sJsClick = $this->getJsClickDo($sReaction, $iValue);
  335. }
  336. else {
  337. $iValue = $this->getValue();
  338. $sReaction = $this->_aDataList[$this->_sDefault]['name'];
  339. $sJsClick = $this->getJsClick($iValue);
  340. }
  341. }
  342. else
  343. $sClass .= $bShowDoVoteAsButton || $bShowDoVoteAsButtonSmall ? ' bx-btn-disabled' : ' ' . $this->_sStylePrefix . '-disabled';
  344. if($this->_bApi)
  345. return [
  346. 'is_undo' => $bUndo,
  347. 'is_voted' => $bVoted,
  348. 'is_disabled' => $bDisabled,
  349. 'value' => $iValue,
  350. 'reaction' => $sReaction,
  351. 'icon' => ($sEmoji = $this->getEmoji($sReaction)) != '' ? $sEmoji : '',
  352. 'title' => _t($this->_getTitleDoWithTrack($bVoted, $aParams['track'])),
  353. ];
  354. return $this->_oTemplate->parseLink('javascript:void(0)', $this->_getDoVoteLabel($aParams), array(
  355. 'class' => $this->_sStylePrefix . '-do-vote' . $sClass,
  356. 'title' => _t($this->_getTitleDoWithTrack($bVoted, $aParams['track'])),
  357. 'onclick' => $sJsClick,
  358. 'bx-vote-reaction' => $sReaction,
  359. 'bx-vote-value' => $iValue,
  360. ));
  361. }
  362. protected function _getDoVoteLabel($aParams = array())
  363. {
  364. $bVoted = isset($aParams['is_voted']) && (bool)$aParams['is_voted'] === true;
  365. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoActionLabel(), array(
  366. 'style_prefix' => $this->_sStylePrefix,
  367. 'bx_if:show_icon' => array(
  368. 'condition' => isset($aParams['show_do_vote_icon']) && (bool)$aParams['show_do_vote_icon'] === true,
  369. 'content' => array(
  370. 'style_prefix' => $this->_sStylePrefix,
  371. 'name' => $this->_getIconDoWithTrack($bVoted, $aParams['track']),
  372. 'emoji' => $this->_getEmojiDoWithTrack($bVoted, $aParams['track'])
  373. )
  374. ),
  375. 'bx_if:show_text' => array(
  376. 'condition' => isset($aParams['show_do_vote_label']) && (bool)$aParams['show_do_vote_label'] === true,
  377. 'content' => array(
  378. 'style_prefix' => $this->_sStylePrefix,
  379. 'text' => _t($this->_getTitleDoWithTrack($bVoted, $aParams['track']))
  380. )
  381. )
  382. ));
  383. }
  384. public function _getDoVoteMenu($iValue = 0)
  385. {
  386. if(empty($iValue))
  387. $iValue = $this->getValue();
  388. $oMenu = BxTemplMenu::getObjectInstance($this->_sMenuDoVote);
  389. if(!$oMenu)
  390. return false;
  391. $oMenu->setParams(array(
  392. 'object' => &$this,
  393. 'value' => $iValue,
  394. ));
  395. return $oMenu;
  396. }
  397. public function _getDoVotePopup($iValue = 0)
  398. {
  399. $oMenu = $this->_getDoVoteMenu($iValue);
  400. if($oMenu === false)
  401. return '';
  402. return $oMenu->getCode();
  403. }
  404. protected function _getCounterLabel($iCount, $aParams = array())
  405. {
  406. $sReaction = !empty($aParams['reaction']) ? $aParams['reaction'] : $this->_sDefault;
  407. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterLabel(), array(
  408. 'style_prefix' => $this->_sStylePrefix,
  409. 'bx_if:show_icon' => array(
  410. 'condition' => !isset($aParams['show_counter_label_icon']) || (bool)$aParams['show_counter_label_icon'] === true,
  411. 'content' => array(
  412. 'style_prefix' => $this->_sStylePrefix,
  413. 'name' => $this->getIcon($sReaction),
  414. 'emoji' => $this->getEmoji($sReaction),
  415. 'title_attr' => bx_html_attribute(_t($this->_aDataList[$sReaction]['title'])),
  416. )
  417. ),
  418. 'bx_if:show_text' => array(
  419. 'condition' => !isset($aParams['show_counter_label_text']) || (bool)$aParams['show_counter_label_text'] === true,
  420. 'content' => array(
  421. 'style_prefix' => $this->_sStylePrefix,
  422. 'text' => parent::_getCounterLabel($iCount)
  423. )
  424. )
  425. ));
  426. }
  427. protected function _getVotedBy($aParams = array())
  428. {
  429. if(!isset($aParams['reaction']))
  430. return $this->_getVotedBySummary($aParams);
  431. $bSummary = $aParams['reaction'] == 'summary';
  432. $aBrowseParams = array('type' => 'by', 'object_id' => $this->getId());
  433. if(!$bSummary)
  434. $aBrowseParams['reaction'] = $aParams['reaction'];
  435. $aValues = $this->_oQuery->getPerformed($aBrowseParams);
  436. $aTmplUsers = array();
  437. foreach($aValues as $mValue) {
  438. $mValue = is_array($mValue) ? $mValue : array('author_id' => (int)$mValue, 'reaction' => '');
  439. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $this->_getAuthorInfo($mValue['author_id']);
  440. $aTmplUsers[] = array(
  441. 'style_prefix' => $this->_sStylePrefix,
  442. 'user_unit' => $sUserUnit,
  443. 'bx_if:show_reaction' => array(
  444. 'condition' => $bSummary,
  445. 'content' => array(
  446. 'style_prefix' => $this->_sStylePrefix,
  447. 'icon' => $bSummary ? $this->getIcon($mValue['reaction']) : '',
  448. 'emoji' => $bSummary ? $this->getEmoji($mValue['reaction']) : ''
  449. )
  450. )
  451. );
  452. }
  453. if(empty($aTmplUsers))
  454. $aTmplUsers = MsgBox(_t('_Empty'));
  455. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameByList, array(
  456. 'style_prefix' => $this->_sStylePrefix,
  457. 'class' => ' ' . $this->_sStylePrefix . '-bl-' . $aParams['reaction'],
  458. 'bx_repeat:list' => $aTmplUsers
  459. ));
  460. }
  461. protected function _getVotedBySummary($aParams = array())
  462. {
  463. $sJsObject = $this->getJsObjectName();
  464. $sTxtSummary = _t('_vote_do_by_summary');
  465. $aReactions = array_merge(array('summary'), $this->getReactions());
  466. $aMenuItems = array();
  467. $aTmplVarsLists = array();
  468. foreach ($aReactions as $sReaction) {
  469. if($sReaction == $this->_sDefault)
  470. continue;
  471. $bSummary = $sReaction == 'summary';
  472. $sName = $this->_sStylePrefix . '-' . $sReaction;
  473. $sEmoji = $this->getEmoji($sReaction);
  474. $sTitle = !$bSummary ? $this->_oTemplate->parseIcon($sEmoji ? $sEmoji : $this->getIcon($sReaction)) : $sTxtSummary;
  475. $sTitleAttr = !$bSummary ? _t('_vote_do_by_x_reaction', _t($this->_aDataList[$sReaction]['title'])) : $sTxtSummary;
  476. $aMenuItems[] = array('id' => $sName, 'name' => $sName, 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeVotedBy(this, \'' . $sReaction . '\')', 'target' => '_self', 'title' => $sTitle, 'title_attr' => $sTitleAttr, 'active' => 1);
  477. $aTmplVarsLists[] = array(
  478. 'content' => $this->_getVotedBy(array('reaction' => $sReaction))
  479. );
  480. }
  481. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $this->_sStylePrefix . '-voted-by', 'menu_items' => $aMenuItems));
  482. $oMenu->setSelected('', $this->_sStylePrefix . '-summary');
  483. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameBySummary, array(
  484. 'style_prefix' => $this->_sStylePrefix,
  485. 'title' => '',
  486. 'menu' => $oMenu->getCode(),
  487. 'bx_repeat:lists' => $aTmplVarsLists
  488. ));
  489. }
  490. protected function _getTmplContentCounterWrapper()
  491. {
  492. return $this->_sTmplContentCounterWrapper;
  493. }
  494. }
  495. /** @} */