/** * @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; }
/** * @param string $identifier * @return string[] */ public static function getTaxonomyValues( $identifier ) { $result = array(); if ( !empty( $identifier ) ) { $taxonomyValues = FacetFilteringTool::getTaxonomyTranslation( $identifier ); foreach ( $taxonomyValues as $code => $label ) { $result[$code] = $label; } } return $result; }
/** * @return string[] */ protected function translations() { // we only return the section translations - chapters labels are directly taken from solr return FacetFilteringTool::getTaxonomyTranslation ( 'section' ); }
/** * @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; }
/** * @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; }
/** * 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; }
/** * @return string[] */ protected function translations() { return FacetFilteringTool::getTaxonomyTranslation ( $this->attribute ); }
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 ); }
private static function getTaxonomyCodeFromArticleCategory($category) { $taxonomies = FacetFilteringTool::getTaxonomyTranslation('trip_speciality'); return array_search ($category, $taxonomies); }
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; }
public function jsonBuildResult() { $this->tpl()->setVariable( 'section_translations', FacetFilteringTool::getTaxonomyTranslation ( 'section' ) ); parent::jsonBuildResult(); }