Ejemplo n.º 1
0
    /**
     * Index action method
     */
    public function indexAction()
    {
        $categoryId = (int)$this->Request()->getQuery('sCategory');
        $sPage = !empty($this->Request()->sPage) ? (int)$this->Request()->sPage : 1;
        $sFilterDate = urldecode($this->Request()->sFilterDate);
        $sFilterAuthor = urldecode($this->Request()->sFilterAuthor);
        $sFilterTags = urldecode($this->Request()->sFilterTags);

        // PerPage
        if (!empty($this->Request()->sPerPage)) {
            Shopware()->Session()->sPerPage = (int)$this->Request()->sPerPage;
        }
        $sPerPage = Shopware()->Session()->sPerPage;
        if (empty($sPerPage)) {
            $sPerPage = (int)Shopware()->Config()->get('sARTICLESPERPAGE');
        }

        $filter = $this->createFilter($sFilterDate, $sFilterAuthor, $sFilterTags);

        // Start for Limit
        $sLimitStart = ($sPage - 1) * $sPerPage;
        $sLimitEnd = $sPerPage;

        //get all blog articles
        $query = $this->getCategoryRepository()->getBlogCategoriesByParentQuery($categoryId);
        $blogCategories = $query->getArrayResult();
        $blogCategoryIds = $this->getBlogCategoryListIds($blogCategories);
        $blogCategoryIds[] = $categoryId;
        $blogArticlesQuery = $this->getRepository()->getListQuery($blogCategoryIds, $sLimitStart, $sLimitEnd, $filter);
        $blogArticlesQuery->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
        $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($blogArticlesQuery);

        //returns the total count of the query
        $totalResult = $paginator->count();

        //returns the blog article data
        $blogArticles = $paginator->getIterator()->getArrayCopy();

        foreach ($blogArticles as $key => $blogArticle) {
            //adding number of comments to the blog article
            $blogArticles[$key]["numberOfComments"] = count($blogArticle["comments"]);

            //adding tags and tag filter links to the blog article
            $tagsQuery = $this->repository->getTagsByBlogId($blogArticle["id"]);
            $tagsData = $tagsQuery->getArrayResult();
            $blogArticles[$key]["tags"] = $this->addLinksToFilter($tagsData, "sFilterTags", "name", false);

            //adding average vote data to the blog article
            $avgVoteQuery = $this->repository->getAverageVoteQuery($blogArticle["id"]);
            $blogArticles[$key]["sVoteAverage"] = $avgVoteQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_SINGLE_SCALAR);

            //adding thumbnails to the blog article
            if (!empty($blogArticle["media"][0]['mediaId'])) {
                /**@var $mediaModel \Shopware\Models\Media\Media*/
                $mediaModel = Shopware()->Models()->find('Shopware\Models\Media\Media', $blogArticle["media"][0]['mediaId']);
                if ($mediaModel != null) {
                    $blogArticles[$key]["preview"]["thumbNails"] = array_values($mediaModel->getThumbnails());
                }
            }
        }

        //RSS and ATOM Feed part
        if ($this->Request()->getParam('sRss') || $this->Request()->getParam('sAtom')) {
            $this->Response()->setHeader('Content-Type', 'text/xml');
            $type = $this->Request()->getParam('sRss') ? 'rss' : 'atom';
            $this->View()->loadTemplate('frontend/blog/' . $type . '.tpl');
        }

        $categoryContent = Shopware()->Modules()->Categories()->sGetCategoryContent($categoryId);
        $assigningData = array(
            'sBanner' => Shopware()->Modules()->Marketing()->sBanner($categoryId),
            'sBreadcrumb' => $this->getCategoryBreadcrumb($categoryId),
            'sCategoryContent' => $categoryContent,
            'sNumberArticles' => $totalResult,
            'sPage' => $sPage,
            'sFilterDate' => $this->getDateFilterData($blogCategoryIds, $filter),
            'sFilterAuthor' => $this->getAuthorFilterData($blogCategoryIds, $filter),
            'sFilterTags' => $this->getTagsFilterData($blogCategoryIds, $filter),
            'sCategoryInfo' => $categoryContent,
            'sBlogArticles' => $blogArticles
        );

        $this->View()->assign(array_merge($assigningData, $this->getPagerData($totalResult, $sLimitEnd, $sPage, $categoryId)));
    }
