/** * @param int $withUR * @return array */ protected function getRightComumn( $withUR, $limit = 10, $mode = '' ) { if( $this->user() ) { $db = eZDB::instance(); $ust = array(); $playerData = null; $userSpecialtyTranslations = FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ); foreach( $userSpecialtyTranslations as $translation ) $ust[$translation['id']] = $translation['label']; $userSpecialtyTaxonomyId = $userSpecialtyTranslations[$this->user()->attribute( 'user_speciality' )]['id']; $clusterIdentifier = ($this->isLocalQuiz()) ? ClusterTool::clusterIdentifier() : ''; $resultsGlobal = $db->arrayQuery( sprintf(" SELECT COUNT(id) as total, uuid, user_specialty, game_name, global_ranking, specialty_ranking, score, nb_correct, nb_wrong FROM %s WHERE cluster_identifier = '%s' AND application_id = %d AND global_ranking <= 10 AND global_ranking > 0 GROUP BY uuid ORDER BY global_ranking ASC, uuid = '%s' DESC LIMIT %d", QuizPlayerScoring::SQL_TABLENAME, $db->escapeString( $clusterIdentifier ), $this->applicationObject->attribute( 'id' ), $this->user()->attribute('uuid'), $limit )); $resultsSpecialty = $db->arrayQuery( sprintf(" SELECT COUNT(id) as total, uuid, user_specialty, game_name, global_ranking, specialty_ranking, score, nb_correct, nb_wrong FROM %s WHERE cluster_identifier = '%s' AND application_id = %d AND specialty_ranking <= 10 AND user_specialty = %d GROUP BY uuid ORDER BY specialty_ranking ASC, uuid = '%s' DESC LIMIT %d", QuizPlayerScoring::SQL_TABLENAME, $db->escapeString( $clusterIdentifier ), $this->applicationObject->attribute( 'id' ), $userSpecialtyTaxonomyId, $this->user()->attribute('uuid'), $limit )); $results = array_merge( $resultsGlobal, $resultsSpecialty ); $_globalLeaderboard = array(); $_specialtyLeaderboard = array(); $uuidsInGlobalLeaderboard = array(); $uuidsInSpecialtyLeaderBoard = array(); $totalPlayers = 0; $totalSpecialtyPlayers = 0; $lowestGlobalRanking = 0; $lowestSpecialtyRanking = 0; if( $results ) { foreach( $results as $row ) { if( $row['nb_correct'] == 0 && $row['nb_wrong'] == 0 ) continue; if( $row['global_ranking'] <= 10 && !in_array( $row['uuid'], $uuidsInGlobalLeaderboard ) && count( $uuidsInGlobalLeaderboard ) < 10 ) { $_globalLeaderboard[] = array( 'game_name' => is_null( $row['game_name'] ) || $row['game_name'] == '' ? ezpI18n::tr( 'merck/quiz', 'ANONYMOUS' ) : $row['game_name'], 'specialty_label' => $ust[$row['user_specialty']], 'ranking' => $row['global_ranking'], 'uuid' => $row['uuid'], 'score' => $row['score'] ); $uuidsInGlobalLeaderboard[] = $row['uuid']; } if( $row['specialty_ranking'] <= 10 && $row['user_specialty'] == $userSpecialtyTaxonomyId && !in_array( $row['uuid'], $uuidsInSpecialtyLeaderBoard ) && count( $uuidsInSpecialtyLeaderBoard ) < 10 ) { $_specialtyLeaderboard[] = array( 'game_name' => is_null( $row['game_name'] ) || $row['game_name'] == '' ? ezpI18n::tr( 'merck/quiz', 'ANONYMOUS' ) : $row['game_name'], 'specialty_label' => $ust[$row['user_specialty']], 'ranking' => $row['specialty_ranking'], 'uuid' => $row['uuid'], 'score' => $row['score'] ); $uuidsInSpecialtyLeaderBoard[] = $row['uuid']; } if( $row['uuid'] == $this->user()->attribute( 'uuid' ) && is_null( $playerData ) ) { $playerData = $row; } } if( !in_array( $this->user()->attribute( 'uuid' ), $uuidsInGlobalLeaderboard ) || !in_array( $this->user()->attribute( 'uuid' ) , $uuidsInSpecialtyLeaderBoard ) ) { if( is_null( $playerData ) ) $playerData = QuizPlayerScoring::fetchCurrentUserRow( $this->applicationObject->attribute( 'id' ), false, $this->isLocalQuiz() ); if( $playerData && ( $playerData['nb_correct'] != 0 || $playerData['nb_wrong'] != 0 ) ) { if( !in_array( $playerData['uuid'], $uuidsInGlobalLeaderboard ) ) { $_globalLeaderboard[] = array( 'game_name' => is_null( $playerData['game_name'] ) || $playerData['game_name'] == '' ? ezpI18n::tr( 'merck/quiz', 'ANONYMOUS' ) : $playerData['game_name'], 'specialty_label' => $ust[$playerData['user_specialty']], 'ranking' => $playerData['global_ranking'], 'uuid' => $playerData['uuid'], 'score' => $playerData['score'] ); } if( !in_array( $playerData['uuid'], $uuidsInSpecialtyLeaderBoard ) ) { $_specialtyLeaderboard[] = array( 'game_name' => is_null( $playerData['game_name'] ) || $playerData['game_name'] == '' ? ezpI18n::tr( 'merck/quiz', 'ANONYMOUS' ) : $playerData['game_name'], 'specialty_label' => $ust[$playerData['user_specialty']], 'ranking' => $playerData['specialty_ranking'], 'uuid' => $playerData['uuid'], 'score' => $playerData['score'] ); } } } $playersCount = $db->arrayQuery( sprintf(" SELECT COUNT(*) as total, user_specialty, MAX(global_ranking) as lowest_global_ranking, MAX(specialty_ranking) as lowest_specialty_ranking FROM %s WHERE cluster_identifier = '%s' AND application_id = %d AND ( nb_correct > 0 OR nb_wrong > 0 ) GROUP BY (user_specialty)", QuizPlayerScoring::SQL_TABLENAME, $db->escapeString( $clusterIdentifier ), $this->applicationObject->attribute( 'id' ) ) ); foreach( $playersCount as $row ) { $totalPlayers += $row['total']; if( $row['user_specialty'] == $userSpecialtyTaxonomyId ) { $totalSpecialtyPlayers = $row['total']; $lowestSpecialtyRanking = $row['lowest_specialty_ranking']; } if( $row['lowest_global_ranking'] > $lowestGlobalRanking ) $lowestGlobalRanking = $row['lowest_global_ranking']; } } $tpl = $this->tpl(); $tpl->setVariable( 'global_leaderboard', $_globalLeaderboard ); $tpl->setVariable( 'specialty_leaderboard', $_specialtyLeaderboard ); $tpl->setVariable( 'current_player_uuid', $playerData['uuid'] ); $seasons = $this->getArchiveSeasons(); $tpl->setVariable( 'seasons', $seasons ); $rightColumnData = array( 'player_global_ranking' => ( $playerData['nb_correct'] == 0 && $playerData['nb_wrong'] == 0 ) ? null : $playerData['global_ranking'], 'player_specialty_ranking' => ( $playerData['nb_correct'] == 0 && $playerData['nb_wrong'] == 0 ) ? null : $playerData['specialty_ranking'], 'player_total_points' => $playerData['score'], 'player_total_correct' => $playerData['nb_correct'], 'player_total_wrong' => $playerData['nb_wrong'], 'player_game_name' => $playerData['game_name'] == '' ? null : $playerData['game_name'], 'global' => array( 'total' => $totalPlayers, 'lowest_rank' => $lowestGlobalRanking ), 'specialty' => array( 'total' => $totalSpecialtyPlayers, 'lowest_rank' => $lowestSpecialtyRanking ), 'global_leaderboard' => ($mode == 'homepage') ? $tpl->fetch( 'design:esibuild/app_content/train-the-brain/homepage_leaderboard.tpl' ) : $tpl->fetch( 'design:esibuild/app_content/train-the-brain/global_leaderboard.tpl' ), 'specialty_leaderboard' => $tpl->fetch( 'design:esibuild/app_content/train-the-brain/specialty_leaderboard.tpl' ), 'hall_of_fame' => $tpl->fetch( 'design:esibuild/app_content/train-the-brain/hall_of_fame.tpl' ), 'seasons' => $seasons ); if( $withUR == 1 ) $rightColumnData['user_replies'] = QuizMeta::getUserReplies( $this->applicationObject->attribute( 'id' ), $this->isLocalQuiz() ); return $rightColumnData; } return array(); }
<?php $http = eZHTTPTool::instance(); $description = ''; $userId = MMUsers::getCurrentUserId(); if ($userId !== '-1') { $applicationIdentifier = $http->postVariable('identifier'); $cardType = $http->postVariable('type'); $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByIdentifier($applicationIdentifier); if ($applicationLocalized) { $playerScoring = QuizPlayerScoring::fetchCurrentUserRow($applicationLocalized->applicationObject()->id); $description = ezpI18n::tr('merck/quiz', "WE HAVE THE PLEASURE TO INFORM YOU THAT YOU ARE NOW %SPE_RANK IN YOUR SPECIALITY AND %GLOBAL_RANK IN GLOBAL RANKING WITH A SCORE OF %NB_POINTS POINTS", null, array( '%SPE_RANK' => $playerScoring->attribute('specialty_ranking'), '%GLOBAL_RANK' => $playerScoring->attribute('global_ranking'), '%NB_POINTS' => $playerScoring->attribute('score') )); $description = strip_tags($description); $data = array( 'title' => ezpI18n::tr("merck/quiz", "QUIZ ANNOUNCEMENT"), 'description' => $description, 'specialty_rank' => $playerScoring->attribute('specialty_ranking'), 'global_rank' => $playerScoring->attribute('global_ranking'), 'application_identifier' => $applicationIdentifier, 'type' => $cardType, ); $userId = $playerScoring->attribute('uuid'); $clusterIdentifier = $playerScoring->attribute('cluster_identifier');