/**
     * @param int $applicationLocalizedId
     * @return PublisherFolder[]
     */
    public static function getPublisherFolders( $applicationLocalizedId )
    {
        $conditions = array('application_localized_id' => $applicationLocalizedId);

        /* @type $relations ApplicationHasPublisherFolder[] */
        $relations = self::fetchObjectList(
            self::definition(),
            null,
            $conditions
        );

        $publisherFolders = array();

        foreach ($relations as $relation)
        {
            $publisherConditions = array(
                'id' => $relation->attribute('publisher_folder_id'),
            );

            $publisher = PublisherFolder::fetchObject(
                PublisherFolder::definition(),
                null,
                $publisherConditions
            );

            if ( $publisher instanceof PublisherFolder )
            {
                $publisher->setLanguages( $relation->getLanguages() );
                $publisher->setFallback((bool) $relation->attribute('fallback_language'));
                $publisherFolders[$publisher->attribute('path')] = $publisher;
            }
        }

        return $publisherFolders;
    }
    /**
     * 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;
            }
        );
    }
    /**
     * 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 PublisherFolder $publisherFolder
  * @return int
  */
 public static function getPublisherFolderNodeId ( $publisherFolder )
 {
     $mapping = PublisherFolderTool::getNodeIdToPathMapping();
     
     foreach( $mapping as $nodeId => $info )
     {
         if ( $publisherFolder->attribute('path') == $info['path'] )
             return $nodeId;
     }
     
     return false;
 }
    /**
     * @param eZContentObjectTreeNode $node
     * @param string|ApplicationLocalized $application
     * @param boolean $isSolrData
     * @return PublisherFolder
     */
    public static function getPublisherFolder ( $node, $application, $isSolrData = false )
    {
        if( is_string( $application ) )
            $application = CacheApplicationTool::buildLocalizedApplicationByIdentifier($application);

        if ( !($application instanceof ApplicationLocalized) )
            return null;

        $publisherPath = "";

        switch ( true )
        {
            case $isSolrData :
                if ( !is_array($node) || !isset( $node['publisher_path']) )
                    return null;

                $publisherPath = $node['publisher_path'];
                break;
            case ( is_numeric( $node ) && $node > 0 ) :
                $node = eZContentObjectTreeNode::fetch($node);

                if ( !($node instanceof eZContentObjectTreeNode) )
                    return null;

            // No break as we want to use the next step as well
            case ( $node instanceof eZContentObjectTreeNode ) :
            {
                /* @var $node eZContentObjectTreeNode */
                if ( $node->ClassIdentifier != 'publisher_folder' )
                    $publisherPath = PublisherFolderTool::getPublisherFolderPathFromArticleNode($node);
                else
                {
                    $publisherInfo = PublisherFolderTool::getPublisherFolderInfosFromNodeId(
                        $node->attribute('node_id')
                    );
                    $publisherPath = $publisherInfo['path'];
                }
            }
                break;
            case is_string( $node ) :
                $publisherPath = $node;
                break;
        }

        return PublisherFolder::getPublisherFromPath($publisherPath);
//        return $application->getPublisherFolderFromPath($publisherPath);
    }
 /**
  * @return PublisherFolder
  */
 public function getPublisherFolder()
 {
     return PublisherFolder::fetchObject(
         PublisherFolder::definition(),
         null,
         array( 'id' => $this->attribute( 'publisher_folder_id' ) ),
         false
     );
 }
<?php

/* @type $Params string[] */

$clusterIdentifier = $Params['ClusterIdentifier'];
$publisherPath     = $Params['PublisherPath'];
$logoType          = $Params['Type'];

$publisherFolder = PublisherFolder::getPublisherFromPath($publisherPath);

if ($publisherFolder instanceof PublisherFolder === false)
{
    handleError();
}

$publisherFolderTranslation = $publisherFolder->getTranslation();
if ($publisherFolderTranslation instanceof PublisherFolderTranslation === false)
{
    handleError();
}