Ejemplo n.º 2
0
 /**
  * Index action method
  */
 public function indexAction()
 {
     $categoryId = (int) $this->Request()->getQuery('sCategory');
     $sPage = !empty($this->Request()->sPage) ? (int) $this->Request()->sPage : 1;
     $sFilterDate = urldecode($this->Request()->sFilterDate);
     $sFilterAuthor = urldecode($this->Request()->sFilterAuthor);
     $sFilterTags = urldecode($this->Request()->sFilterTags);
     // Redirect if blog's category is not a child of the current shop's category
     $shopCategory = Shopware()->Shop()->getCategory();
     $category = $this->getCategoryRepository()->findOneBy(array('id' => $categoryId, 'active' => true));
     $isChild = $shopCategory && $category ? $category->isChildOf($shopCategory) : false;
     if (!$isChild) {
         return $this->redirect(array('controller' => 'index'), array('code' => 301));
     }
     // PerPage
     if (!empty($this->Request()->sPerPage)) {
         Shopware()->Session()->sPerPage = (int) $this->Request()->sPerPage;
     }
     $sPerPage = Shopware()->Session()->sPerPage;
     if (empty($sPerPage)) {
         $sPerPage = (int) Shopware()->Config()->get('sARTICLESPERPAGE');
     }
     $filter = $this->createFilter($sFilterDate, $sFilterAuthor, $sFilterTags);
     // Start for Limit
     $sLimitStart = ($sPage - 1) * $sPerPage;
     $sLimitEnd = $sPerPage;
     //get all blog articles
     $query = $this->getCategoryRepository()->getBlogCategoriesByParentQuery($categoryId);
     $blogCategories = $query->getArrayResult();
     $blogCategoryIds = $this->getBlogCategoryListIds($blogCategories);
     $blogCategoryIds[] = $categoryId;
     $blogArticlesQuery = $this->getRepository()->getListQuery($blogCategoryIds, $sLimitStart, $sLimitEnd, $filter);
     $blogArticlesQuery->setHydrationMode(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
     $paginator = Shopware()->Models()->createPaginator($blogArticlesQuery);
     //returns the total count of the query
     $totalResult = $paginator->count();
     //returns the blog article data
     $blogArticles = $paginator->getIterator()->getArrayCopy();
     $mediaIds = array_map(function ($blogArticle) {
         if (isset($blogArticle['media']) && $blogArticle['media'][0]['mediaId']) {
             return $blogArticle['media'][0]['mediaId'];
         }
     }, $blogArticles);
     $context = $this->get('shopware_storefront.context_service')->getShopContext();
     $medias = $this->get('shopware_storefront.media_service')->getList($mediaIds, $context);
     foreach ($blogArticles as $key => $blogArticle) {
         //adding number of comments to the blog article
         $blogArticles[$key]["numberOfComments"] = count($blogArticle["comments"]);
         //adding tags and tag filter links to the blog article
         $tagsQuery = $this->repository->getTagsByBlogId($blogArticle["id"]);
         $tagsData = $tagsQuery->getArrayResult();
         $blogArticles[$key]["tags"] = $this->addLinksToFilter($tagsData, "sFilterTags", "name", false);
         //adding average vote data to the blog article
         $avgVoteQuery = $this->repository->getAverageVoteQuery($blogArticle["id"]);
         $blogArticles[$key]["sVoteAverage"] = $avgVoteQuery->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_SINGLE_SCALAR);
         //adding thumbnails to the blog article
         if (empty($blogArticle["media"][0]['mediaId'])) {
             continue;
         }
         $mediaId = $blogArticle["media"][0]['mediaId'];
         if (!isset($medias[$mediaId])) {
             continue;
         }
         /**@var $media \Shopware\Bundle\StoreFrontBundle\Struct\Media*/
         $media = $medias[$mediaId];
         $media = $this->get('legacy_struct_converter')->convertMediaStruct($media);
         if (Shopware()->Shop()->getTemplate()->getVersion() < 3) {
             $blogArticles[$key]["preview"]["thumbNails"] = array_column($media['thumbnails'], 'source');
         } else {
             $blogArticles[$key]['media'] = $media;
         }
     }
     //RSS and ATOM Feed part
     if ($this->Request()->getParam('sRss') || $this->Request()->getParam('sAtom')) {
         $this->Response()->setHeader('Content-Type', 'text/xml');
         $type = $this->Request()->getParam('sRss') ? 'rss' : 'atom';
         $this->View()->loadTemplate('frontend/blog/' . $type . '.tpl');
     }
     /**@var $repository \Shopware\Models\Emotion\Repository*/
     $repository = Shopware()->Models()->getRepository('Shopware\\Models\\Emotion\\Emotion');
     $query = $repository->getCampaignByCategoryQuery($categoryId);
     $campaignsResult = $query->getArrayResult();
     $campaigns = array();
     foreach ($campaignsResult as $campaign) {
         $campaign['categoryId'] = $categoryId;
         $campaigns[$campaign['landingPageBlock']][] = $campaign;
     }
     $categoryContent = Shopware()->Modules()->Categories()->sGetCategoryContent($categoryId);
     $assigningData = array('sBanner' => Shopware()->Modules()->Marketing()->sBanner($categoryId), 'sBreadcrumb' => $this->getCategoryBreadcrumb($categoryId), 'sCategoryContent' => $categoryContent, 'sNumberArticles' => $totalResult, 'sPage' => $sPage, 'sPerPage' => $sPerPage, 'sFilterDate' => $this->getDateFilterData($blogCategoryIds, $filter), 'sFilterAuthor' => $this->getAuthorFilterData($blogCategoryIds, $filter), 'sFilterTags' => $this->getTagsFilterData($blogCategoryIds, $filter), 'sCategoryInfo' => $categoryContent, 'sBlogArticles' => $blogArticles, 'campaigns' => $campaigns);
     $this->View()->assign(array_merge($assigningData, $this->getPagerData($totalResult, $sLimitEnd, $sPage, $categoryId)));
 }