/** * @param array $solrResult * @return array */ public function facetResult( &$solrResult ) { $translations = FacetFilteringTool::getTaxonomyTranslation ( $this->baseAttribute ); $this->needsRefresh = false; $facetResult = array(); $index = 0; foreach ( $this->queries as $q ) { $count = $solrResult['facet_counts']['facet_queries'][$q['query']]; $checked = ( $count && in_array( $index, $this->values ) ) ? 1 : 0; if ( isset( $translations[$q['label']]) ) { $facetResult[$translations[$q['label']]] = array( 'count' => (int)$count, 'id' => $index, 'checked' => $checked ); } // a value set for filter returns 0 results => we need to refresh the solr search if ( $count == 0 && in_array( $index, $this->values ) ) { $this->needsRefresh = true; unset( $this->values[array_search($index, $this->values)] ); $this->values = array_values($this->values); } $index++; } return $facetResult; }
/** * @param array $solrResult * @return array */ public function facetResult( &$solrResult ) { $translations = FacetFilteringTool::getTaxonomyTranslation ( $this->attribute ); $facetResult = array(); $this->needsRefresh = false; foreach( $solrResult['facet_counts']['facet_fields'][$this->facetSolrIdFieldName()] as $id => $count ) { $checked = ( $count && in_array( $id, $this->values ) ) ? 1 : 0; if( empty( $this->values ) && !$this->forcedUnchecked && in_array( $id, $this->forcedValues ) ) $checked = 1; if( $this->forcedUnchecked ) $checked = 0; if ( isset($translations[$id]) ) { $facetResult[$translations[$id]] = array( 'count' => (int)$count, 'id' => $id, 'checked' => $checked ); } } return $facetResult; }
/** * @param $category * @param $taxonomy * @return array */ private function getArticlesHierarchyWithTaxonomy($category, $taxonomy) { $taxonomies = FacetFilteringTool::getTaxonomyTranslation($category); $hierarchy = array( "title" => $taxonomies[$taxonomy], "articles" => array() ); $solrFilter = $this->_application->getResultHandler()->solrFilter(); if( $solrFilter ) $filters[] = $solrFilter; $filters[] = sprintf('subattr_%s___source_id____s:"%s"', $category, $taxonomy); $params = array( 'indent' => 'on', 'q' => '', 'start' => 0, 'rows' => 100, 'fq' => implode(' AND ' , $filters), 'fl' => 'attr_'.ClusterTool::clusterIdentifier().'_url_s,attr_headline_s,meta_main_node_id_si,main_node_meta_path_string_ms,attr_relative_depth_i,subattr_publisher_folder___source_id____s', 'qt' => 'ezpublish', 'sort' => 'main_node_meta_priority_si asc', 'explainOther' => '', 'hl.fl' => '', ); return $this->parseSolrResponse(SolrTool::rawSearch( $params ), $hierarchy); }
/** * Constructor */ public function __construct() { $translation = FacetFilteringTool::getTaxonomyTranslation( 'layer' ); $value = (!empty($translation)) ? $translation['layer'] : 'Layer'; parent::__construct(1, $value, 'layer_natom'); $this->sort = 'alpha'; $this->sortOnRefresh = false; }
/** * */ public function initVars() { $this->application = CacheApplicationTool::buildLocalizedApplicationByIdentifier($this->applicationIdentifier); $tab = FacetFilteringTool::getTaxonomyTranslation('speciality'); foreach($tab as $key => $val) { $this->specialityIds[] = $key; } }
/** * @param array $solrResult * @return array */ public function facetResult( &$solrResult ) { $translations = FacetFilteringTool::getTaxonomyTranslation ( $this->attribute ); $result = parent::facetResult($solrResult); //sorting $keysById = array(); foreach ( $result as $k => $f ) $keysById[$f['id']] = $k; $sortedResult = array(); foreach($this->defaultValues as $id) { if( isset($keysById[$id])) { $visible = true; if (SolrSafeOperatorHelper::featureIsActive('Univadis18Redesign')) { $hiddenValues = SolrSafeOperatorHelper::feature('Univadis18Redesign', 'SpecialtyFacetHiddenValues'); if (in_array($id, $hiddenValues)) { $visible = false; } } $f = $result[$keysById[$id]]; $f['visible'] = $visible; $sortedResult[$keysById[$id]] = $f; } else { if ( isset($translations[$id]) ) { $visible = true; if (SolrSafeOperatorHelper::featureIsActive('Univadis18Redesign')) { $hiddenValues = SolrSafeOperatorHelper::feature('Univadis18Redesign', 'SpecialtyFacetHiddenValues'); if (in_array($id, $hiddenValues)) { $visible = false; } } $sortedResult[$translations[$id]] = array( 'count' => 0, 'id' => $id, 'checked' => 0, 'visible' => $visible, ); } } } return $sortedResult; }
private static function getTaxonomyCodeFromArticleCategory($category) { $taxonomies = FacetFilteringTool::getTaxonomyTranslation('trip_speciality'); return array_search ($category, $taxonomies); }
/** * @param int $quizId * @param int $applicationId * @return array */ static function getQuizData( $quizId, $applicationId, $isLocalQuiz = true ) { $quizData = self::fetchOneBy( array( 'quiz_id' => $quizId, 'application_id' => $applicationId ) ); if( !$quizData ) { // We don't have the quiz meta for the requested quiz, we try to create it (happens only once) $object =& eZContentObject::fetch( $quizId ); if( !$object ) return null; /* @type $dm eZContentObjectAttribute[] */ $dm = $object->DataMap(); $mc = $dm['media_content']->content(); if( isset( $mc['relation_list'][0]['node_id'] ) ) { $quiz =& eZContentObjectTreeNode::fetch( $mc['relation_list'][0]['node_id'] ); /* @type $quizDM eZContentObjectAttribute[] */ $quizDM = $quiz->DataMap(); self::add( $quizId, ClusterTool::clusterIdentifier(), $applicationId, (int)$quizDM['points']->content(), (int)$quizDM['correct_reply']->content() ); $quizData = self::fetchOneBy( array( 'quiz_id' => $quizId, 'application_id' => $applicationId ) ); } else { return null; } } $currentMMUser = MMUsers::getCurrentUserObject(); $currentUserResponse = false; $nbCorrect = (int)$quizData->attribute( 'nb_correct' ); $nbWrong = (int)$quizData->attribute( 'nb_wrong' ); if ( $currentMMUser ) { $responseFetchParams = array( 'quiz_id' => $quizId, 'uuid' => $currentMMUser->attribute( 'uuid' ), 'application_id' => $applicationId ); if (!$isLocalQuiz) { $responseFetchParams['cluster_identifier'] = null; } $currentUserResponse = QuizReply::fetchOneBy( $responseFetchParams ); } if( $currentUserResponse ) { $currentUserResponded = true; $answerWasCorrect = (bool)$currentUserResponse->attribute( 'is_correct' ); } else { $currentUserResponded = false; $answerWasCorrect = false; } $speRepliesResult = array( 'total' => 0, 'correct' => 0, 'wrong' => 0 ); $userSpecialtyTranslations = FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ); if ( $currentMMUser ) { $userSpecialtyId = $userSpecialtyTranslations[$currentMMUser->attribute( 'user_speciality' )]['id']; $speReplies = QuizReply::fetchBySpecialtyInScoring( $currentMMUser->attribute( 'uuid' ), $quizId, $applicationId, $userSpecialtyId ); if( $speReplies ) { $speRepliesResult['total'] = count( $speReplies ); foreach( $speReplies as $reply ) { if( $reply['is_correct'] == 1 ) $speRepliesResult['correct']++; else $speRepliesResult['wrong']++; } } } $response = array( 'points' => (int)$quizData->attribute( 'points' ), 'correct_answer' => (int)$quizData->attribute( 'correct_answer' ), 'global_answers' => array( 'total' => ( $nbCorrect + $nbWrong ), 'correct' => $nbCorrect, 'wrong' => $nbWrong ), 'specialty_answers' => $speRepliesResult, 'current_user_responded' => $currentUserResponded, 'answer_was_correct' => $answerWasCorrect ); if( $currentUserResponded ) { /* @type $quizArticleDM eZContentObjectAttribute[] */ $quizArticleDM = eZContentObject::fetch( $quizId )->DataMap(); $mediaContent = $quizArticleDM["media_content"]->content(); $quizDM = eZContentObjectTreeNode::fetch( $mediaContent['relation_list'][0]['node_id'] )->DataMap(); $outputHandler = new eZXHTMLXMLOutput( $quizDM['commented_answer']->DataText, false ); $commentedAnswer = $outputHandler->outputText(); $response['commented_answer'] = $commentedAnswer; } return $response; }
/** * @return array */ protected function getHomepageElementCount() { $returnArray = array(); $taxonomyCategory = $this->getHomepageTaxonomyCategory(); $taxonomies = FacetFilteringTool::getTaxonomyTranslation($taxonomyCategory); $facetPosition = $this->getHomepageFacetPosition(); if ( $facetPosition === false || !isset($this->facets[$facetPosition]) ) return false; $facetResults = $this->resultHandler->filteredFacetResult( $this->facets[$facetPosition] ); foreach ( array_keys($taxonomies) as $taxonomyCode ) { foreach( $facetResults as $facetValue ) { if ( $facetValue['id'] === $taxonomyCode ) { $returnArray[$taxonomyCode] = $facetValue['count']; break; } } if ( !isset($returnArray[$taxonomyCode]) ) $returnArray[$taxonomyCode] = 0; } return $returnArray; }
'use-modules' => true, 'use-extensions' => true ) ); $script->startup(); $script->initialize(); $cli = eZCLI::instance(); $db = MMDB::instance(); foreach($db->arrayQuery("SELECT cluster_identifier FROM mm_seo group by cluster_identifier") as $cluster) { $clusterIdentifier = $cluster["cluster_identifier"]; $cli->output($clusterIdentifier); $specialties = FacetFilteringTool::filteredTaxonomy("speciality", $clusterIdentifier, true); $rows = $db->arrayQuery(sprintf("SELECT id, speciality FROM mm_seo WHERE cluster_identifier = '%s'", $clusterIdentifier)); $progressBar = new ezcConsoleProgressbar( new ezcConsoleOutput(), count($rows), array( 'emptyChar' => ' ', 'barChar' => '=' ) ); $progressBar->start(); foreach($rows as $row) { if(array_key_exists($row["speciality"], $specialties)) { $db->query(sprintf("UPDATE mm_seo SET spe_code='%s' WHERE id=%d", $specialties[$row["speciality"]], $row["id"])); } $progressBar->advance();
/** * This function construct different parameter for an article for template mustache * @param $articles * @param $additionalMappingTaxonomies * @param ChannelBlock $block * @return array */ private function constructArticles($articles, $additionalMappingTaxonomies, ChannelBlock $block) { $taxonomyTranslations = $constructedArticles = array(); foreach($articles as $article) { // add view parameter channel in url $article["url"] .= "/(channel)/".$block->attribute("id"); // info for sorting articles cross applications $article["info_sort"] = array(); if($article["online_date"]) { $article["info_sort"]["date"] = solrTool::getTimestampFromSolr($article["online_date"]); $article["online_date"] = solrTool::getDateFromSolr($article["online_date"]); } $article["info_sort"]["rating"] = $article["rating"]; $article["info_sort"]["views"] = $article["views"]; $article["info_sort"]["headline"] = $article["headline"]; $article["info_sort"]["score"] = $article["score"]; $mediaCase = ImageArticleTool::MULTIMEDIA_APPLICATION_CASE; $hasImage = SolrSafeOperatorHelper::hasImageArticleFromSolr($article, $mediaCase); if( !$hasImage ) { $mediaCase = ImageArticleTool::NEWS_APPLICATION_CASE; $hasImage = SolrSafeOperatorHelper::hasImageArticleFromSolr($article, $mediaCase); } // image information $article["hasDtImage"] = $hasImage; $article["hasMbImage"] = $hasImage; if ( $hasImage ) { $article["dt_url"] = SolrSafeOperatorHelper::getImageArticleUrl($mediaCase, $article['object_id'], $article['language'], 'dt_full'); $article["mb_url"] = SolrSafeOperatorHelper::getImageArticleUrl($mediaCase, $article['object_id'], $article['language'], 'm_full'); } $promoTaxonomy = $this->getCustomParameter('PromoTaxonomy'); foreach ($article['media_types'] as $type => $value) { $article["has_media_{$type}"] = true; } $article['hasPromoTaxonomy'] = false; // construct taxonomies fields foreach($additionalMappingTaxonomies as $taxonomyCategory => $solrField) { if ($taxonomyCategory == $promoTaxonomy) { if (count($article[$taxonomyCategory]) == 1 && $article[$taxonomyCategory][0] != '') { $article['hasPromoTaxonomy'] = true; $article['promoTaxonomy'] = FacetFilteringTool::getTaxonomyTranslationByCode($article[$taxonomyCategory][0]); } } // special case for retrieve value of taxonomy publisher folder if($taxonomyCategory == "publisher_folder") { $publisher = PublisherFolder::getPublisherFromPath($article["publisher_folder"][0]); if($publisher) { $article["publisher_folder"] = $publisher->getTranslation()->attribute("name"); } else { $article["publisher_folder"] = null; } } else { if(!empty($article[$taxonomyCategory]) && $article[$taxonomyCategory][0] != "") { if(empty($taxonomyTranslations[$taxonomyCategory])) { $taxonomyTranslations[$taxonomyCategory] = FacetFilteringTool::getTaxonomyTranslation($taxonomyCategory); } $article[$taxonomyCategory] = $taxonomyTranslations[$taxonomyCategory][$article[$taxonomyCategory][0]]; } else { // if the category has not value, we remove the entry in article unset($article[$taxonomyCategory]); } } } $this->constructAdditionalInformations($article); // rebuild array for delete keys for mustache $constructedArticles[] = $article; } return $constructedArticles; }
/** * @param array $uncrytedTicket * @return MMUsers */ public static function createOrUpdateMMUser( $uncrytedTicket ) { $userId = $uncrytedTicket['uuid']; $customerType = $uncrytedTicket['customerType']; if ( isset($uncrytedTicket['userSpeciality']) ) { $userSpeciality = $uncrytedTicket['userSpeciality']; } else { $userSpeciality = $uncrytedTicket['mainSpeciality']; } $state = $uncrytedTicket['state']; $country = eZIni::instance('site.ini')->variable('RegionalSettings','CountryOfRegistration'); $language = $uncrytedTicket['language']; /** * @todo: check $language entry format and parse it if needed to get an iso code on 2 chars */ $iniMapping = eZINI::instance('mercktaxonomymapping.ini'); $taxonomyType = $iniMapping->variable( 'Taxonomy', 'SpecialtiesTaxonomyType'); $specialtiesMappingINI = $iniMapping->variable( 'Taxonomy', 'Specialties' ); $customerTypesMappingINI = $iniMapping->variable( 'Taxonomy', 'CustomerTypes' ); if($taxonomyType != "transitive") { if ( isset( $customerTypesMappingINI[$customerType] ) ) { $customerType = $customerTypesMappingINI[$customerType]; } else { $customerType = $customerTypesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-CT', $userId, $country ); } if ( isset( $specialtiesMappingINI[$userSpeciality] ) ) { $userSpeciality = $specialtiesMappingINI[$userSpeciality]; } else { $userSpeciality = $specialtiesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-SPE', $userId, $country ); } } else { $customerTypesMapping = SolrSafeOperatorHelper::getCustomerTypes(); if ( !isset( $customerTypesMapping["$customerType"] ) ) { // fill with default value $customerType = $customerTypesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-CT', $userId, $country ); } $specialtiesMapping = SolrSafeOperatorHelper::getUserSpecialities(); if ( !isset( $specialtiesMapping[(string)$userSpeciality] ) ) { // fill with default value $userSpeciality = $specialtiesMappingINI['Default']; self::updateDBWithEmptyValue( 'empty-SPE', $userId, $country ); } } /** @var MMUsers $user */ $user = MMUsers::fetchByIdAndCountry( $userId, $country ); $isModifiedUser = false; if ( $user ) { if ( $customerType != $user->attribute('customer_type') ) { $user->setAttribute('customer_type', $customerType); $isModifiedUser = true; } if ( $userSpeciality !== $user->attribute('user_speciality') ) { $mainSpeciality = UserSpecialityContentSpeciality::getContentSpeciality ( $userSpeciality ); $defaultAdditionalSpecialities = MMUserLogin::getAddSpecialties($mainSpeciality); $user->setAttribute('user_speciality', $userSpeciality); // mapping main_spe additional spe $preferences = $user->getPreferences(); $userAditionalSpecialities = $preferences['specialities']; array_shift($userAditionalSpecialities); $tmp = array_diff( $userAditionalSpecialities, $defaultAdditionalSpecialities ); if( empty( $tmp ) ) // we don't modify the user spes if he has changed his selection { $preferences["specialities"] = MMUserLogin::getAddSpecialties($mainSpeciality); $user->setPreferences($preferences); } $user->setPreferences($preferences); // The user specialty has been modified, we need to update it for Quiz-type applications of the current cluster if( CacheApplicationTool::buildLocalizedApplicationByIdentifier('train-the-brain') instanceof ApplicationLocalized) { $playerScoring = QuizPlayerScoring::fetchOneBy( array( 'application_id' => (int)$app->applicationObject->id, 'uuid' => $user->attribute( 'uuid' ) ) ); // Checking if the current user has scored at least once for the application if( $playerScoring ) { foreach( FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ) as $k => $t ) { if( ($k . "") === ($userSpeciality . "") ) { // Updating the user specialty id in the player scoring table $playerScoring->setAttribute( 'user_specialty', $t['id'] ); $playerScoring->store(); } } // Scheduling a ranking update QuizPendingRankingUpdate::add( $playerScoring->attribute( 'global_ranking' ), $app->applicationObject->id ); } } $isModifiedUser = true; } if ( $country != $user->attribute('country') ) { $user->setAttribute('country', $country); $isModifiedUser = true; } if( $language != $user->attribute( 'language' ) ) { $user->setAttribute('language', $language ); $isModifiedUser = true; } if ( $state != $user->attribute('state') ) { $user->setAttribute('state', $state); $isModifiedUser = true; } if ( $isModifiedUser ) { $user->setAttribute('date_update', time()); $user->store(); } // set gpnotebook hand shake data in preferences if($user->getGPNotebookHS()) { SolrSafeOperatorHelper::getAndStoreGPNotebookHS(); } } else { $mainSpeciality = UserSpecialityContentSpeciality::getContentSpeciality ( $userSpeciality ); $insertedArray = array ( 'uuid' => $userId, 'customer_type' => $customerType, 'user_speciality' => $userSpeciality, 'country' => $country, 'language' => $language, 'date_update' => time(), 'state' => $state, ); $user = new MMUsers ($insertedArray); $user->store(); // mapping main_spe additional spe $preferences = $user->getPreferences(); $preferences["specialities"] = MMUserLogin::getAddSpecialties($mainSpeciality); $user->setPreferences($preferences); $isModifiedUser = true; } if ( $isModifiedUser ) { // Tag Lyris user to be reimported : $user->tagLyrisToProcess(); } return $user; }
/** * @return string[] */ protected function translations() { // we only return the section translations - chapters labels are directly taken from solr return FacetFilteringTool::getTaxonomyTranslation ( 'section' ); }
/** * @param string $newGameName * @param int $applicationId * @return array */ static function createNewPlayer( $newGameName, $applicationId, $isLocalQuiz = true ) { $currentMMUser = MMUsers::getCurrentUserObject(); if( $currentMMUser ) { $clusterIdentifier = ($isLocalQuiz) ? ClusterTool::clusterIdentifier() : ''; $newPlayer = new QuizPlayerScoring(); // Setting up the global ranking of the new player $lowestGlobalScore = self::fetchBy( array( 'application_id' => $applicationId, 'cluster_identifier' => $clusterIdentifier ), array( 'global_ranking' => 'desc' ), array( 'length' => 1 ) ); if( $lowestGlobalScore ) $lgs = $lowestGlobalScore[0]->attribute( 'score' ) == 0 ? $lowestGlobalScore[0]->attribute( 'global_ranking' ) : ( $lowestGlobalScore[0]->attribute( 'global_ranking' ) + 1 ); else $lgs = 1; // Setting up the specialty ranking of the new player $userSpecialtyTranslations = FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ); $userSpecialtyTaxonomyId = $userSpecialtyTranslations[$currentMMUser->attribute( 'user_speciality' )]['id']; $lowestSpecialtyScore = self::fetchBy( array( 'application_id' => $applicationId, 'user_specialty' => $userSpecialtyTaxonomyId ), array( 'specialty_ranking' => 'desc' ), array( 'length' => 1 ) ); if( $lowestSpecialtyScore ) $lss = $lowestSpecialtyScore[0]->attribute( 'score' ) == 0 ? $lowestSpecialtyScore[0]->attribute( 'specialty_ranking' ) : ( $lowestSpecialtyScore[0]->attribute( 'specialty_ranking' ) + 1 ); else $lss = 1; $newPlayer->setAttribute( 'game_name', $newGameName ); $newPlayer->setAttribute( 'uuid', $currentMMUser->attribute( 'uuid' ) ); $newPlayer->setAttribute( 'cluster_identifier', $clusterIdentifier); $newPlayer->setAttribute( 'application_id', $applicationId ); $newPlayer->setAttribute( 'score', 0 ); $newPlayer->setAttribute( 'user_specialty', Taxonomy::fetchObject( Taxonomy::definition(), null, array( 'code' => $currentMMUser->attribute( 'user_speciality' ) ), true)->attribute( 'id' ) ); $newPlayer->setAttribute( 'nb_correct', 0 ); $newPlayer->setAttribute( 'nb_wrong', 0 ); $newPlayer->setAttribute( 'global_ranking', $lgs ); $newPlayer->setAttribute( 'specialty_ranking', $lss ); $newPlayer->setAttribute( 'user_cluster', ClusterTool::clusterIdentifier() ); $newPlayer->store(); return array( 'lgs' => $lgs, 'lss' => $lss ); } return null; }
'clusterIdentifier' => 'Cluster identifier', 'countryCode' => 'Country code' ) ); $script->startup(); $script->initialize(); if( $options['clusterIdentifier'] && $options['countryCode'] ) { $updated = 0; $lowestRankingsPerQuizApp = array(); $playerScoringRows = QuizPlayerScoring::fetchBy( array( 'cluster_identifier' => array( array( $options['clusterIdentifier'] ) ) ) ); if( $playerScoringRows ) { ClusterTool::setCurrentCluster( $options['clusterIdentifier'] ); $us = FacetFilteringTool::getTaxoTranslationWithIDs( 'user_specialty' ); foreach( $playerScoringRows as $playerScoring ) { $user = MMUsers::fetchByIdAndCountry( $playerScoring->attribute( 'uuid' ), $options['countryCode'] ); if( $user ) { if( isset( $us[$user->attribute( 'user_speciality' )] ) && $us[$user->attribute( 'user_speciality' )]['id'] != $playerScoring->attribute( 'user_specialty' ) ) { if( !isset( $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] ) || ( isset( $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] ) && $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] < (int)$playerScoring->attribute( 'global_ranking' ) ) ) $lowestRankingsPerQuizApp[$playerScoring->attribute( 'application_id' )] = (int)$playerScoring->attribute( 'global_ranking' ); $oldUS = $playerScoring->attribute( 'user_specialty' ); $playerScoring->setAttribute( 'user_specialty', $us[$user->attribute( 'user_speciality' )]['id'] ); $playerScoring->store(); $updated++; $cli->output( "Updated user speciality (" . $oldUS . " -> " . $us[$user->attribute( 'user_speciality' )]['id'] . ") in scoring data for user " . $playerScoring->attribute( 'uuid' ) ); }
public function getHallOfFame($season) { $tpl = $this->tpl(); $db = eZDB::instance(); $ust = array(); $playerData = null; $totalPlayers = 0; $lowestGlobalRanking = 0; $uuidsInGlobalLeaderboard = array(); $_globalLeaderboard = array( 1 => array(), 2 => array(), 3 => array(), ); $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() : ''; $results = array(); for ($i = 1; $i <= 3; $i++) { $chunks = $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 = %d AND season = %d GROUP BY uuid ORDER BY global_ranking ASC, uuid = '%s' DESC LIMIT 5", QuizHallOfFame::SQL_TABLENAME, $db->escapeString( $clusterIdentifier ), $this->applicationObject->attribute( 'id' ), $i, $season, $this->user()->attribute('uuid') )); $results = array_merge($results, $chunks); } 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[$row['global_ranking']][] = 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['uuid'] == $this->user()->attribute( 'uuid' ) && is_null( $playerData ) ) { $playerData = $row; } } if( !in_array( $this->user()->attribute( 'uuid' ), $uuidsInGlobalLeaderboard ) ) { if( is_null( $playerData ) ) { $playerData = QuizHallOfFame::fetchUserInSeason( $this->applicationObject->attribute( 'id' ), $season, false, $this->isLocalQuiz() ); } if( $playerData && ( $playerData['nb_correct'] == 0 && $playerData['nb_wrong'] == 0 ) ) { $playerData = null; } } $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 ) AND season = %d GROUP BY (user_specialty)", QuizHallOfFame::SQL_TABLENAME, $db->escapeString( $clusterIdentifier ), $this->applicationObject->attribute( 'id' ), $season ) ); 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->setVariable( 'global_leaderboard', $_globalLeaderboard ); $tpl->setVariable( 'current_player_uuid', $this->user()->attribute('uuid') ); $response = array( 'player_position' => ($playerData) ? $playerData['global_ranking'] : 0, 'hall_of_fame' => $tpl->fetch( 'design:esibuild/app_content/train-the-brain/hall_of_fame.tpl' ), 'total_players' => $totalPlayers, ); return $response; }
protected function getCustomerTypes() { if (self::$customerTypeIds == null) { self::$customerTypeIds = array(); $tab = FacetFilteringTool::getTaxonomyTranslation('customer_type'); foreach($tab as $key => $val) { self::$customerTypeIds[] = $key; } } return self::$customerTypeIds; }
/** * @see ezfSolrDocumentFieldBase::getData() * @return array */ public function getData() { $data = parent::getData(); $content = $this->ContentObjectAttribute->content(); /* @var $content array */ foreach ( array_merge( self::taxonomyAttribute(), array_keys($content) ) as $taxonomyIdentifier ) { $taxonomyValues = isset( $content[$taxonomyIdentifier] ) ? $content[$taxonomyIdentifier] : array(); $subattrSourceIdValues = array(); $subattrSourceIdFieldName = self::getCustomSubattributeFieldName( $taxonomyIdentifier, 'source_id'); foreach ( $taxonomyValues as $taxonomyValue ) { if( preg_match( '#^symptom_.*$#', $taxonomyValue ) ) { $sourceKey = $taxonomyValue; $subattrSourceIdValues[] = $sourceKey; // we need a few more things for the symptoms /* @type $node eZContentObjectTreeNode */ $contentObject = $this->ContentObjectAttribute->object(); $node = $contentObject->mainNode(); $clusters = NodeTool::getArticleClusters($node); foreach( $clusters as $cluster ) { ClusterTool::setCurrentCluster($cluster); $ini = eZINI::fetchFromFile('extension/'.$cluster.'/settings/site.ini'); $node->setCurrentLanguage( $ini->variable('RegionalSettings', 'ContentObjectLocale') ); $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByIdentifier( MerckManualShowcase::mainApplicationIdentifier() ); if ( !$applicationLocalized ) continue; $customSymptomAttributeKey = 'attr_custom_symptom_'.$cluster.'_s'; $labelTranslations = FacetFilteringTool::getTaxonomyTranslation( 'symptom' ); $label = $labelTranslations[$sourceKey]; $url = preg_replace( '#^[^/]+#', '', MerckManualFunctionCollection::getMerckManualNodeUrl( 'meck-manual-showcase', $node, $ini->variable('RegionalSettings', 'ContentObjectLocale') ) ); ClusterTool::resetCurrentCluster(); $customSymptomAttributeValueParts = array( mb_strtolower(mb_substr(StringTool::removeAccents( StringTool::CJK2Pinyin($label) ), 0, 1)), $label, $url ); $data[$customSymptomAttributeKey] = implode( '##', $customSymptomAttributeValueParts ); } } else if ( preg_match('#^222\.[0-9]+$#', $taxonomyValue ) ) { $sourceKey = $taxonomyValue; $subattrSourceIdValues[] = $sourceKey; /* @type $node eZContentObjectTreeNode */ /* @type $dataMap eZContentObjectAttribute[] */ $contentObject = $this->ContentObjectAttribute->object(); $node = $contentObject->mainNode(); $clusters = NodeTool::getArticleClusters($node); $customSymptomAttributeValueParts = array( $content['layer_natom'][0], $content['sub_layer_natom'][0], ); foreach( $clusters as $cluster ) { ClusterTool::setCurrentCluster($cluster); $customSymptomAttributeKey = 'attr_custom_layer_sublayer_natom_'.$cluster.'_s'; $data[$customSymptomAttributeKey] = implode( '##', $customSymptomAttributeValueParts ); ClusterTool::resetCurrentCluster(); } } else $subattrSourceIdValues[] = trim( $taxonomyValue ); } $data[$subattrSourceIdFieldName] = empty($subattrSourceIdValues) ? '' : $subattrSourceIdValues; } return $data; }
public static function fetchSymptomsLetters($related_infos = false) { if ( is_null(self::$_symptomsLetters) ) { $field = 'attr_custom_symptom_'.ClusterTool::clusterIdentifier().'_s'; $params = array( 'indent' => 'on', 'q' => '', 'start' => 0, 'rows' => 0, 'fl' => 'score', 'qt' => 'ezpublish', 'explainOther' => '', 'hl.fl' => '', 'facet' => 'true', 'facet.field' => $field, 'facet.mincount' => 1 ); $solrResult = self::rawSearch($params); $translations = FacetFilteringTool::getTaxonomyTranslation( 'symptom' ); $letters = array(); foreach( $solrResult['facet_counts']['facet_fields'][$field] as $key => $v) { list( $letter, $symptomLabel, $url ) = explode('##', $key); if( !isset($letters[$letter]) ) $letters[$letter] = array(); $letters[$letter][$symptomLabel] = $url; } ksort($letters); foreach ( $letters as $letter => $symptoms) { uksort($symptoms, function($a, $b) { return strcmp(StringTool::CJK2Pinyin($a), StringTool::CJK2Pinyin($b)); }); $letters[$letter] = $symptoms; } self::$_symptomsLetters = $letters; } return array( 'result' => self::$_symptomsLetters ); }
public static function translateTaxonomy($code) { return FacetFilteringTool::getTaxonomyTranslationByCode($code); }
/** * @return string[] */ protected function translations() { return FacetFilteringTool::getTaxonomyTranslation ( $this->attribute ); }
/** * i18n operator works like : source|context([argument1, argument2 ...]) * Arguments are optional and are comma separated * * @return Callable[] * * Examples : * * Simple without argument: * {{# i18n }} * MORE|merck() * {{/ i18n }} * * Or with argument: * {{# i18n }} * %nb RESULTS|merck(3) * {{/ i18n }} */ private static function getHelpers($application = null) { return array( 'i18n' => function($text) { preg_match("#(?<source>[^\|]+)\|(?<context>[^(]+)\((?<params>[^\)]+)?\)#", $text, $m); if($m && $m["source"] && $m["context"]) { $arguments = array(); if($m["params"]) { $params = explode(",", $m["params"]); preg_match_all("#(?<arguments>%\w+)#", $m["source"], $mParams); if($mParams && $mParams["arguments"]) { for($i = 0; $i < count($mParams["arguments"]); $i++) { $arguments[$mParams["arguments"][$i]] = $params[$i]; } } } return ezpI18n::tr($m["context"], $m["source"], null, $arguments); } return $text; }, 'taxonomies_filter' => function($text) use ($application) { $filterTaxonomies = $application->getCustomParameter('TaxonomiesFilter'); $html = ''; foreach($filterTaxonomies as $category) { $taxonomies = FacetFilteringTool::getTaxonomyTranslationsByCategory($category); $tpl = eZTemplate::factory(); $tpl->setVariable('taxonomies', $taxonomies); $tpl->setVariable('category', $category); $html .= $tpl->fetch( 'design:esibuild/app_content/channel/filter.tpl' ); } return $html; }, 'editors_choice_content' => function($text) use ($application) { $taxonomyCategory = $application->getCustomParameter('EditorsChoiceFilter'); $taxonomyValue = $application->getCustomParameter('EditorsChoiceValue'); $limit = $application->getCustomParameter('EditorsChoiceLimit'); $html = ''; $language = eZINI::instance('site.ini')->variable('RegionalSettings', 'ContentObjectLocale'); $fields = array( 'node_id' => 'meta_node_id_si', 'object_id' => 'meta_id_si', 'language' => 'meta_language_code_ms', 'url' => 'attr_'.ClusterTool::clusterIdentifier().'_url_s', 'headline' => 'attr_headline_s', 'promo_description' => 'attr_promo_description_t', 'rating' => 'attr_content_rating_'.ClusterTool::clusterIdentifier().'_f', 'views' => 'attr_view_counter_'.ClusterTool::clusterIdentifier().'_i', 'app_identifiers' => 'subattr_parent_application___identifier____s', 'apps' => 'subattr_local_application___source_mixed____s', 'app_id' => 'subattr_local_application___source_id____s', 'online_date' => 'attr_online_date_dt', 'score' => 'score', 'publisher_path' => 'subattr_publisher_folder___source_id____s', 'has_image' => 'attr_has_image_'.ClusterTool::clusterIdentifier().'_bst', 'media_types' => 'attr_media_content_types_'.ClusterTool::clusterIdentifier().'_bst', 'internal_id' => 'attr_publisher_internal_id_s', 'link_url' => 'attr_media_content_link_'.ClusterTool::clusterIdentifier().'____ms' ); $filters = array( "subattr_{$taxonomyCategory[0]}___source_id____s: \"{$taxonomyValue[0]}\"", "meta_language_code_ms: \"{$language}\"" ); $params = array( 'indent' => 'on', 'q' => '*:*', 'fq' => implode(' AND ' , $filters), 'start' => '0', 'rows' => $limit, 'fl' => implode(',',$fields), 'qt' => 'ezpublish', 'explainOther' => '', 'hl.fl' => '', 'sort' => "attr_online_date_dt desc", ); $result = SolrTool::rawSearch($params); foreach ($result[response][docs] as $key => $value) { $result[response][docs][$key]['headline'] = $value['attr_headline_s']; $result[response][docs][$key]['node_id'] = $value['meta_node_id_si']; $result[response][docs][$key]['object_id'] = $value['meta_id_si']; $result[response][docs][$key]['language'] = $value['meta_language_code_ms']; $result[response][docs][$key]['promo_description'] = $value['attr_promo_description_t']; $app = CacheApplicationTool::buildLocalizedApplicationByApplication( $value['subattr_local_application___source_id____s'][0] ); $applicationObject = $app->applicationObject(); $applicationType = $applicationObject->applicationType()->attribute('type_identifier'); $result[response][docs][$key]['application_name'] = $app->attribute('url_alias'); $publisherPath = $value['subattr_publisher_folder___source_id____s'][0]; $publisher = PublisherFolder::getPublisherFromPath($publisherPath); $publisherFolderId = $publisher->getTranslation()->attribute('publisher_folder_id'); $publisherName = $publisher->getTranslation()->attribute('name'); $result[response][docs][$key]['publisher_name'] = $publisherName; $url = $value['attr_'.ClusterTool::clusterIdentifier().'_url_s']; $url = ($applicationType == 'first-child') ? $app->attribute('url_alias') : $app->attribute('url_alias') . '/' . $publisherFolderId . '/' . $url; $result[response][docs][$key]['url'] = $url; $result[response][docs][$key]['online_date'] = solrTool::getDateFromSolr($value['attr_online_date_dt']); $result[response][docs][$key]['publisher_name'] = $publisherName; $result[response][docs][$key]['has_image'] = json_decode( base64_decode($value['attr_has_image_'.ClusterTool::clusterIdentifier().'_bst']), true ); $mediaCase = ImageArticleTool::NEWS_APPLICATION_CASE; $hasImage = $result[response][docs][$key]['has_image'][$mediaCase]; if ($hasImage) { $result[response][docs][$key]["dt_url"] = SolrSafeOperatorHelper::getImageArticleUrl($mediaCase, $result[response][docs][$key]['object_id'], $result[response][docs][$key]['language'], 'dt_full'); $result[response][docs][$key]["mb_url"] = SolrSafeOperatorHelper::getImageArticleUrl($mediaCase, $result[response][docs][$key]['object_id'], $result[response][docs][$key]['language'], 'm_full'); } } $tpl = eZTemplate::factory(); $tpl->setVariable('editorsChoice', $result); $html .= $tpl->fetch( 'design:esibuild/app_content/channel/editors_choice.tpl' ); return $html; } ); }
public function jsonBuildResult() { $this->tpl()->setVariable( 'section_translations', FacetFilteringTool::getTaxonomyTranslation ( 'section' ) ); parent::jsonBuildResult(); }