/**
     * @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;
    }
 /**
  * @return PublisherFolder
  */
 public function getPublisherFolder()
 {
     return PublisherFolder::fetchObject(
         PublisherFolder::definition(),
         null,
         array( 'id' => $this->attribute( 'publisher_folder_id' ) ),
         false
     );
 }
    /**
     * @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();
    }