Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
BulkActionTrait | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
getBulkActionConfig | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getBulkActionExportConfig | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getBulkActionLimit | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
getExportActionLimit | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * VuFind Action Feature Trait - Bulk action helper methods |
5 | * Depends on access to the config loader and export support class. |
6 | * |
7 | * PHP version 8 |
8 | * |
9 | * Copyright (C) Villanova University 2024 |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2, |
13 | * as published by the Free Software Foundation. |
14 | * |
15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * |
24 | * @category VuFind |
25 | * @package Feature |
26 | * @author Demian Katz <demian.katz@villanova.edu> |
27 | * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> |
28 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
29 | * @link https://vufind.org Main Page |
30 | */ |
31 | |
32 | namespace VuFind\Feature; |
33 | |
34 | /** |
35 | * VuFind Action Feature Trait - Bulk action helper methods |
36 | * |
37 | * @category VuFind |
38 | * @package Feature |
39 | * @author Demian Katz <demian.katz@villanova.edu> |
40 | * @author Thomas Wagener <wagener@hebis.uni-frankfurt.de> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org Main Page |
43 | */ |
44 | trait BulkActionTrait |
45 | { |
46 | /** |
47 | * Config |
48 | * |
49 | * @var \Laminas\Config\Config |
50 | */ |
51 | protected $bulkActionConfig; |
52 | |
53 | /** |
54 | * Export Config |
55 | * |
56 | * @var \Laminas\Config\Config |
57 | */ |
58 | protected $bulkActionExportConfig; |
59 | |
60 | /** |
61 | * Get Config. |
62 | * |
63 | * @return \Laminas\Config\Config |
64 | */ |
65 | protected function getBulkActionConfig() |
66 | { |
67 | if ($this->bulkActionConfig === null) { |
68 | $this->bulkActionConfig = $this->configLoader->get('config'); |
69 | } |
70 | return $this->bulkActionConfig; |
71 | } |
72 | |
73 | /** |
74 | * Get Export Config. |
75 | * |
76 | * @return \Laminas\Config\Config |
77 | */ |
78 | protected function getBulkActionExportConfig() |
79 | { |
80 | if ($this->bulkActionExportConfig === null) { |
81 | $this->bulkActionExportConfig = $this->configLoader->get('export'); |
82 | } |
83 | return $this->bulkActionExportConfig; |
84 | } |
85 | |
86 | /** |
87 | * Get the limit of a bulk action. |
88 | * |
89 | * @param string $action Name of the bulk action |
90 | * |
91 | * @return int |
92 | */ |
93 | public function getBulkActionLimit($action) |
94 | { |
95 | if ($action == 'export') { |
96 | $formats = $this->export->getActiveFormats('bulk'); |
97 | return max(array_map([$this, 'getExportActionLimit'], $formats)); |
98 | } |
99 | $bulkActionConfig = $this->getBulkActionConfig()?->BulkActions; |
100 | return $bulkActionConfig?->limits?->$action |
101 | ?? $bulkActionConfig?->limits?->default |
102 | ?? 100; |
103 | } |
104 | |
105 | /** |
106 | * Get the limit of the export action for a specific format. |
107 | * |
108 | * @param string $format Name of the format |
109 | * |
110 | * @return int |
111 | */ |
112 | public function getExportActionLimit($format) |
113 | { |
114 | $bulkActionConfig = $this->getBulkActionConfig()?->BulkActions; |
115 | return $this->getBulkActionExportConfig()?->$format?->limit |
116 | ?? $bulkActionConfig?->limits?->export |
117 | ?? $bulkActionConfig?->limits?->default |
118 | ?? 100; |
119 | } |
120 | } |