We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * (c) Kitodo. Key to digital objects e.V. <[email protected]> |
||
5 | * |
||
6 | * This file is part of the Kitodo and TYPO3 projects. |
||
7 | * |
||
8 | * @license GNU General Public License version 3 or later. |
||
9 | * For the full copyright and license information, please read the |
||
10 | * LICENSE.txt file that was distributed with this source code. |
||
11 | */ |
||
12 | |||
13 | namespace Kitodo\Dlf\Hooks; |
||
14 | |||
15 | use Kitodo\Dlf\Common\Helper; |
||
16 | use Psr\Log\LoggerAwareInterface; |
||
17 | use Psr\Log\LoggerAwareTrait; |
||
18 | use TYPO3\CMS\Backend\Utility\BackendUtility; |
||
19 | use TYPO3\CMS\Core\Configuration\ConfigurationManager; |
||
20 | use TYPO3\CMS\Core\Database\ConnectionPool; |
||
21 | use TYPO3\CMS\Core\TypoScript\TemplateService; |
||
22 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
23 | |||
24 | /** |
||
25 | * Helper for FlexForm's custom "itemsProcFunc" |
||
26 | * |
||
27 | * @package TYPO3 |
||
28 | * @subpackage dlf |
||
29 | * |
||
30 | * @access public |
||
31 | */ |
||
32 | class ItemsProcFunc implements LoggerAwareInterface |
||
33 | { |
||
34 | use LoggerAwareTrait; |
||
35 | |||
36 | /** |
||
37 | * @access protected |
||
38 | * @var int |
||
39 | */ |
||
40 | protected $storagePid; |
||
41 | |||
42 | /** |
||
43 | * Helper to get flexform's items array for plugin "Toolbox" |
||
44 | * |
||
45 | * @access public |
||
46 | * |
||
47 | * @param array &$params An array with parameters |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function toolList(array &$params): void |
||
52 | { |
||
53 | $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); |
||
54 | $options = $configurationManager->getLocalConfigurationValueByPath('SC_OPTIONS'); |
||
55 | foreach ($options['dlf/Classes/Plugin/Toolbox.php']['tools'] as $class => $label) { |
||
56 | $params['items'][] = [Helper::getLanguageService()->sL($label), $class]; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Extract typoScript configuration from site root of the plugin |
||
62 | * |
||
63 | * @access public |
||
64 | * |
||
65 | * @param array $params |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | public function getTyposcriptConfigFromPluginSiteRoot(array $params): void |
||
70 | { |
||
71 | $pid = $params['flexParentDatabaseRow']['pid']; |
||
72 | $rootLine = BackendUtility::BEgetRootLine($pid); |
||
73 | $siteRootRow = []; |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
74 | foreach ($rootLine as $row) { |
||
75 | if (isset($row['is_siteroot'])) { |
||
76 | $siteRootRow = $row; |
||
77 | break; |
||
78 | } |
||
79 | } |
||
80 | |||
81 | try { |
||
82 | $ts = GeneralUtility::makeInstance(TemplateService::class); |
||
83 | $ts->rootLine = $rootLine; |
||
84 | $ts->runThroughTemplates($rootLine, 0); |
||
85 | $ts->generateConfig(); |
||
86 | $typoScriptConfig = $ts->setup; |
||
87 | $this->storagePid = $typoScriptConfig['plugin.']['tx_dlf.']['persistence.']['storagePid']; |
||
88 | } catch (\Exception $e) { |
||
89 | $this->logger->error($e->getMessage()); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Helper to get flexForm's items array for plugin "Search" |
||
95 | * |
||
96 | * @access public |
||
97 | * |
||
98 | * @param array &$params An array with parameters |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | public function extendedSearchList(array &$params): void |
||
103 | { |
||
104 | $this->generateList( |
||
105 | $params, |
||
106 | 'label,index_name', |
||
107 | 'tx_dlf_metadata', |
||
108 | 'label', |
||
109 | 'index_indexed=1' |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Helper to get flexForm's items array for plugin "Search" |
||
115 | * |
||
116 | * @access public |
||
117 | * |
||
118 | * @param array &$params An array with parameters |
||
119 | */ |
||
120 | public function getFacetsList(array &$params): void |
||
121 | { |
||
122 | $this->generateList( |
||
123 | $params, |
||
124 | 'label,index_name', |
||
125 | 'tx_dlf_metadata', |
||
126 | 'label', |
||
127 | 'is_facet=1' |
||
128 | ); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get list items from database |
||
133 | * |
||
134 | * @access protected |
||
135 | * |
||
136 | * @param array &$params An array with parameters |
||
137 | * @param string $fields Comma-separated list of fields to fetch |
||
138 | * @param string $table Table name to fetch the items from |
||
139 | * @param string $sorting Field to sort items by (optionally appended by 'ASC' or 'DESC') |
||
140 | * @param string $andWhere Additional AND WHERE clause |
||
141 | * |
||
142 | * @return void |
||
143 | */ |
||
144 | protected function generateList(array &$params, string $fields, string $table, string $sorting, string $andWhere = ''): void |
||
145 | { |
||
146 | $this->getTyposcriptConfigFromPluginSiteRoot($params); |
||
147 | |||
148 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
||
149 | ->getQueryBuilderForTable($table); |
||
150 | |||
151 | // Get $fields from $table on given pid. |
||
152 | $result = $queryBuilder |
||
153 | ->select(...explode(',', $fields)) |
||
154 | ->from($table) |
||
155 | ->where( |
||
156 | $queryBuilder->expr()->eq($table . '.pid', $this->storagePid), |
||
157 | $queryBuilder->expr()->in($table . '.sys_language_uid', [-1, 0]), |
||
158 | $andWhere |
||
159 | ) |
||
160 | ->orderBy($sorting) |
||
161 | ->execute(); |
||
162 | |||
163 | while ($resArray = $result->fetchNumeric()) { |
||
164 | $params['items'][] = $resArray; |
||
165 | } |
||
166 | } |
||
167 | } |
||
168 |