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 Comments.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2023.
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   Sudharma Kellampalli <skellamp@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\CommentsEntityInterface;
33use VuFind\Db\Entity\ResourceEntityInterface;
34use VuFind\Db\Entity\UserEntityInterface;
35
36/**
37 * Database service interface for Comments.
38 *
39 * @category VuFind
40 * @package  Database
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:database_gateways Wiki
44 */
45interface CommentsServiceInterface extends DbServiceInterface
46{
47    /**
48     * Create a comments entity object.
49     *
50     * @return CommentsEntityInterface
51     */
52    public function createEntity(): CommentsEntityInterface;
53
54    /**
55     * Add a comment to the current resource. Returns comment ID on success, null on failure.
56     *
57     * @param string                      $comment      The comment to save.
58     * @param UserEntityInterface|int     $userOrId     User object or identifier
59     * @param ResourceEntityInterface|int $resourceOrId Resource object or identifier
60     *
61     * @return ?int
62     */
63    public function addComment(
64        string $comment,
65        UserEntityInterface|int $userOrId,
66        ResourceEntityInterface|int $resourceOrId
67    ): ?int;
68
69    /**
70     * Get comments associated with the specified record.
71     *
72     * @param string $id     Record ID to look up
73     * @param string $source Source of record to look up
74     *
75     * @return CommentsEntityInterface[]
76     */
77    public function getRecordComments(string $id, string $source = DEFAULT_SEARCH_BACKEND): array;
78
79    /**
80     * Delete a comment if the owner is logged in.  Returns true on success.
81     *
82     * @param int                     $id       ID of row to delete
83     * @param UserEntityInterface|int $userOrId User object or identifier
84     *
85     * @return bool
86     */
87    public function deleteIfOwnedByUser(int $id, UserEntityInterface|int $userOrId): bool;
88
89    /**
90     * Deletes all comments by a user.
91     *
92     * @param UserEntityInterface|int $userOrId User object or identifier
93     *
94     * @return void
95     */
96    public function deleteByUser(UserEntityInterface|int $userOrId): void;
97
98    /**
99     * Get statistics on use of comments.
100     *
101     * @return array
102     */
103    public function getStatistics(): array;
104
105    /**
106     * Get a comment row by ID (or return null for no match).
107     *
108     * @param int $id ID of comment to retrieve.
109     *
110     * @return ?CommentsEntityInterface
111     */
112    public function getCommentById(int $id): ?CommentsEntityInterface;
113
114    /**
115     * Change all matching comments to use the new resource ID instead of the old one (called when an ID changes).
116     *
117     * @param int $old Original resource ID
118     * @param int $new New resource ID
119     *
120     * @return void
121     */
122    public function changeResourceId(int $old, int $new): void;
123}