Details.php 2.43 KB
Newer Older
1
<?php
2
/**
3 4
 * Copyright (c) 2016 by the ACP3 Developers.
 * See the LICENCE file at the top-level module directory for licencing details.
5
 */
6

7
namespace ACP3\Modules\ACP3\Articles\Controller\Frontend\Index;
8 9 10 11 12

use ACP3\Core;
use ACP3\Modules\ACP3\Articles;

/**
13 14
 * Class Details
 * @package ACP3\Modules\ACP3\Articles\Controller\Frontend\Index
15
 */
16
class Details extends Core\Controller\FrontendAction
17 18 19 20 21 22
{
    /**
     * @var \ACP3\Core\Date
     */
    protected $date;
    /**
23
     * @var \ACP3\Core\Helpers\PageBreaks
24
     */
25
    protected $pageBreaksHelper;
26
    /**
27
     * @var \ACP3\Modules\ACP3\Articles\Model\ArticleRepository
28
     */
29
    protected $articleRepository;
30 31 32 33 34 35
    /**
     * @var \ACP3\Modules\ACP3\Articles\Cache
     */
    protected $articlesCache;

    /**
36 37
     * Details constructor.
     *
38
     * @param \ACP3\Core\Controller\Context\FrontendContext       $context
39 40 41 42
     * @param \ACP3\Core\Date                                     $date
     * @param \ACP3\Core\Helpers\PageBreaks                       $pageBreaksHelper
     * @param \ACP3\Modules\ACP3\Articles\Model\ArticleRepository $articleRepository
     * @param \ACP3\Modules\ACP3\Articles\Cache                   $articlesCache
43 44
     */
    public function __construct(
45
        Core\Controller\Context\FrontendContext $context,
46
        Core\Date $date,
47
        Core\Helpers\PageBreaks $pageBreaksHelper,
48
        Articles\Model\ArticleRepository $articleRepository,
49 50 51 52 53
        Articles\Cache $articlesCache)
    {
        parent::__construct($context);

        $this->date = $date;
54
        $this->pageBreaksHelper = $pageBreaksHelper;
55
        $this->articleRepository = $articleRepository;
56 57 58
        $this->articlesCache = $articlesCache;
    }

59 60 61
    /**
     * @param int $id
     *
62
     * @return array
63
     * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
64
     */
65
    public function execute($id)
66
    {
67
        if ($this->articleRepository->resultExists($id, $this->date->getCurrentDateTime()) === true) {
68
            $article = $this->articlesCache->getCache($id);
69
            
70
            $this->breadcrumb->replaceAncestor($article['title'], '', true);
71

72
            return [
73 74 75 76
                'page' => $this->pageBreaksHelper->splitTextIntoPages(
                    $this->view->fetchStringAsTemplate($article['text']),
                    $this->request->getUriWithoutPages()
                )
77
            ];
78
        }
79

80
        throw new Core\Controller\Exception\ResultNotExistsException();
81 82
    }
}