/**
     * @return ApplicationObject[]
     */
    public function getAppsToAdd()
    {
        $applications = array();

        $env = new MMEnvironment();
        $controller = new MMHomePageController();
        $zones = $controller->fetchZones( $env->currentId() );
        foreach( $zones['right'] as $block )
        {
            if( $block->Type == MMBlock::TYPE_CAROUSEL )
            {
                $apps = json_decode( $block->Content );
                foreach( $apps->application_list as $appId )
                {
                    $appLocalized = CacheApplicationTool::buildLocalizedApplicationByLocalizedId( $appId );
                    if( !$appLocalized )
                    {
                        continue;
                    }                    
                    $applications[] = $appLocalized->applicationObject();
                }
            }
        }

        return $applications;

    }
    /**
     * Creates a new instance
     *
     * @param int $appId Localized Application Id
     * @param int $nbArticles Number of articles
     * @param int $viewMode View mode to use
     * @param int $publisherId Id of Publisher
     * @param int $selectionType Selection type to use
     **/
    public function __construct( $appId, $nbArticles, $viewMode, $publisherId, $selectionType )
    {
        $this->applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByLocalizedId($appId);
        $this->applicationObject    = $this->applicationLocalized->applicationObject();
        $this->nbArticles           = $nbArticles;
        $this->viewMode             = $viewMode;
        $this->publisherId          = $publisherId;
        $this->selectionType        = $selectionType;
        $applicationName            = $this->applicationLocalized->attribute('url');

        if($applicationName)
            $this->_application = ApplicationFactory::fetchByUri( '/'.$applicationName );
    }
    /**
     * Fetches and returns a list of localized applications
     *
     * @return ApplicationLocalized[]
     **/
    protected function fetchApplications()
    {
        $apps = array();
        foreach( $this->appIdList as $appId )
        {
            $app = CacheApplicationTool::buildLocalizedApplicationByLocalizedId($appId);
            if( !$app )
            {
                continue;
            }
            $apps[] = $app;

        }
        return $apps;
    }
Esempio n. 4
0
    /**
     * @param ChannelBlockConfiguration $configuration
     * @param ChannelBlock $block
     * @return string
     */
    private function getLinkMore(ChannelBlockConfiguration $configuration, ChannelBlock $block)
    {
        $query = "/(channel)/".$block->attribute("id");
        if($block->attribute("sorting_method") && $block->attribute("sorting_method") != "")
        {
            $query .= "#?s=".$block->attribute("sorting_method");
        }

        $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByLocalizedId($configuration->attribute("application_localized_id"));
        return $applicationLocalized->applicationUrl().$query;
    }
    /**
     * @return string    fq parameter for the current configuration
     */
    public function getSolrFq()
    {
        $facets = eZINI::instance("merck.ini")->variable("ApplicationObjectSettings", "FacetMapping");
        $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByLocalizedId($this->attribute("application_localized_id"));
        $applicationFacets = array();
        if ( $applicationLocalized instanceof ApplicationLocalized ) {
            $applicationFacets = $applicationLocalized->applicationObject()->getContentServiceConfiguration()->getFacetList();
        }

        $mappingFacetClasses = array();
        /** @var ApplicationFacet $applicationFacet */
        foreach($applicationFacets as $applicationFacet)
        {
            $facetType = $applicationFacet->attribute("facet_type");
            if(isset($facets[$facetType]))
            {
                $mappingFacetClasses[$applicationFacet->attribute("attribute_identifier")] = $facets[$facetType];
            }
        }

        $finalFilters = array();
        $fq = $this->attribute("fq");

        if(!$fq || $fq == "")
        {
            return "";
        }

        $fields = json_decode($fq, true);
        if(!is_array($fields))
        {
            return null;
        }

        foreach($fields as $field => $values)
        {

            $filterOr = array();
            foreach($values as $value)
            {
                if($mappingFacetClasses[$field] && method_exists( $mappingFacetClasses[$field], 'getMapping' ))
                {
                    // special case when we have special value and not values like 201.1. Like for FacetPublisherSince
                    $className = $mappingFacetClasses[$field];
                    $mapping = $className::getMapping($field);

                    foreach($mapping as $data)
                    {
                        if($data["label"] == $value)
                        {
                            $filterOr[] = $data["query"];
                            break;
                        }
                    }
                }
                else if ($field == 'depth')
                {
                    $filterOr[] = sprintf('attr_relative_depth_i: %s', $value);
                }
                else
                {
                    $filterOr[] = sprintf('subattr_%s___source_id____s:"%s"', $field, $value);
                }
            }

            $finalFilters[] = '('.implode(" OR ", $filterOr).')';
        }
        $useDepth = $applicationLocalized->getCustomParameter('ShowParentArticleOnly');
        if (!$useDepth)
        {
            $useDepth = $applicationLocalized->applicationObject()->getCustomParameter('ShowParentArticleOnly');
        }
        if ($useDepth) {
            $finalFilters[] = 'attr_relative_depth_i: 0';
        }
        return implode(" AND ", $finalFilters);
    }
