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 UserResource.
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 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org/wiki/development:plugins:database_gateways Wiki
28 */
29
30namespace VuFind\Db\Service;
31
32use VuFind\Db\Entity\ResourceEntityInterface;
33use VuFind\Db\Entity\UserEntityInterface;
34use VuFind\Db\Entity\UserListEntityInterface;
35use VuFind\Db\Entity\UserResourceEntityInterface;
36
37/**
38 * Database service interface for UserResource.
39 *
40 * @category VuFind
41 * @package  Database
42 * @author   Demian Katz <demian.katz@villanova.edu>
43 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
44 * @link     https://vufind.org/wiki/development:plugins:database_gateways Wiki
45 */
46interface UserResourceServiceInterface extends DbServiceInterface
47{
48    /**
49     * Get information saved in a user's favorites for a particular record.
50     *
51     * @param string                           $recordId ID of record being checked.
52     * @param string                           $source   Source of record to look up
53     * @param UserListEntityInterface|int|null $listOrId Optional list entity or ID
54     * (to limit results to a particular list).
55     * @param UserEntityInterface|int|null     $userOrId Optional user entity or ID
56     * (to limit results to a particular user).
57     *
58     * @return UserResourceEntityInterface[]
59     */
60    public function getFavoritesForRecord(
61        string $recordId,
62        string $source = DEFAULT_SEARCH_BACKEND,
63        UserListEntityInterface|int|null $listOrId = null,
64        UserEntityInterface|int|null $userOrId = null
65    ): array;
66
67    /**
68     * Get statistics on use of UserResource.
69     *
70     * @return array
71     */
72    public function getStatistics(): array;
73
74    /**
75     * Create user/resource/list link if one does not exist; update notes if one does.
76     *
77     * @param ResourceEntityInterface|int $resourceOrId Entity or ID of resource to link up
78     * @param UserEntityInterface|int     $userOrId     Entity or ID of user creating link
79     * @param UserListEntityInterface|int $listOrId     Entity or ID of list to link up
80     * @param string                      $notes        Notes to associate with link
81     *
82     * @return UserResource|false
83     */
84    public function createOrUpdateLink(
85        ResourceEntityInterface|int $resourceOrId,
86        UserEntityInterface|int $userOrId,
87        UserListEntityInterface|int $listOrId,
88        string $notes = ''
89    ): UserResourceEntityInterface;
90
91    /**
92     * Unlink rows for the specified resource.
93     *
94     * @param int|int[]|null              $resourceId ID (or array of IDs) of resource(s) to unlink (null for ALL
95     * matching resources)
96     * @param UserEntityInterface|int     $userOrId   ID or entity representing user removing links
97     * @param UserListEntityInterface|int $listOrId   ID or entity representing list to unlink (null for ALL
98     * matching lists)
99     *
100     * @return void
101     */
102    public function unlinkFavorites(
103        int|array|null $resourceId,
104        UserEntityInterface|int $userOrId,
105        UserListEntityInterface|int|null $listOrId = null
106    ): void;
107
108    /**
109     * Create a UserResource entity object.
110     *
111     * @return UserResourceEntityInterface
112     */
113    public function createEntity(): UserResourceEntityInterface;
114
115    /**
116     * Change all matching rows to use the new resource ID instead of the old one (called when an ID changes).
117     *
118     * @param int $old Original resource ID
119     * @param int $new New resource ID
120     *
121     * @return void
122     */
123    public function changeResourceId(int $old, int $new): void;
124
125    /**
126     * Deduplicate rows (sometimes necessary after merging foreign key IDs).
127     *
128     * @return void
129     */
130    public function deduplicate(): void;
131}