Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3/**
4 * Database service interface for resource.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2024.
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  Database
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @author   Sudharma Kellampalli <skellamp@villanova.edu>
27 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
28 * @link     https://vufind.org/wiki/development:plugins:database_gateways Wiki
29 */
30
31namespace VuFind\Db\Service;
32
33use Exception;
34use VuFind\Db\Entity\ResourceEntityInterface;
35use VuFind\Db\Entity\UserEntityInterface;
36use VuFind\Db\Entity\UserListEntityInterface;
37
38/**
39 * Database service interface for resource.
40 *
41 * @category VuFind
42 * @package  Database
43 * @author   Demian Katz <demian.katz@villanova.edu>
44 * @author   Sudharma Kellampalli <skellamp@villanova.edu>
45 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
46 * @link     https://vufind.org/wiki/development:plugins:database_gateways Wiki
47 */
48interface ResourceServiceInterface extends DbServiceInterface
49{
50    /**
51     * Lookup and return a resource.
52     *
53     * @param int $id Identifier value
54     *
55     * @return ?ResourceEntityInterface
56     */
57    public function getResourceById(int $id): ?ResourceEntityInterface;
58
59    /**
60     * Create a resource entity object.
61     *
62     * @return ResourceEntityInterface
63     */
64    public function createEntity(): ResourceEntityInterface;
65
66    /**
67     * Get a set of records that do not have metadata stored in the resource
68     * table.
69     *
70     * @return ResourceEntityInterface[]
71     */
72    public function findMissingMetadata(): array;
73
74    /**
75     * Retrieve a single resource row by record ID/source. Return null if it does not exist.
76     *
77     * @param string $id     Record ID
78     * @param string $source Record source
79     *
80     * @return ?ResourceEntityInterface
81     */
82    public function getResourceByRecordId(
83        string $id,
84        string $source = DEFAULT_SEARCH_BACKEND
85    ): ?ResourceEntityInterface;
86
87    /**
88     * Retrieve resource entities matching a set of specified records.
89     *
90     * @param string[] $ids    Array of IDs
91     * @param string   $source Source of records to look up
92     *
93     * @return ResourceEntityInterface[]
94     */
95    public function getResourcesByRecordIds(array $ids, string $source = DEFAULT_SEARCH_BACKEND): array;
96
97    /**
98     * Get a set of resources from the requested favorite list.
99     *
100     * @param UserEntityInterface|int          $userOrId          ID of user owning favorite list
101     * @param UserListEntityInterface|int|null $listOrId          ID of list to retrieve (null for all favorites)
102     * @param string[]                         $tags              Tags to use for limiting results
103     * @param ?string                          $sort              Resource table field to use for sorting (null for no
104     * particular sort).
105     * @param int                              $offset            Offset for results
106     * @param ?int                             $limit             Limit for results (null for none)
107     * @param bool                             $caseSensitiveTags Treat tags as case-sensitive?
108     *
109     * @return ResourceEntityInterface[]
110     */
111    public function getFavorites(
112        UserEntityInterface|int $userOrId,
113        UserListEntityInterface|int|null $listOrId = null,
114        array $tags = [],
115        ?string $sort = null,
116        int $offset = 0,
117        ?int $limit = null,
118        bool $caseSensitiveTags = false
119    ): array;
120
121    /**
122     * Delete a resource by record id and source. Return true if found and deleted, false if not found.
123     * Throws exception if something goes wrong.
124     *
125     * @param string $id     Resource ID
126     * @param string $source Resource source
127     *
128     * @return bool
129     * @throws Exception
130     */
131    public function deleteResourceByRecordId(string $id, string $source): bool;
132
133    /**
134     * Globally change the name of a source value in the database; return the number of rows affected.
135     *
136     * @param string $old Old source value
137     * @param string $new New source value
138     *
139     * @return int
140     */
141    public function renameSource(string $old, string $new): int;
142
143    /**
144     * Delete a resource entity.
145     *
146     * @param ResourceEntityInterface|int $resourceOrId Resource entity or ID value.
147     *
148     * @return void
149     */
150    public function deleteResource(ResourceEntityInterface|int $resourceOrId): void;
151}