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 Ratings.
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;
34
35/**
36 * Database service interface for Ratings.
37 *
38 * @category VuFind
39 * @package  Database
40 * @author   Sudharma Kellampalli <skellamp@villanova.edu>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org/wiki/development:plugins:database_gateways Wiki
43 */
44interface RatingsServiceInterface extends DbServiceInterface
45{
46    /**
47     * Get average rating and rating count associated with the specified record.
48     *
49     * @param string $id     Record ID to look up
50     * @param string $source Source of record to look up
51     * @param ?int   $userId User ID, or null for all users
52     *
53     * @return array Array with keys count and rating (between 0 and 100)
54     */
55    public function getRecordRatings(string $id, string $source, ?int $userId): array;
56
57    /**
58     * Get rating breakdown for the specified record.
59     *
60     * @param string $id     Record ID to look up
61     * @param string $source Source of record to look up
62     * @param array  $groups Group definition (key => [min, max])
63     *
64     * @return array Array with keys count and rating (between 0 and 100) as well as
65     * an groups array with ratings from lowest to highest
66     */
67    public function getCountsForRecord(
68        string $id,
69        string $source,
70        array $groups
71    ): array;
72
73    /**
74     * Deletes all ratings by a user.
75     *
76     * @param UserEntityInterface|int $userOrId User object or identifier
77     *
78     * @return void
79     */
80    public function deleteByUser(UserEntityInterface|int $userOrId): void;
81
82    /**
83     * Get statistics on use of Ratings.
84     *
85     * @return array
86     */
87    public function getStatistics(): array;
88
89    /**
90     * Add or update user's rating for a resource.
91     *
92     * @param ResourceEntityInterface|int $resourceOrId Resource to add or update rating.
93     * @param UserEntityInterface|int     $userOrId     User
94     * @param ?int                        $rating       Rating (null to delete)
95     *
96     * @throws \Exception
97     * @return int ID of rating added, deleted or updated
98     */
99    public function addOrUpdateRating(
100        ResourceEntityInterface|int $resourceOrId,
101        UserEntityInterface|int $userOrId,
102        ?int $rating
103    ): int;
104}