| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Reputation Reputation
- * @ingroup UnaModules
- *
- * @{
- */
- class BxReputationTemplate extends BxBaseModNotificationsTemplate
- {
- public function __construct(&$oConfig, &$oDb)
- {
- parent::__construct($oConfig, $oDb);
- }
- public function getBlockLevels()
- {
- $oFunctions = BxTemplFunctions::getInstance();
- $aLevels = $this->_oDb->getLevels([
- 'sample' => 'all',
- 'active' => true
- ]);
- $aTmplVarsLevels = [];
- foreach($aLevels as $aLevel) {
- list($sIconFont, $sIconUrl, $sIconA, $sIconHtml) = $oFunctions->getIcon($aLevel['icon']);
- $bIconFont = !empty($sIconFont);
- $bIconHtml = !empty($sIconHtml);
- $aTmplVarsLevels[] = array_merge([
- 'id' => $aLevel['id'],
- 'name' => $aLevel['name'],
- 'title' => _t($aLevel['title']),
- 'icon' => $aLevel['icon'],
- 'points_in' => (int)$aLevel['points_in'],
- 'points_out' => (int)$aLevel['points_out'],
- ], (!$this->_bIsApi ? [
- 'bx_if:icon' => [
- 'condition' => $bIconFont || $bIconHtml,
- 'content' => [
- 'bx_if:icon_font' => [
- 'condition' => $bIconFont,
- 'content' => [
- 'icon' => $sIconFont
- ]
- ],
- 'bx_if:icon_html' => [
- 'condition' => $bIconHtml,
- 'content' => [
- 'icon' => $sIconHtml
- ]
- ],
- ]
- ],
- 'points' => _t('_bx_reputation_txt_from_to', (int)$aLevel['points_in'], (int)$aLevel['points_out'])
- ] : [
- 'icon' => $bIconHtml ? $sIconHtml : ''
- ]));
- }
- return $this->parseHtmlByName('block_levels.html', [
- 'bx_repeat:levels' => $aTmplVarsLevels
- ]);
- }
- public function getBlockSummary($iProfileId)
- {
- $CNF = &$this->_oConfig->CNF;
- $oProfile = BxDolProfile::getInstance($iProfileId);
- if(!$oProfile)
- return false;
- $aProfileInfo = $this->_oDb->getProfiles(['sample' => 'id', 'id' => $iProfileId]);
- $bProfileInfo = !empty($aProfileInfo) && is_array($aProfileInfo);
- $aProfileLevels = $this->_oDb->getLevels([
- 'sample' => 'profile_id',
- 'profile_id' => $iProfileId
- ]);
- $oFunctions = BxTemplFunctions::getInstance();
- $aTmplVarsLevels = [];
- foreach($aProfileLevels as $aProfileLevel) {
- list($sIconFont, $sIconUrl, $sIconA, $sIconHtml) = $oFunctions->getIcon($aProfileLevel['icon']);
- $bIconFont = !empty($sIconFont);
- $bIconHtml = !empty($sIconHtml);
- $sTitle = _t($aProfileLevel['title']);
- $aTmplVarsLevels[] = !$this->_bIsApi ? [
- 'bx_if:icon' => [
- 'condition' => $bIconFont || $bIconHtml,
- 'content' => [
- 'bx_if:icon_font' => [
- 'condition' => $bIconFont,
- 'content' => [
- 'icon' => $sIconFont
- ]
- ],
- 'bx_if:icon_html' => [
- 'condition' => $bIconHtml,
- 'content' => [
- 'icon' => $sIconHtml
- ]
- ],
- ]
- ],
- 'title' => $sTitle
- ] : [
- 'name' => $aProfileLevel['name'],
- 'title' => $sTitle,
- 'icon' => $bIconHtml ? $sIconHtml : '',
- ];
- }
- $iProfilePoints = $bProfileInfo ? (int)$aProfileInfo['points'] : 0;
-
- if($this->_bIsApi)
- return [
- bx_api_get_block('reputation_summary', [
- 'author_data' => BxDolProfile::getData($iProfileId),
- 'points' => $iProfilePoints,
- 'levels' => $aTmplVarsLevels,
- ])
- ];
- return $this->parseHtmlByName('block_summary.html', [
- 'profile_image' => $oProfile->getUnit($iProfileId, ['template' => ['name' => 'unit_wo_info', 'size' => 'ava']]),
- 'profile_name' => $oProfile->getDisplayName(),
- 'points' => $iProfilePoints,
- 'history_url' => BxDolPermalinks::getInstance()->permalink($CNF['URL_HISTORY']),
- 'bx_repeat:levels' => $aTmplVarsLevels
- ]);
- }
- public function getBlockHistory($iProfileId, $iStart = 0, $iLimit = 0)
- {
- $CNF = &$this->_oConfig->CNF;
- $oModule = $this->getModule();
- if(!$iLimit)
- $iLimit = (int)getParam($CNF['PARAM_HISTORY_LIMIT']);
- $aItems = $this->_oDb->getEvents([
- 'sample' => 'owner_id',
- 'owner_id' => $iProfileId,
- 'start' => $iStart,
- 'limit' => $iLimit + 1
- ]);
- $aTmplVarsItems = [];
- foreach($aItems as $aItem) {
- $aTmplVarsItems[] = [
- 'unit' => $oModule->getUnitTitle($aItem['type']),
- 'action' => $oModule->getActionTitle($aItem['action']),
- 'points' => ($iPoints = (int)$aItem['points']) > 0 ? '+' . $iPoints : $iPoints,
- 'date' => bx_time_js($aItem['date'])
- ];
- }
- if($this->_bIsApi)
- return $aTmplVarsItems;
- $oPaginate = new BxTemplPaginate([
- 'start' => $iStart,
- 'per_page' => $iLimit,
- 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}')"
- ]);
- $oPaginate->setNumFromDataArray($aTmplVarsItems);
- $sPaginate = $oPaginate->getSimplePaginate();
- return $this->parseHtmlByName('block_history.html', [
- 'bx_repeat:items' => $aTmplVarsItems,
- 'bx_if:show_paginate' => [
- 'condition' => !empty($sPaginate),
- 'content' => [
- 'paginate' => $sPaginate
- ]
- ]
- ]);
- }
- public function getBlockLeaderboard($iDays = 0, $iLimit = 0)
- {
- $CNF = &$this->_oConfig->CNF;
-
- if(!$iLimit)
- $iLimit = (int)getParam($CNF['PARAM_LEADERBOARD_LIMIT']);
- $bGrowth = $iDays > 0;
- if($bGrowth)
- $aItems = $this->_oDb->getEvents(['sample' => 'stats', 'days' => $iDays, 'limit' => $iLimit]);
- else
- $aItems = $this->_oDb->getProfiles(['sample' => 'stats', 'limit' => $iLimit]);
- $aTmplVarsProfiles = [];
- foreach($aItems as $iProfileId => $iPoints)
- if($iPoints != 0 && ($iProfileId = abs($iProfileId)) && ($oProfile = BxDolProfile::getInstance($iProfileId)) !== false)
- $aTmplVarsProfiles[] = [
- 'unit' => !$this->_bIsApi ? $oProfile->getUnit($iProfileId) : BxDolProfile::getData($oProfile),
- 'sign' => $bGrowth ? ($iPoints > 0 ? '+' : '-') : '',
- 'points' => $bGrowth ? abs($iPoints) : $iPoints
- ];
- if($this->_bIsApi)
- return [
- bx_api_get_block('reputation_leaderboard', [
- 'days' => $iDays,
- 'profiles' => $aTmplVarsProfiles
- ])
- ];
- $this->addCss(['main.css']);
- return $this->parseHtmlByName('block_leaderboard.html', [
- 'bx_repeat:profiles' => $aTmplVarsProfiles
- ]);
- }
- }
- /** @} */
|