Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.25% covered (warning)
81.25%
13 / 16
60.00% covered (warning)
60.00%
3 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Missing
81.25% covered (warning)
81.25%
13 / 16
60.00% covered (warning)
60.00%
3 / 5
10.66
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 determineMissingTitle
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
4
 getShortTitle
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getTitle
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getFormats
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Model for missing records -- used for saved favorites that have been deleted
5 * from the index.
6 *
7 * PHP version 8
8 *
9 * Copyright (C) Villanova University 2010.
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  RecordDrivers
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
28 * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
29 */
30
31namespace VuFind\RecordDriver;
32
33use VuFind\Db\Service\ResourceServiceInterface;
34
35/**
36 * Model for missing records -- used for saved favorites that have been deleted
37 * from the index.
38 *
39 * @category VuFind
40 * @package  RecordDrivers
41 * @author   Demian Katz <demian.katz@villanova.edu>
42 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
43 * @link     https://vufind.org/wiki/development:plugins:record_drivers Wiki
44 */
45class Missing extends DefaultRecord
46{
47    /**
48     * Constructor
49     *
50     * @param \Laminas\Config\Config $mainConfig   VuFind main configuration (omit
51     * for built-in defaults)
52     * @param \Laminas\Config\Config $recordConfig Record-specific configuration file
53     * (omit to use $mainConfig as $recordConfig)
54     */
55    public function __construct($mainConfig = null, $recordConfig = null)
56    {
57        parent::__construct($mainConfig, $recordConfig);
58        $this->setSourceIdentifiers('missing');
59    }
60
61    /**
62     * Format the missing title.
63     *
64     * @return string
65     */
66    public function determineMissingTitle()
67    {
68        // If available, use details from ILS:
69        $ilsDetails = $this->getExtraDetail('ils_details');
70        if (isset($ilsDetails['title'])) {
71            return $ilsDetails['title'];
72        }
73
74        // If available, load title from database:
75        if ($id = $this->getUniqueID()) {
76            $resourceService = $this->getDbService(ResourceServiceInterface::class);
77            $resource = $resourceService->getResourceByRecordId($id, $this->getSourceIdentifier());
78            if ($title = $resource?->getTitle()) {
79                return $title;
80            }
81        }
82
83        // Default -- message about missing title:
84        return $this->translate('Title not available');
85    }
86
87    /**
88     * Get the short title of the record.
89     *
90     * @return string
91     */
92    public function getShortTitle()
93    {
94        $title = parent::getShortTitle();
95        return empty($title) ? $this->determineMissingTitle() : $title;
96    }
97
98    /**
99     * Get the full title of the record.
100     *
101     * @return string
102     */
103    public function getTitle()
104    {
105        $title = parent::getShortTitle();
106        return empty($title) ? $this->determineMissingTitle() : $title;
107    }
108
109    /**
110     * Get an array of all the formats associated with the record.
111     *
112     * @return array
113     */
114    public function getFormats()
115    {
116        return ['Unknown'];
117    }
118}