Bundle/AnalyticsBundle/Helper/AnalyticsViewHelper.php
public function getMostReadArticlesByBlog($blog, $number, $excludeUnpublished = true)
    {
        $viewReferences = [];
        //get articles and viewReferenceIds
        $articles = $this->entityManager->getRepository('Victoire\Bundle\BlogBundle\Entity\Article')
                    ->getAll($excludeUnpublished)
                    ->filterByBlog($blog)
                    ->run();

        foreach ($articles as $key => $article) {
            if ($viewReference = $this->viewReferenceRepository->getOneReferenceByParameters(
                [
                    'entityNamespace' => 'Victoire\Bundle\BlogBundle\Entity\Article',
                    'entityId' => $article->getId(),
                ]
            )) {
                $viewReferences[$viewReference->getId()] = $viewReference;
            }
        }
        //get pager
        $browseEvents = $this->entityManager->getRepository('Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent')
            ->getMostVisitedFromReferences(array_keys($viewReferences), $number)
            ->getQuery()
            ->getResult();

        $views = [];
        //Now we get the most visited references, we'll get views with PageHelper
        foreach ($browseEvents as $browseEvent) {
            $views[] = $this->pageHelper->findPageByReference(
                $viewReferences[$browseEvent->getViewReferenceId()]
            );
        }

        return $views;
    }
public function getMostReadArticlesByBlog($blog, $number, $excludeUnpublished = true)
    {
        $viewReferences = [];
        //get articles and viewReferenceIds
        $articles = $this->entityManager->getRepository('Victoire\Bundle\BlogBundle\Entity\Article')
                    ->getAll($excludeUnpublished)
                    ->filterByBlog($blog)
                    ->run();

        foreach ($articles as $key => $article) {
            if ($viewReference = $this->viewReferenceRepository->getOneReferenceByParameters(
                [
                    'entityNamespace' => 'Victoire\Bundle\BlogBundle\Entity\Article',
                    'entityId' => $article->getId(),
                ]
            )) {
                $viewReferences[$viewReference->getId()] = $viewReference;
            }
        }
        //get pager
        $browseEvents = $this->entityManager->getRepository('Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent')
            ->getMostVisitedFromReferences(array_keys($viewReferences), $number)
            ->getQuery()
            ->getResult();

        $views = [];
        //Now we get the most visited references, we'll get views with PageHelper
        foreach ($browseEvents as $browseEvent) {
            $views[] = $this->pageHelper->findPageByReference(
                $viewReferences[$browseEvent->getViewReferenceId()]
            );
        }

        return $views;
    }
public function getMostReadArticlesByBlog ( $ blog , $ number , $ excludeUnpublished = true ) { $ viewReferences = [ ] ; //get articles and viewReferenceIds $ articles = $ this -> entityManager -> getRepository ( 'Victoire\Bundle\BlogBundle\Entity\Article' ) -> getAll ( $ excludeUnpublished ) -> filterByBlog ( $ blog ) -> run ( ) ; foreach ( $ articles as $ key => $ article ) { if ( $ viewReference = $ this -> viewReferenceRepository -> getOneReferenceByParameters ( [ 'entityNamespace' => 'Victoire\Bundle\BlogBundle\Entity\Article' , 'entityId' => $ article -> getId ( ) , ] ) ) { $ viewReferences [ $ viewReference -> getId ( ) ] = $ viewReference ; } } //get pager $ browseEvents = $ this -> entityManager -> getRepository ( 'Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent' ) -> getMostVisitedFromReferences ( array_keys ( $ viewReferences ) , $ number ) -> getQuery ( ) -> getResult ( ) ; $ views = [ ] ; //Now we get the most visited references, we'll get views with PageHelper foreach ( $ browseEvents as $ browseEvent ) { $ views [ ] = $ this -> pageHelper -> findPageByReference ( $ viewReferences [ $ browseEvent -> getViewReferenceId ( ) ] ) ; } return $ views ; }
Get the most read articles by blog.

@return Article[]
Get the most read articles by blog .