Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
IlsRecords
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getDrivers
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
 collectRequestStats
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * VuFind Action Helper - ILS Records Support Methods
5 *
6 * PHP version 8
7 *
8 * Copyright (C) The National Library of Finland 2021.
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  Controller_Plugins
25 * @author   Ere Maijala <ere.maijala@helsinki.fi>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org Main Page
28 */
29
30namespace VuFind\Controller\Plugin;
31
32use Laminas\Config\Config;
33use VuFind\Record\Loader;
34
35/**
36 * Action helper to perform ILS record related actions
37 *
38 * @category VuFind
39 * @package  Controller_Plugins
40 * @author   Ere Maijala <ere.maijala@helsinki.fi>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org Main Page
43 */
44class IlsRecords extends \Laminas\Mvc\Controller\Plugin\AbstractPlugin
45{
46    use \VuFind\ILS\Logic\SummaryTrait;
47
48    /**
49     * VuFind configuration
50     *
51     * @var Config
52     */
53    protected $config;
54
55    /**
56     * Record loader
57     *
58     * @var Loader
59     */
60    protected $loader;
61
62    /**
63     * Constructor
64     *
65     * @param Config $config VuFind configuration
66     * @param Loader $loader Record loader
67     */
68    public function __construct(Config $config, Loader $loader)
69    {
70        $this->config = $config;
71        $this->loader = $loader;
72    }
73
74    /**
75     * Get record driver objects corresponding to an array of record arrays returned
76     * by an ILS driver's methods such as getMyHolds / getMyTransactions.
77     *
78     * @param array $records Record information
79     *
80     * @return \VuFind\RecordDriver\AbstractBase[]
81     */
82    public function getDrivers(array $records): array
83    {
84        if (!$records) {
85            return [];
86        }
87        $ids = array_map(
88            function ($current) {
89                return [
90                    'id' => $current['id'] ?? '',
91                    'source' => $current['source'] ?? DEFAULT_SEARCH_BACKEND,
92                ];
93            },
94            $records
95        );
96        $drivers = $this->loader->loadBatch($ids, true);
97        foreach ($records as $i => $current) {
98            // loadBatch takes care of maintaining correct order, so we can access
99            // the array by index
100            $drivers[$i]->setExtraDetail('ils_details', $current);
101        }
102        return $drivers;
103    }
104
105    /**
106     * Collect up to date status information for ajax account notifications.
107     *
108     * This information is used to trigger a refresh for account notifications if
109     * necessary.
110     *
111     * @param array $records Records for holds, ILL requests or storage retrieval
112     * requests
113     *
114     * @return array
115     */
116    public function collectRequestStats(array $records): ?array
117    {
118        // Collect up to date stats for ajax account notifications:
119        if (!($this->config->Authentication->enableAjax ?? true)) {
120            return null;
121        }
122        return $this->getRequestSummary(
123            array_map(
124                function ($record) {
125                    return $record->getExtraDetail('ils_details');
126                },
127                $records
128            )
129        );
130    }
131}