Completed
Pull Request — master (#1083)
by
unknown
16:21
created

ApacheSolrDocumentController::indexAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
crap 6
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Controller\Backend\Web\Info;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017 Rafael Kähm <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
28
use ApacheSolrForTypo3\Solr\Domain\Search\Repository\ApacheSolrDocumentRepository;
29
use TYPO3\CMS\Backend\View\BackendTemplateView;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
32
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
33
34
/**
35
 * Administration module controller
36
 *
37
 * @author Ingo Renner <[email protected]>
38
 */
39
class ApacheSolrDocumentController extends ActionController
40
{
41
42
    /**
43
     * Page ID in page context
44
     *
45
     * @var int
46
     */
47
    protected $pageId = 0;
48
49
    /**
50
     * Page ID in page context
51
     *
52
     * @var int
53
     */
54
    protected $languageId = 0;
55
56
    /**
57
     * @var \ApacheSolrForTypo3\Solr\Domain\Search\Repository\ApacheSolrDocumentRepository
58
     * @inject
59
     */
60
    protected $apacheSolrDocumentRepository;
61
62
    /**
63
     * Initializes action
64
     *
65
     * @return void
66
     */
67
    protected function initializeAction()
68
    {
69
        parent::initializeAction();
70
        $pageId = (int)GeneralUtility::_GP('id');
71
        $languageId = (int)GeneralUtility::_GP('L');
72
        $this->initializePageIdAndLanguageId($pageId, $languageId);
73
    }
74
75
    /**
76
     * Initializes required for processing properties page and language Ids
77
     *
78
     * @param $pageId
79
     * @param $languageId
80
     */
81
    public function initializePageIdAndLanguageId($pageId, $languageId)
82
    {
83
        $this->pageId = $pageId;
84
        $this->languageId = $languageId;
85
    }
86
87
    /**
88
     * Lists all avalable apacha solr documents from page
89
     *
90
     * @return string|void
91
     */
92
    public function indexAction()
93
    {
94
        $documents = $this->apacheSolrDocumentRepository->findByPageIdAndByLanguageId($this->pageId, 0);
95
        $documentsByType = [];
96
        foreach ($documents as $document) {
97
            $documentsByType[$document->type][] = $document;
98
        }
99
100
        $this->view->assignMultiple([
101
            'pageId' => $this->pageId,
102
            'documentsByType' => $documentsByType
103
        ]);
104
    }
105
}
106