public function __construct(BASE_CLASS_WidgetParameter $params) { parent::__construct(); $lang = OW::getLanguage(); $service = OCSTOPUSERS_BOL_Service::getInstance(); $limit = $params->customParamList['userCount']; $list = $service->findList(1, $limit); if ($list) { $this->assign('list', $list); $total = $service->countUsers(); $this->assign('total', $total); $idList = array(); $scores = array(); $rates = array(); foreach ($list as $user) { array_push($idList, $user['dto']->id); $scores[$user['dto']->id] = $user['score']; $rates[$user['dto']->id] = $user['rates']; } $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($idList); foreach ($avatars as $userId => &$av) { $av['title'] .= ' - ' . $lang->text('ocstopusers', 'rate_info', array('rates' => $rates[$userId], 'score' => floatval($scores[$userId]))); } $this->assign('avatars', $avatars); $this->assign('scores', $scores); if ($total > $limit) { $toolbar = array(array('href' => OW::getRouter()->urlForRoute('ocstopusers.list'), 'label' => OW::getLanguage()->text('base', 'view_all'))); $this->setSettingValue(self::SETTING_TOOLBAR, $toolbar); } } else { $this->assign('list', null); } }
public function rated() { if (!OW::getUser()->isAuthenticated()) { throw new AuthenticateException(); } $lang = OW::getLanguage(); $page = !empty($_GET['page']) && intval($_GET['page']) > 0 ? $_GET['page'] : 1; $perPage = (int) OW::getConfig()->getValue('base', 'users_count_on_page'); $service = OCSTOPUSERS_BOL_Service::getInstance(); $userId = OW::getUser()->getId(); $users = $service->findRateUserList($userId, $page, $perPage); if ($users) { $count = $service->countRateUsers($userId); $list = array(); $fields = array(); foreach ($users as $user) { $list[] = $user['dto']; $fields[$user['dto']->id] = array('score' => $user['score'], 'timeStamp' => $user['timeStamp']); } $cmp = new OCSTOPUSERS_CMP_RatedList($list, $count, $perPage, false, $fields); $this->addComponent('users', $cmp); } else { $this->assign($users, null); } OW::getDocument()->setHeading($lang->text('ocstopusers', 'rated_me')); OW::getDocument()->setHeadingIconClass('ow_ic_star'); OW::getNavigation()->activateMenuItem(BOL_NavigationService::MENU_TYPE_MAIN, 'base', 'users_main_menu_item'); $this->setTemplate(OW::getPluginManager()->getPlugin('ocstopusers')->getCtrlViewDir() . 'list_index.html'); }
/** * Returns an instance of class * * @return OCSTOPUSERS_BOL_Service */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
public function __construct(BASE_CLASS_WidgetParameter $params) { parent::__construct(); $userId = $params->additionalParamList['entityId']; $service = BOL_RateService::getInstance(); $ownerMode = $userId == OW::getUser()->getId(); $this->assign('ownerMode', $ownerMode); if ($ownerMode) { $limit = $params->customParamList['userCount']; $topService = OCSTOPUSERS_BOL_Service::getInstance(); $ratedList = $topService->findRateUserList($userId, 1, $limit); if ($ratedList) { $idList = array(); foreach ($ratedList as $user) { array_push($idList, $user['dto']->id); } $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($idList); $this->assign('avatars', $avatars); $this->assign('list', $ratedList); $total = $topService->countRateUsers($userId); if ($total > $limit) { $toolbar = array('label' => OW::getLanguage()->text('base', 'view_all'), 'href' => OW::getRouter()->urlForRoute('ocstopusers.rated_list')); $this->assign('toolbar', array($toolbar)); } else { $this->assign('toolbar', null); } } else { $this->assign('list', null); } } $maxRate = $service->getConfig(BOL_RateService::CONFIG_MAX_RATE); $this->assign('maxRate', $maxRate); $cmpId = rand(1, 100000); $this->assign('cmpId', $cmpId); $entityId = $userId; $entityType = 'user_rates'; $ownerId = $ownerMode ? $userId : null; if (OW::getUser()->isAuthenticated()) { $userRateItem = $service->findRate($entityId, $entityType, OW::getUser()->getId()); if ($userRateItem !== null) { $userRate = $userRateItem->getScore(); } else { $userRate = null; } } else { $userRate = null; } $this->addComponent('total_score', new OCSTOPUSERS_CMP_TotalScore($entityId, $entityType)); $jsParamsArray = array('cmpId' => $cmpId, 'userRate' => $userRate, 'entityId' => $entityId, 'entityType' => $entityType, 'itemsCount' => $maxRate, 'respondUrl' => OW::getRouter()->urlFor('OCSTOPUSERS_CTRL_List', 'updateRate'), 'ownerId' => $ownerId); OW::getDocument()->addOnloadScript("var rate{$cmpId} = new OwRate(" . json_encode($jsParamsArray) . "); rate{$cmpId}.init();"); }