Esempio n. 6
0
    /**
     * Renders (as HTML) the contents of this block
     *
     * @return string HTML
     **/
    public function render()
    {
        /* @type $presenter MMBlockInterface */
        $jsonContent = json_decode( $this->attribute('content') );
        switch( $this->attribute('type') )
        {
            case self::TYPE_CONTENT:
                $presenter = new MMBlockContentPresenter(
                    $jsonContent->{'static_page_id'}
                );
                break;
            case self::TYPE_APPLIST:
                $appLocalized = CacheApplicationTool::buildLocalizedApplicationByLocalizedId( $jsonContent->{'application_localized_id'} );
                if ( $appLocalized instanceof ApplicationLocalized )
                {
                    $presenter = new MMBlockAppListPresenter(
                        $jsonContent->{'application_localized_id'},
                        $jsonContent->{'nb_articles'},
                        $jsonContent->{'view_mode'},
                        $jsonContent->{'publisher_id'},
                        $jsonContent->{'selection_type'}
                    );
                }
                break;
            case self::TYPE_CAROUSEL:
                $presenter = new MMBlockCarouselPresenter(
                    $jsonContent->{'application_list'}
                );
                break;
            case self::TYPE_CHANNEL:
                $presenter = new MMBlockChannelPresenter(
                    $this->attribute('name'),
                    $jsonContent->{'nb_items'}
                );
                break;
            case self::TYPE_FEATURED_CHANNEL:
                $presenter = new MMBlockFeaturedChannelPresenter(
                    $this->attribute('name'),
                    $jsonContent->{'nb_articles'}
                );
                break;
            case self::TYPE_CONGRESS_REPORT:
                $presenter = new MMBlockCongressReportPresenter(
                    $this->attribute('name'),
                    $jsonContent->{'nb_articles'}
                );

                break;
        }

        if ( $presenter instanceof MMBlockInterface )
            $html = $presenter->render();
        else
            $html = '';

        return $html;
    }
    /**
     * @param string clusterIdentifier
     * @param array $applicationIds
     * @return string
     */
    protected function bulidUpdateXml( $clusterIdentifier, $applicationIds = array() )
    {
        $xml = '<add>';

        $sql  = $this->getSql( $clusterIdentifier );
        if ( !empty( $applicationIds ) )
        {
            $sql .= sprintf( " AND a.id IN ('%s')", implode( "','" , $applicationIds ) );
        }

        $applications = MMDB::instance()->arrayQuery( $sql );
        foreach( $applications as $row )
        {
            $application = new ApplicationLocalized( $row );

            $cacheApp = CacheApplicationTool::buildLocalizedApplicationByLocalizedId($application->id);
            
            if( !($cacheApp instanceof ApplicationLocalized) )
            {
                continue;
            }     
            $xml .= '<doc>';
            $this->addField( $xml, self::META_INSTALLATION_ID_MS_KEY, self::META_INSTALLATION_ID_MS_VAL );
            $this->addField( $xml, 'meta_guid_ms', md5( $application->application_id ) . "-{$application->cluster_identifier}" );
            $this->addField( $xml, 'identifier_s', $row['application_identifier'] );
            $this->addField( $xml, 'name_s', htmlspecialchars( $application->name ) );
            $this->addField( $xml, 'cluster_identifier_s', $application->cluster_identifier );

            $headlineKeywords = $this->prepareHeadlineKeywords($application->headline);

            foreach ($headlineKeywords as $headlineKeyword) {
                $this->addField( $xml, self::HEADLINE_KEYWORD, self::prepareKeywordString( $headlineKeyword ) );
            }


            $keywords = $application->getKeywords();
            if ( is_array( $keywords ) )
            {
                foreach ( $keywords as $keyword )
                {
                    $this->addField( $xml, self::META_APPLICATION_KEYWORD, self::prepareKeywordString( $keyword ) );
                }
            }
            $xml .= '</doc>';
        }

        $xml .= '</add>';
        return $xml;
    }
 public function getApplicationLocalized()
 {
     return CacheApplicationTool::buildLocalizedApplicationByLocalizedId($this->attribute("channel_application_localized_id"));
 }