Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
BlockLoader | |
0.00% |
0 / 16 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getFromSearchClassId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getFromOptions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFromConfig | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getFromConfigObject | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | /** |
4 | * Content block loader |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2018. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package ContentBlock |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
28 | */ |
29 | |
30 | namespace VuFind\ContentBlock; |
31 | |
32 | use Laminas\Config\Config; |
33 | use VuFind\Config\PluginManager as ConfigManager; |
34 | use VuFind\ContentBlock\PluginManager as BlockManager; |
35 | use VuFind\Search\Base\Options; |
36 | use VuFind\Search\Options\PluginManager as OptionsManager; |
37 | |
38 | /** |
39 | * Content block plugin manager |
40 | * |
41 | * @category VuFind |
42 | * @package ContentBlock |
43 | * @author Demian Katz <demian.katz@villanova.edu> |
44 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
45 | * @link https://vufind.org/wiki/development:plugins:recommendation_modules Wiki |
46 | */ |
47 | class BlockLoader |
48 | { |
49 | /** |
50 | * Options manager. |
51 | * |
52 | * @var OptionsManager |
53 | */ |
54 | protected $optionsManager; |
55 | |
56 | /** |
57 | * Config manager. |
58 | * |
59 | * @var ConfigManager |
60 | */ |
61 | protected $configManager; |
62 | |
63 | /** |
64 | * Block manager. |
65 | * |
66 | * @var BlockManager |
67 | */ |
68 | protected $blockManager; |
69 | |
70 | /** |
71 | * Constructor |
72 | * |
73 | * @param OptionsManager $om Options manager |
74 | * @param ConfigManager $cm Config manager |
75 | * @param BlockManager $bm Block manager |
76 | */ |
77 | public function __construct( |
78 | OptionsManager $om, |
79 | ConfigManager $cm, |
80 | BlockManager $bm |
81 | ) { |
82 | $this->optionsManager = $om; |
83 | $this->configManager = $cm; |
84 | $this->blockManager = $bm; |
85 | } |
86 | |
87 | /** |
88 | * Fetch blocks using a search class ID. |
89 | * |
90 | * @param string $searchClassId Search class ID |
91 | * |
92 | * @return array |
93 | */ |
94 | public function getFromSearchClassId($searchClassId) |
95 | { |
96 | $options = $this->optionsManager->get($searchClassId); |
97 | return $this->getFromOptions($options); |
98 | } |
99 | |
100 | /** |
101 | * Fetch blocks using an Options object. |
102 | * |
103 | * @param Options $options Options object |
104 | * |
105 | * @return array |
106 | */ |
107 | public function getFromOptions(Options $options) |
108 | { |
109 | return $this->getFromConfig($options->getSearchIni()); |
110 | } |
111 | |
112 | /** |
113 | * Fetch blocks using a configuration name |
114 | * |
115 | * @param string $name Configuration name |
116 | * @param string $section Section to load from object |
117 | * @param string $setting Setting to load from section |
118 | * |
119 | * @return array |
120 | */ |
121 | public function getFromConfig( |
122 | $name, |
123 | $section = 'HomePage', |
124 | $setting = 'content' |
125 | ) { |
126 | $config = $this->configManager->get($name); |
127 | return $this->getFromConfigObject($config, $section, $setting); |
128 | } |
129 | |
130 | /** |
131 | * Fetch blocks using Config object. |
132 | * |
133 | * @param Config $config Configuration object |
134 | * @param string $section Section to load from object |
135 | * @param string $setting Setting to load from section |
136 | * |
137 | * @return array |
138 | */ |
139 | public function getFromConfigObject( |
140 | Config $config, |
141 | $section = 'HomePage', |
142 | $setting = 'content' |
143 | ) { |
144 | $blocks = []; |
145 | if (isset($config->$section->$setting)) { |
146 | foreach ($config->$section->$setting as $current) { |
147 | $parts = explode(':', $current, 2); |
148 | $block = $this->blockManager->get($parts[0]); |
149 | $block->setConfig($parts[1] ?? ''); |
150 | $blocks[] = $block; |
151 | } |
152 | } |
153 | return $blocks; |
154 | } |
155 | } |