Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
6.67% covered (danger)
6.67%
1 / 15
11.11% covered (danger)
11.11%
1 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
Comments
6.67% covered (danger)
6.67%
1 / 15
11.11% covered (danger)
11.11%
1 / 9
109.38
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setComment
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getComment
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setCreated
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getCreated
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setUser
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 getUser
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 setResource
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Row Definition for comments
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
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  Db_Row
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 Main Site
28 */
29
30namespace VuFind\Db\Row;
31
32use DateTime;
33use VuFind\Db\Entity\CommentsEntityInterface;
34use VuFind\Db\Entity\ResourceEntityInterface;
35use VuFind\Db\Entity\UserEntityInterface;
36use VuFind\Db\Service\DbServiceAwareInterface;
37use VuFind\Db\Service\UserServiceInterface;
38
39/**
40 * Row Definition for comments
41 *
42 * @category VuFind
43 * @package  Db_Row
44 * @author   Demian Katz <demian.katz@villanova.edu>
45 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
46 * @link     https://vufind.org Main Site
47 *
48 * @property int     $id
49 * @property ?int    $user_id
50 * @property int     $resource_id
51 * @property string  $comment
52 * @property string  $created
53 */
54class Comments extends RowGateway implements CommentsEntityInterface, DbServiceAwareInterface
55{
56    use \VuFind\Db\Service\DbServiceAwareTrait;
57
58    /**
59     * Constructor
60     *
61     * @param \Laminas\Db\Adapter\Adapter $adapter Database adapter
62     */
63    public function __construct($adapter)
64    {
65        parent::__construct('id', 'comments', $adapter);
66    }
67
68    /**
69     * Id getter
70     *
71     * @return int
72     */
73    public function getId(): int
74    {
75        return $this->id;
76    }
77
78    /**
79     * Comment setter
80     *
81     * @param string $comment Comment
82     *
83     * @return Comments
84     */
85    public function setComment(string $comment): CommentsEntityInterface
86    {
87        $this->comment = $comment;
88        return $this;
89    }
90
91    /**
92     * Comment getter
93     *
94     * @return string
95     */
96    public function getComment(): string
97    {
98        return $this->comment;
99    }
100
101    /**
102     * Created setter.
103     *
104     * @param DateTime $dateTime Created date
105     *
106     * @return Comments
107     */
108    public function setCreated(DateTime $dateTime): CommentsEntityInterface
109    {
110        $this->created = $dateTime->format('Y-m-d H:i:s');
111        return $this;
112    }
113
114    /**
115     * Created getter
116     *
117     * @return DateTime
118     */
119    public function getCreated(): DateTime
120    {
121        return DateTime::createFromFormat('Y-m-d H:i:s', $this->created);
122    }
123
124    /**
125     * User setter.
126     *
127     * @param ?UserEntityInterface $user User that created comment
128     *
129     * @return Comments
130     */
131    public function setUser(?UserEntityInterface $user): CommentsEntityInterface
132    {
133        $this->user_id = $user ? $user->getId() : null;
134        return $this;
135    }
136
137    /**
138     * User getter
139     *
140     * @return ?UserEntityInterface
141     */
142    public function getUser(): ?UserEntityInterface
143    {
144        return $this->user_id
145            ? $this->getDbServiceManager()->get(UserServiceInterface::class)->getUserById($this->user_id)
146            : null;
147    }
148
149    /**
150     * Resource setter.
151     *
152     * @param ResourceEntityInterface $resource Resource id.
153     *
154     * @return Comments
155     */
156    public function setResource(ResourceEntityInterface $resource): CommentsEntityInterface
157    {
158        $this->resource_id = $resource->getId();
159        return $this;
160    }
161}