if ($publisherFolderTranslation->attribute($logoType) == null)
{
    handleError();
}

//we do this only to copy the image into a proper path
$filePath = $publisherFolderTranslation->getFile($logoType);

$filePath = StaticData::clusterFilePath( $clusterIdentifier, "publisher_folders/{$publisherFolder->attribute('path')}/{$logoType}.png" );
    public function render(array $localApplications, array $data, $clusterIdentifier, array $options = array())
    {
        $domainsInClusters = eZINI::instance( 'merck.ini' )->variable( 'DomainMappingSettings', 'ClusterDomains' );
        $domain = $domainsInClusters[$clusterIdentifier];

        $xml = new DOMDocument( '1.0', 'utf-8' );
        $rss = $xml->createElement( 'rss' );
        $rss->setAttribute( 'version', '2.0' );

        $clusterSiteIni = eZINI::fetchFromFile( "extension/{$clusterIdentifier}/settings/site.ini.append.php" );
        $clusterLanguages = $clusterSiteIni->variable( 'RegionalSettings', 'SiteLanguageList' );
        $clusterLanguage = $clusterLanguages[0];

        $rss->appendChild( $xml->createElement( 'language', $clusterLanguage ) );
        $channel = $xml->createElement( 'channel' );

        foreach ( $data as $applicationId => $appFeed )
        {
            foreach( $appFeed as $appArticles)
            {
                $docs = $appArticles['articles'];

                $linkToOverview = false;
                if (SolrSafeOperatorHelper::featureIsActive('newsletterConfig'))
                {
                    $appsLinkedToOverview = SolrSafeOperatorHelper::feature('newsletterConfig', 'applicationsLinkedToOverview');
                    $applicationIdentifier = $localApplications[$applicationId]->attribute('application_object')->attribute('identifier');
                    $linkToOverview = in_array($applicationIdentifier, $appsLinkedToOverview);
                }
                foreach ( $docs as $doc )
                {
                    $publisherPath = $doc['subattr_publisher_folder___source_id____s'][0];
                    $publisherId   = PublisherFolderTool::getPathToIDMapping($publisherPath);
                    $item = $xml->createElement( 'item' );
                    $item->appendChild( $xml->createElement( 'appid', $applicationId ) );

                    $specialities = $xml->createElement( 'specialties', implode( ',', $doc['subattr_speciality___source_id____s'] ) );
                    $item->appendChild( $specialities );

                    $customertypes = $xml->createElement( 'customertypes', implode( ',', $doc['subattr_customer_type___source_id____s'] ) );
                    $item->appendChild( $customertypes );

                    // Title
                    $xmlTitle = $this->escapeStr( $doc['attr_headline_s']);
                    $isEmptyHeadline = trim($doc['attr_promo_headline_t']) == "";

                    if($clusterIdentifier == 'cluster_pt' && !$isEmptyHeadline){
                        $xmlTitle = $this->escapeStr( $doc['attr_promo_headline_t']);
                    }
                    $title = self::createCDATAElement($xml, 'title', $xmlTitle) ;
                    $item->appendChild($title);

                    // Promo headline
                    $promoHeadline = self::createCDATAElement($xml, 'short_title', $doc['attr_promo_headline_t'] );
                    $item->appendChild( $promoHeadline );

                    // Link
                    $merckIni = eZINI::instance( 'merck.ini' );
                    $urlAdditionalValues = $merckIni->variable( 'RssUrlSettings', 'AdditionalValues' );


                    $urlApplication = $localApplications[$applicationId]->attribute('url_alias');
                    if(isset($doc["is_sdk_b"]) && $doc["is_sdk_b"])
                    {
                        $url = $urlApplication . '/' . $doc['meta_url_alias_ms'][0];
                    }
                    else
                    {
                        $url = $urlApplication . '/' . $publisherId['pfid'] . '/' . $doc['attr_' . $clusterIdentifier . '_url_s'];
                    }

                    if ( $linkToOverview )
                    {
                        $linkUrl = 'http://' . rtrim($domain, '/') . $urlApplication;
                        $link = $xml->createElement( 'link', $linkUrl );
                    }
                    else if ( isset( $urlAdditionalValues[$clusterIdentifier] ) )
                    {
                        $linkUrl = 'http://' . rtrim($domain, '/') . '/' . $urlAdditionalValues[$clusterIdentifier] . $url;
                        $link = $xml->createElement( 'link', $linkUrl  );
                    }
                    else
                    {
                        $linkUrl = 'http://' . rtrim($domain, '/') . $url;
                        $link = $xml->createElement( 'link', urlencode( $linkUrl ) );
                    }


                    $item->appendChild( $link );

                    // Author
                    $author = $xml->createElement( 'author', $doc["attr_author_t"] );
                    $item->appendChild( $author );

                    // Source
                    $text = false;
                    $publisherPath = $doc["subattr_publisher_folder___source_id____s"];
                    if($publisherPath && isset($publisherPath[0]))
                    {
                        /** @var PublisherFolder $publisher */
                        $publisher = PublisherFolder::getPublisherFromPath($publisherPath[0]);
                        if( $publisher && $publisher->getTranslation() )
                        {
                            $text = $publisher->getTranslation()->attribute( 'name' );
                        }
                    }
                    $source = $xml->createElement( 'source', $this->escapeStr( htmlspecialchars($text) ) );
                    $item->appendChild( $source );

                    // Description
                    $text = $this->escapeStr( $doc['attr_promo_description_t'] );
                    $text = ( empty( $text ) ? $this->escapeStr( $doc['attr_core_content_t'] ) : $text );

                    $description = self::createCDATAElement( $xml, 'description', $this->escapeStr( $text ) );
                    $item->appendChild( $description );

                    // Publishdate
                    $onlineDate = DateTime::createFromFormat("Y-m-d\TH:i:s\Z", $doc["attr_online_date_dt"])->format('Y-m-d H:i:s');
                    $date = $xml->createElement( 'publishdate', $onlineDate );
                    $item->appendChild( $date );

                    //creationDate
                    $creationDate = DateTime::createFromFormat("Y-m-d\TH:i:s\Z", $doc["attr_date_dt"])->format('Y-m-d H:i:s');
                    $creationDate = $xml->createElement( 'creationdate', $creationDate );
                    $item->appendChild( $creationDate );

                    $mediaContentTypes = json_decode(base64_decode($doc['attr_media_content_types_' . ClusterTool::clusterIdentifier() . '_bst']), true);
                    $hasImageArray = json_decode(base64_decode($doc['attr_has_image_' . $clusterIdentifier . '_bst']));

                    $images = array();
                    if ( $hasPromoImage = SolrSafeOperatorHelper::hasImageArticleFromSolr( array('has_image' => $hasImageArray), 2 ) )
                    {
                        $path = SolrSafeOperatorHelper::getImageArticleUrl(2,$doc['meta_id_si'], $doc['meta_language_code_ms'], 'dt_full');
                        $url = 'http://' . rtrim($domain, '/') . $path;
                        $images[] = $url;
                        $hasPromoImage = 2;
                    }

                    //media_content
                    if( !$hasPromoImage && (isset($mediaContentTypes['image']) || isset($mediaContentTypes['slide'])) )
                    {
                        $slideCount = isset($mediaContentTypes['image']) ? 1 : $mediaContentTypes['slide'];
                        $slideCount = $slideCount > 3 ? 3 : $slideCount;

                        if ( SolrSafeOperatorHelper::hasImageArticleFromSolr( array ( 'has_image' => $hasImageArray ), 0 ) )
                        {
                            for( $i=0; $i<$slideCount; $i++ )
                            {
                                $path = SolrSafeOperatorHelper::getImageArticleUrl(0,$doc['meta_id_si'], $doc['meta_language_code_ms'], 'dt_full', $imageNumber);
                                $url = 'http://' . rtrim($domain, '/') . $path;
                                $images[] = $url;
                            }
                        }
                    }
                    for( $i=0; $i < 3; $i++ )
                    {
                        $imageNumber = ( $i + 1 );
                        if ( $i >= count($images) )
                        {
                            $url = '';
                        }
                        else
                        {
                            $url = $images[$i];
                        }
                        $imageElement = $xml->createElement( 'image' . $imageNumber, $url );
                        $item->appendChild( $imageElement );
                    }

                    // Top
                    $item->appendChild( $xml->createElement( 'top', $doc['attr_featured_content_b'] == '1' ? 1 : 0 ) );

                    // Readcounter
                    $count = 0;
                    if ( isset( $doc['attr_view_counter_' . $clusterIdentifier . '_i'] ) )
                        $count = $doc['attr_view_counter_' . $clusterIdentifier . '_i'];
                    $item->appendChild( $xml->createElement( 'readcounter', $count ) );
                    
                    // Quizreplies
                    $quizReplies = $doc['attr_media_content_quiz_replies_' . $clusterIdentifier . '____ms'];
                    if( isset($quizReplies) && count($quizReplies) > 0 )
                    {
                        $repliesElement = $xml->createElement( 'quizreplies' );
                        for($i = 0; $i < count($quizReplies); $i++)
                        {
                            $repliesElement->appendChild( $xml->createElement( 'quizreply'.$i, $quizReplies[$i] ) );
                        }
                        $item->appendChild( $repliesElement );
                    }

                    $channel->appendChild( $item );

                    eZContentObject::clearCache();
                }
            }
        }

        $rss->appendChild( $channel );
        $xml->appendChild( $rss );

        $xml->formatOutput = true;

        return $xml->saveXML();
    }
    /**
     * @param string $mapping
     * @return array
     */
    private static function buildPublisherFolderMappings($mapping)
    {
        $db                  = eZDB::instance();
        $nodeToPathMapping   = array();
        $pathToIDMapping     = array();
        $publisherFolderList = PublisherFolder::fetchObjectList( PublisherFolder::definition(),array('path', 'id'), null, null, null, false );
        $pfRemotes           = array();
        $pfByPath            = array();

        foreach(array_keys($publisherFolderList) as $key )
        {
            $pf                    = $publisherFolderList[$key];
            $pfByPath[$pf['path']] = $pf['id'];
            $pfRemotes[]           = "\"publisher_folder-{$pf['path']}\"";
        }

        $pfRemotesString = implode( ',', $pfRemotes );
        $query = "
            SELECT c.remote_id as remote, ct.main_node_id as main_node
                FROM ezcontentobject c, ezcontentobject_tree ct
                WHERE c.remote_id IN ( $pfRemotesString ) and c.id = ct.contentobject_id and ct.node_id = ct.main_node_id";

        $results = $db->arrayQuery($query);
        
        foreach ( $results as $line )
        {
            $m = array();
            if (preg_match("#^publisher_folder-(.*)$#", $line['remote'], $m))
                $pfPath = $m[1];
            else
                continue;
            
            $nodeId = $line['main_node'];
            
            $pathToIDMapping[$pfPath]   = array( 'nid'  => $nodeId, 'pfid' => $pfByPath[$pfPath] );
            $nodeToPathMapping[$nodeId] = array( 'path' => $pfPath  , 'pfid' => $pfByPath[$pfPath] );
        }

        GlobalCacheTool::dailyValue( 'publisherFolderPathToIDMapping', $pathToIDMapping );
        GlobalCacheTool::dailyValue( 'publisherFolderNodeIdToPathMapping', $nodeToPathMapping );
        
        switch ($mapping)
        {
            case 'publisherFolderPathToIDMapping' :
                return $pathToIDMapping;
            case 'publisherFolderNodeIdToPathMapping' :
                return $nodeToPathMapping;
        }

        return array();
    }