BxBaseScore.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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 BxDolScore
  11. */
  12. class BxBaseScore extends BxDolScore
  13. {
  14. protected $_bCssJsAdded;
  15. protected $_sJsObjName;
  16. protected $_sStylePrefix;
  17. protected $_aHtmlIds;
  18. protected $_sTmplNameLegend;
  19. protected $_sTmplNameByList;
  20. public function __construct($sSystem, $iId, $iInit = true, $oTemplate = false)
  21. {
  22. parent::__construct($sSystem, $iId, $iInit, $oTemplate);
  23. $this->_bCssJsAdded = false;
  24. $this->_sJsObjName = 'oScore' . bx_gen_method_name($sSystem, array('_' , '-')) . $iId;
  25. $this->_sStylePrefix = 'bx-score';
  26. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sSystem) . '-' . $iId;
  27. $this->_aHtmlIds = array(
  28. 'main' => 'bx-score-' . $sHtmlId,
  29. 'counter' => 'bx-score-counter-' . $sHtmlId,
  30. 'by_popup' => 'bx-score-by-popup-' . $sHtmlId,
  31. 'legend' => 'bx-score-legend-' . $sHtmlId,
  32. );
  33. $this->_aElementDefaults = [
  34. 'show_do_vote_as_button' => false,
  35. 'show_do_vote_as_button_small' => false,
  36. 'show_do_vote_icon' => true,
  37. 'show_do_vote_label' => false,
  38. 'show_counter' => true,
  39. 'show_counter_only' => true,
  40. 'show_counter_empty' => true,
  41. 'show_counter_style' => self::$_sCounterStyleSimple, //--- Alloved styles are 'simple', 'divided'
  42. 'show_counter_label_icon' => false,
  43. 'show_counter_label_text' => true,
  44. 'show_legend' => false,
  45. 'show_script' => true
  46. ];
  47. $this->_aElementDefaultsApi = array_merge($this->_aElementDefaults, [
  48. 'show_counter' => true,
  49. ]);
  50. $this->_aElementParamsApi = ['is_voted'];
  51. $this->_sTmplNameLegend = 'score_legend.html';
  52. $this->_sTmplNameByList = 'score_by_list.html';
  53. $this->_sTmplContentElementBlock = $this->_oTemplate->getHtml('score_element_block.html');
  54. $this->_sTmplContentElementInline = $this->_oTemplate->getHtml('score_element_inline.html');
  55. $this->_sTmplContentDoActionLabel = $this->_oTemplate->getHtml('score_do_vote_label.html');
  56. $this->_sTmplContentCounterLabel = $this->_oTemplate->getHtml('score_counter_label.html');
  57. }
  58. public function getJsObjectName()
  59. {
  60. return $this->_sJsObjName;
  61. }
  62. public function getJsScript($aParams = [])
  63. {
  64. $sJsObjName = $this->getJsObjectName();
  65. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  66. $aParamsJs = array(
  67. 'sObjName' => $sJsObjName,
  68. 'sSystem' => $this->getSystemName(),
  69. 'iAuthorId' => $this->_getAuthorId(),
  70. 'iObjId' => $this->getId(),
  71. 'sRootUrl' => BX_DOL_URL_ROOT,
  72. 'sSocket' => $this->getSocketName(),
  73. 'sStylePrefix' => $this->_sStylePrefix,
  74. 'aHtmlIds' => $this->_aHtmlIds,
  75. 'aRequestParams' => $this->_prepareRequestParamsData($aParams)
  76. );
  77. $sCode = "if(window['" . $sJsObjName . "'] == undefined) var " . $sJsObjName . " = new BxDolScore(" . json_encode($aParamsJs) . ");";
  78. return $this->_oTemplate->_wrapInTagJsCode($sCode);
  79. }
  80. public function getJsClick($sType)
  81. {
  82. return $this->getJsObjectName() . '.vote' . ucfirst($sType) . '(this)';
  83. }
  84. public function getJsClickCounter($aParams = [])
  85. {
  86. $sJsObject = $this->getJsObjectName();
  87. $sJsMethod = 'toggleByPopup';
  88. if(!isset($aParams['type'], $aParams['show_counter_style']) || $aParams['show_counter_style'] == self::$_sCounterStyleSimple)
  89. return $sJsObject . '.' . $sJsMethod . '(this)';
  90. return $sJsObject . '.' . $sJsMethod . '(this, \'' . $aParams['type'] . '\')';
  91. }
  92. public function getCounter($aParams = [])
  93. {
  94. $aParams = array_merge($this->_aElementDefaults, $aParams);
  95. $sDefault = $this->_aElementDefaults['show_counter_style'];
  96. $sCounterStyle = !empty($aParams['show_counter_style']) ? $aParams['show_counter_style'] : $sDefault;
  97. $sMethodPrefix = '_getCounter';
  98. $sMethod = $sMethodPrefix . bx_gen_method_name($sCounterStyle);
  99. if(!method_exists($this, $sMethod))
  100. $sMethod = $sMethodPrefix . bx_gen_method_name($sDefault);
  101. return $this->$sMethod($aParams);
  102. }
  103. public function _getCounterSimple($aParams = [])
  104. {
  105. $aScore = $this->_getVote();
  106. $iCup = (int)$aScore['count_up'];
  107. $iCdown = (int)$aScore['count_down'];
  108. return $this->_getCounterItem(array_merge($aParams, [
  109. 'allowed_view_voters' => $this->isAllowedVoteViewVoters(),
  110. 'value' => $iCup - $iCdown,
  111. 'value_empty' => $iCup == 0 && $iCdown == 0,
  112. ]));
  113. }
  114. public function _getCounterDivided($aParams = [])
  115. {
  116. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && (bool)$aParams['show_counter_empty'] === true;
  117. $bShowCounterOnly = isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true;
  118. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  119. $bAllowedViewVoters = $this->isAllowedVoteViewVoters();
  120. $bScore = $this->_isVote();
  121. $aScore = $this->_getVote();
  122. $aCounters = [
  123. BX_DOL_SCORE_DO_UP => (int)$aScore['count_up'],
  124. BX_DOL_SCORE_DO_DOWN => (int)$aScore['count_down']
  125. ];
  126. $sCounters = '';
  127. foreach($aCounters as $sType => $iValue)
  128. $sCounters .= $this->_getCounterItem(array_merge($aParams, [
  129. 'show_counter_label_icon' => $bShowCounterOnly,
  130. 'show_script' => false,
  131. 'allowed_view_voters' => $bAllowedViewVoters,
  132. 'type' => $sType,
  133. 'value_html_id' => $this->_aHtmlIds['counter'] . '-' . $sType,
  134. 'value' => $iValue,
  135. 'value_empty' => !$bScore,
  136. ]));
  137. return $this->_oTemplate->parseHtmlByName('score_counter_wrapper.html', [
  138. 'html_id' => $this->_aHtmlIds['counter'],
  139. 'style_prefix' => $this->_sStylePrefix,
  140. 'class' => $this->_aHtmlIds['counter'] . (!$bScore && !$bShowCounterEmpty ? ' bx-sc-hidden' : ''),
  141. 'style' => self::$_sCounterStyleDivided,
  142. 'counter' => $sCounters,
  143. 'script' => $bShowScript ? $this->getJsScript($aParams) : ''
  144. ]);
  145. }
  146. public function _getCounterItem($aParams = [])
  147. {
  148. $aParams = array_merge($this->_aElementDefaults, $aParams);
  149. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  150. $bShowEmpty = isset($aParams['show_counter_empty']) && (bool)$aParams['show_counter_empty'] === true;
  151. $bShowDoVoteAsButtonSmall = isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true;
  152. $bShowDoVoteAsButton = !$bShowDoVoteAsButtonSmall && isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true;
  153. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  154. $sClass = 'sys-action-counter';
  155. if(isset($aParams['show_counter_only']) && (bool)$aParams['show_counter_only'] === true)
  156. $sClass .= ' sys-ac-only';
  157. $sClass .= ' ' . $this->_sStylePrefix . '-counter';
  158. if($bShowDoVoteAsButtonSmall)
  159. $sClass .= ' bx-btn-small-height';
  160. if($bShowDoVoteAsButton)
  161. $sClass .= ' bx-btn-height';
  162. $bLink = $aParams['allowed_view_voters'] && !$aParams['value_empty'];
  163. $sCounter = !$aParams['value_empty'] || $bShowEmpty ? $this->_getCounterLabel($aParams['value'], $aParams) : '';
  164. $aTmplVarsText = [
  165. 'id' => isset($aParams['value_html_id']) ? $aParams['value_html_id'] : $this->_aHtmlIds['counter'],
  166. 'class' => $sClass,
  167. 'content' => $sCounter,
  168. 'title' => _t($this->_getTitleDoBy()),
  169. ];
  170. $aTmplVarsLink = array_merge($aTmplVarsText, [
  171. 'onclick' => $bLink ? 'javascript:' . $this->getJsClickCounter($aParams) : ''
  172. ]);
  173. return $this->_oTemplate->parseHtmlByName('score_counter.html', array(
  174. 'bx_if:show_link' => array(
  175. 'condition' => $bLink,
  176. 'content' => $aTmplVarsLink
  177. ),
  178. 'bx_if:show_text' => array(
  179. 'condition' => !$bLink,
  180. 'content' => $aTmplVarsText
  181. ),
  182. 'script' => $bShowScript ? $this->getJsScript($aParams) : ''
  183. ));
  184. }
  185. public function getCounterAPI($aParams = [])
  186. {
  187. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  188. return $this->_getVote();
  189. }
  190. public function getLegend($aParams = array())
  191. {
  192. $aLegend = $this->_oQuery->getLegend($this->_iId);
  193. $aTypes = array(
  194. BX_DOL_SCORE_DO_UP,
  195. BX_DOL_SCORE_DO_DOWN
  196. );
  197. $aTmplVarsItems = array();
  198. foreach($aTypes as $sType)
  199. $aTmplVarsItems[] = array(
  200. 'style_prefix' => $this->_sStylePrefix,
  201. 'value' => $this->_getLabelDo($sType, $aParams),
  202. 'label' => isset($aLegend[$sType]['count']) ? (int)$aLegend[$sType]['count'] : 0
  203. );
  204. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameLegend, array(
  205. 'style_prefix' => $this->_sStylePrefix,
  206. 'html_id' => $this->_aHtmlIds['legend'],
  207. 'bx_repeat:items' => $aTmplVarsItems
  208. ));
  209. }
  210. public function getElementBlock($aParams = array())
  211. {
  212. $aParams['usage'] = BX_DOL_SCORE_USAGE_BLOCK;
  213. return $this->getElement($aParams);
  214. }
  215. public function getElementInline($aParams = array())
  216. {
  217. $aParams['usage'] = BX_DOL_SCORE_USAGE_INLINE;
  218. return $this->getElement($aParams);
  219. }
  220. public function getElement($aParams = array())
  221. {
  222. $aParams = array_merge($this->_aElementDefaults, $aParams);
  223. $bShowDoVoteAsButtonSmall = isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true;
  224. $bShowDoVoteAsButton = !$bShowDoVoteAsButtonSmall && isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true;
  225. $bShowCounterEmpty = isset($aParams['show_counter_empty']) && (bool)$aParams['show_counter_empty'] === true;
  226. $bShowCounterSimple = $bShowCounterDivided = false;
  227. if(isset($aParams['show_counter_style'])) {
  228. if($aParams['show_counter_style'] == self::$_sCounterStyleSimple)
  229. $bShowCounterSimple = true;
  230. if($aParams['show_counter_style'] == self::$_sCounterStyleDivided)
  231. $bShowCounterDivided = true;
  232. }
  233. $iObjectId = $this->getId();
  234. $iAuthorId = $this->_getAuthorId();
  235. $iAuthorIp = $this->_getAuthorIp();
  236. $isAllowedVote = $this->isAllowedVote();
  237. $isAllowedVoteView = $this->isAllowedVoteView();
  238. $isAllowedVoteViewVoters = $this->isAllowedVoteViewVoters();
  239. $aScore = $this->_getVote();
  240. $bCount = $this->_isCount($aScore);
  241. $bCounter = $this->_isShowCounter($aParams, $isAllowedVote, $isAllowedVoteView, $bCount);
  242. $aParams['is_voted'] = $this->isPerformed($iObjectId, $iAuthorId, $iAuthorIp) ? true : false;
  243. //--- Do Vote
  244. $bTmplVarsDoVote = $this->_isShowDoVote($aParams, $isAllowedVote, $bCount);
  245. $aTmplVarsDoVoteUp = $aTmplVarsDoVoteDown = [];
  246. if($bTmplVarsDoVote)
  247. foreach([BX_DOL_SCORE_DO_UP, BX_DOL_SCORE_DO_DOWN] as $sType)
  248. ${'aTmplVarsDoVote' . ucfirst($sType)} = [
  249. 'style_prefix' => $this->_sStylePrefix,
  250. 'style' => $aParams['show_counter_style'],
  251. 'do_vote' => $this->_getDoVote($sType, $aParams, $isAllowedVote),
  252. 'bx_if:show_counter_' . $sType => [
  253. 'condition' => $bShowCounterDivided && $bCounter,
  254. 'content' => [
  255. 'style_prefix' => $this->_sStylePrefix,
  256. 'style' => $aParams['show_counter_style'],
  257. 'bx_if:show_c' . $sType . '_hidden' => [
  258. 'condition' => !$bShowCounterEmpty && !$bCount,
  259. 'content' => []
  260. ],
  261. 'counter' => $this->_getCounterItem(array_merge($aParams, [
  262. 'show_do_vote_as_button' => false,
  263. 'show_do_vote_as_button_small' => false,
  264. 'show_counter_only' => false,
  265. 'show_counter_label_icon' => false,
  266. 'show_script' => false,
  267. 'allowed_view_voters' => $isAllowedVoteViewVoters,
  268. 'type' => $sType,
  269. 'value_html_id' => $this->_aHtmlIds['counter'] . '-' . $sType,
  270. 'value' => isset($aScore['count_' . $sType]) ? (int)$aScore['count_' . $sType] : 0,
  271. 'value_empty' => !$bCount,
  272. ]))
  273. ]
  274. ]
  275. ];
  276. //--- Counter (Simple)
  277. $bTmplVarsCounter = $bShowCounterSimple && $bCounter;
  278. $aTmplVarsCounter = array();
  279. if($bTmplVarsCounter)
  280. $aTmplVarsCounter = array(
  281. 'style_prefix' => $this->_sStylePrefix,
  282. 'bx_if:show_hidden' => array(
  283. 'condition' => !$bShowCounterEmpty && !$bCount,
  284. 'content' => array()
  285. ),
  286. 'counter' => $this->getCounter(array_merge($aParams, [
  287. 'show_counter_only' => false,
  288. 'show_script' => false
  289. ]))
  290. );
  291. //--- Legend
  292. $bTmplVarsLegend = $this->_isShowLegend($aParams, $isAllowedVote, $isAllowedVoteView, $bCount);
  293. $aTmplVarsLegend = array();
  294. if($bTmplVarsLegend)
  295. $aTmplVarsLegend = array(
  296. 'legend' => $this->getLegend($aParams)
  297. );
  298. if(!$bTmplVarsDoVote && !$bTmplVarsCounter && !$bTmplVarsLegend)
  299. return '';
  300. $sTmplName = $this->{'_getTmplContentElement' . bx_gen_method_name(!empty($aParams['usage']) ? $aParams['usage'] : BX_DOL_SCORE_USAGE_DEFAULT)}();
  301. return $this->_oTemplate->parseHtmlByContent($sTmplName, array(
  302. 'style_prefix' => $this->_sStylePrefix,
  303. 'html_id' => $this->_aHtmlIds['main'],
  304. 'class' => $this->_sStylePrefix . ($bShowDoVoteAsButton ? '-button' : '') . ($bShowDoVoteAsButtonSmall ? '-button-small' : ''),
  305. 'score' => $aScore['score'],
  306. 'cup' => $aScore['count_up'],
  307. 'cdown' => $aScore['count_down'],
  308. 'bx_if:show_do_vote_up' => array(
  309. 'condition' => $bTmplVarsDoVote,
  310. 'content' => $aTmplVarsDoVoteUp
  311. ),
  312. 'bx_if:show_counter' => array(
  313. 'condition' => $bTmplVarsCounter,
  314. 'content' => $aTmplVarsCounter
  315. ),
  316. 'bx_if:show_do_vote_down' => array(
  317. 'condition' => $bTmplVarsDoVote,
  318. 'content' => $aTmplVarsDoVoteDown
  319. ),
  320. 'bx_if:show_legend' => array(
  321. 'condition' => $bTmplVarsLegend,
  322. 'content' => $aTmplVarsLegend
  323. ),
  324. 'script' => $this->getJsScript($aParams)
  325. ));
  326. }
  327. public function getElementAPI($aParams = [])
  328. {
  329. if(!($this->_bIsApi = bx_is_api()))
  330. return;
  331. if(!$this->isEnabled())
  332. return bx_api_get_msg('_sys_score_err_not_enabled');
  333. $aParams = array_merge($this->_aElementDefaultsApi, $aParams);
  334. $iObjectId = $this->getId();
  335. $iAuthorId = $this->_getAuthorId();
  336. $bCount = $this->_isCount();
  337. $isAllowedVote = $this->isAllowedVote();
  338. $isAllowedVoteView = $this->isAllowedVoteView();
  339. $aParams['is_voted'] = $this->isPerformed($iObjectId, $iAuthorId);
  340. $aParams['track'] = $aParams['is_voted'] ? $this->_getTrack($iObjectId, $iAuthorId) : [];
  341. //--- Do Vote
  342. $bDoVote = $this->_isShowDoVote($aParams, $isAllowedVote, $bCount);
  343. $aDoVoteUp = $bDoVote ? $this->_getDoVote(BX_DOL_SCORE_DO_UP, $aParams, $isAllowedVote) : [];
  344. $aDoVoteDown = $bDoVote ? $this->_getDoVote(BX_DOL_SCORE_DO_DOWN, $aParams, $isAllowedVote) : [];
  345. //--- Counter
  346. $bCounter = $this->_isShowCounter($aParams, $isAllowedVote, $isAllowedVoteView, $bCount);
  347. $aCounter = $bCounter ? $this->getCounterAPI(array_merge($aParams, [
  348. 'show_counter_only' => false,
  349. 'show_script' => false
  350. ])) : [];
  351. if(!$bDoVote && !$bCounter)
  352. return bx_api_get_msg('');
  353. return [
  354. 'type' => 'scores',
  355. 'system' => $this->_sSystem,
  356. 'object_id' => $this->_iId,
  357. 'ts' => microtime(true),
  358. 'params' => array_intersect_key($aParams, array_flip($this->_aElementParamsApi)),
  359. 'action' => [
  360. BX_DOL_SCORE_DO_UP => $aDoVoteUp,
  361. BX_DOL_SCORE_DO_DOWN => $aDoVoteDown
  362. ],
  363. 'counter' => $aCounter,
  364. ];
  365. }
  366. protected function _getDoVote($sType, $aParams = [], $isAllowedVote = true)
  367. {
  368. $bUndo = $this->isUndo();
  369. $bVoted = isset($aParams['is_voted']) && (bool)$aParams['is_voted'] === true;
  370. $bShowDoVoteAsButtonSmall = isset($aParams['show_do_vote_as_button_small']) && (bool)$aParams['show_do_vote_as_button_small'] === true;
  371. $bShowDoVoteAsButton = !$bShowDoVoteAsButtonSmall && isset($aParams['show_do_vote_as_button']) && (bool)$aParams['show_do_vote_as_button'] === true;
  372. $bDisabled = !$isAllowedVote || ($bVoted && !$bUndo);
  373. $sClass = '';
  374. if($bShowDoVoteAsButton)
  375. $sClass = 'bx-btn';
  376. else if ($bShowDoVoteAsButtonSmall)
  377. $sClass = 'bx-btn bx-btn-small';
  378. if($bDisabled)
  379. $sClass .= $bShowDoVoteAsButton || $bShowDoVoteAsButtonSmall ? ' bx-btn-disabled' : 'bx-score-disabled';
  380. if($this->_bIsApi)
  381. return [
  382. 'is_undo' => $bUndo,
  383. 'is_voted' => $bVoted,
  384. 'is_disabled' => $bDisabled,
  385. 'title' => _t($this->_getTitleDo($sType)),
  386. ];
  387. return $this->_oTemplate->parseLink('javascript:void(0)', $this->_getLabelDo($sType, $aParams), array(
  388. 'class' => $this->_sStylePrefix . '-do-vote ' . $this->_sStylePrefix . '-dv-' . $sType . ' ' . $sClass,
  389. 'title' => _t($this->_getTitleDo($sType)),
  390. 'onclick' => !$bDisabled ? $this->getJsClick($sType) : ''
  391. ));
  392. }
  393. protected function _getCounterLabel($iCount, $aParams = [])
  394. {
  395. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentCounterLabel(), array(
  396. 'style_prefix' => $this->_sStylePrefix,
  397. 'bx_if:show_icon' => array(
  398. 'condition' => !isset($aParams['show_counter_label_icon']) || (bool)$aParams['show_counter_label_icon'] === true,
  399. 'content' => array(
  400. 'style_prefix' => $this->_sStylePrefix,
  401. 'icon' => $this->_oTemplate->getImageAuto($this->_getIconDo(isset($aParams['type']) ? $aParams['type'] : ''))
  402. )
  403. ),
  404. 'bx_if:show_text' => array(
  405. 'condition' => !isset($aParams['show_counter_label_text']) || (bool)$aParams['show_counter_label_text'] === true,
  406. 'content' => array(
  407. 'style_prefix' => $this->_sStylePrefix,
  408. 'text' => _t('_sys_score_counter', $iCount)
  409. )
  410. )
  411. ));
  412. }
  413. protected function _getLabelDo($sType, $aParams = array())
  414. {
  415. return $this->_oTemplate->parseHtmlByContent($this->_getTmplContentDoActionLabel(), array(
  416. 'style_prefix' => $this->_sStylePrefix,
  417. 'bx_if:show_icon' => array(
  418. 'condition' => isset($aParams['show_do_vote_icon']) && (bool)$aParams['show_do_vote_icon'] === true,
  419. 'content' => array(
  420. 'style_prefix' => $this->_sStylePrefix,
  421. 'icon' => $this->_oTemplate->getImageAuto($this->_getIconDo($sType))
  422. )
  423. ),
  424. 'bx_if:show_text' => array(
  425. 'condition' => isset($aParams['show_do_vote_label']) && (bool)$aParams['show_do_vote_label'] === true,
  426. 'content' => array(
  427. 'style_prefix' => $this->_sStylePrefix,
  428. 'text' => _t($this->_getTitleDo($sType))
  429. )
  430. )
  431. ));
  432. }
  433. protected function _getVotedBy($aParams)
  434. {
  435. $aParams = array_merge($this->_aElementDefaults, $aParams, [
  436. 'show_do_vote_icon' => true,
  437. 'show_do_vote_label' => false
  438. ]);
  439. $aParamsDb = [];
  440. if(!empty($aParams['type']))
  441. $aParamsDb['type'] = $aParams['type'];
  442. $aUsers = $this->_oQuery->getPerformedBy($this->getId(), $aParamsDb);
  443. $aTmplUsers = [];
  444. foreach($aUsers as $aUser) {
  445. list($sUserName, $sUserLink, $sUserIcon, $sUserUnit, $sUserUnitWoInfo) = $this->_getAuthorInfo($aUser['id']);
  446. $aTmplUsers[] = [
  447. 'style_prefix' => $this->_sStylePrefix,
  448. 'user_name' => $sUserName,
  449. 'user_link' => $sUserLink,
  450. 'user_unit' => $sUserUnitWoInfo,
  451. 'vote' => $this->_getLabelDo($aUser['vote_type'], $aParams),
  452. 'date' => bx_time_js($aUser['vote_date']),
  453. ];
  454. }
  455. if(empty($aTmplUsers))
  456. $aTmplUsers = MsgBox(_t('_Empty'));
  457. return $this->_oTemplate->parseHtmlByName($this->_sTmplNameByList, [
  458. 'style_prefix' => $this->_sStylePrefix,
  459. 'bx_repeat:list' => $aTmplUsers
  460. ]);
  461. }
  462. protected function _isShowDoVote($aParams, $isAllowedVote, $bCount)
  463. {
  464. $bShowDoVote = !isset($aParams['show_do_vote']) || (bool)$aParams['show_do_vote'] === true;
  465. return $bShowDoVote && ($isAllowedVote || $bCount);
  466. }
  467. protected function _isShowCounter($aParams, $isAllowedVote, $isAllowedVoteView, $bCount)
  468. {
  469. return isset($aParams['show_counter']) && (bool)$aParams['show_counter'] === true && $isAllowedVoteView && ($isAllowedVote || $bCount);
  470. }
  471. protected function _isShowLegend($aParams, $isAllowedVote, $isAllowedVoteView, $bCount)
  472. {
  473. return isset($aParams['show_legend']) && (bool)$aParams['show_legend'] === true && $isAllowedVoteView;
  474. }
  475. }
  476. /** @} */