Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
4.76% |
1 / 21 |
|
8.33% |
1 / 12 |
CRAP | |
0.00% |
0 / 1 |
UserResource | |
4.76% |
1 / 21 |
|
8.33% |
1 / 12 |
158.99 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUser | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
setUser | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getResource | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
setResource | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getUserList | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
setUserList | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getNotes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setNotes | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getSaved | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setSaved | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Row Definition for user_resource |
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 | |
30 | namespace VuFind\Db\Row; |
31 | |
32 | use DateTime; |
33 | use VuFind\Db\Entity\ResourceEntityInterface; |
34 | use VuFind\Db\Entity\UserEntityInterface; |
35 | use VuFind\Db\Entity\UserListEntityInterface; |
36 | use VuFind\Db\Entity\UserResourceEntityInterface; |
37 | use VuFind\Db\Service\DbServiceAwareInterface; |
38 | use VuFind\Db\Service\DbServiceAwareTrait; |
39 | use VuFind\Db\Service\ResourceServiceInterface; |
40 | use VuFind\Db\Service\UserListServiceInterface; |
41 | use VuFind\Db\Service\UserServiceInterface; |
42 | |
43 | /** |
44 | * Row Definition for user_resource |
45 | * |
46 | * @category VuFind |
47 | * @package Db_Row |
48 | * @author Demian Katz <demian.katz@villanova.edu> |
49 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
50 | * @link https://vufind.org Main Site |
51 | * |
52 | * @property int $id |
53 | * @property int $user_id |
54 | * @property int $resource_id |
55 | * @property int $list_id |
56 | * @property string $notes |
57 | * @property string $saved |
58 | */ |
59 | class UserResource extends RowGateway implements |
60 | \VuFind\Db\Entity\UserResourceEntityInterface, |
61 | \VuFind\Db\Table\DbTableAwareInterface, |
62 | DbServiceAwareInterface |
63 | { |
64 | use \VuFind\Db\Table\DbTableAwareTrait; |
65 | use DbServiceAwareTrait; |
66 | |
67 | /** |
68 | * Constructor |
69 | * |
70 | * @param \Laminas\Db\Adapter\Adapter $adapter Database adapter |
71 | */ |
72 | public function __construct($adapter) |
73 | { |
74 | parent::__construct('id', 'user_resource', $adapter); |
75 | } |
76 | |
77 | /** |
78 | * Get identifier (returns null for an uninitialized or non-persisted object). |
79 | * |
80 | * @return ?int |
81 | */ |
82 | public function getId(): ?int |
83 | { |
84 | return $this->id ?? null; |
85 | } |
86 | |
87 | /** |
88 | * Get user. |
89 | * |
90 | * @return UserEntityInterface |
91 | */ |
92 | public function getUser(): UserEntityInterface |
93 | { |
94 | return $this->getDbServiceManager()->get(UserServiceInterface::class) |
95 | ->getUserById($this->user_id); |
96 | } |
97 | |
98 | /** |
99 | * Set user. |
100 | * |
101 | * @param UserEntityInterface $user User |
102 | * |
103 | * @return UserResourceEntityInterface |
104 | */ |
105 | public function setUser(UserEntityInterface $user): UserResourceEntityInterface |
106 | { |
107 | $this->user_id = $user->getId(); |
108 | return $this; |
109 | } |
110 | |
111 | /** |
112 | * Get resource. |
113 | * |
114 | * @return ResourceEntityInterface |
115 | */ |
116 | public function getResource(): ResourceEntityInterface |
117 | { |
118 | return $this->getDbServiceManager()->get(ResourceServiceInterface::class) |
119 | ->getResourceById($this->resource_id); |
120 | } |
121 | |
122 | /** |
123 | * Set resource. |
124 | * |
125 | * @param ResourceEntityInterface $resource Resource |
126 | * |
127 | * @return UserResourceEntityInterface |
128 | */ |
129 | public function setResource(ResourceEntityInterface $resource): UserResourceEntityInterface |
130 | { |
131 | $this->resource_id = $resource->getId(); |
132 | return $this; |
133 | } |
134 | |
135 | /** |
136 | * Get user list. |
137 | * |
138 | * @return ?UserListEntityInterface |
139 | */ |
140 | public function getUserList(): ?UserListEntityInterface |
141 | { |
142 | return $this->list_id |
143 | ? $this->getDbServiceManager()->get(UserListServiceInterface::class)->getUserListById($this->list_id) |
144 | : null; |
145 | } |
146 | |
147 | /** |
148 | * Set user list. |
149 | * |
150 | * @param ?UserListEntityInterface $list User list |
151 | * |
152 | * @return UserResourceEntityInterface |
153 | */ |
154 | public function setUserList(?UserListEntityInterface $list): UserResourceEntityInterface |
155 | { |
156 | $this->list_id = $list?->getId(); |
157 | return $this; |
158 | } |
159 | |
160 | /** |
161 | * Get notes. |
162 | * |
163 | * @return ?string |
164 | */ |
165 | public function getNotes(): ?string |
166 | { |
167 | return $this->notes ?? null; |
168 | } |
169 | |
170 | /** |
171 | * Set notes. |
172 | * |
173 | * @param ?string $notes Notes associated with the resource |
174 | * |
175 | * @return UserResourceEntityInterface |
176 | */ |
177 | public function setNotes(?string $notes): UserResourceEntityInterface |
178 | { |
179 | $this->notes = $notes; |
180 | return $this; |
181 | } |
182 | |
183 | /** |
184 | * Get saved date. |
185 | * |
186 | * @return DateTime |
187 | */ |
188 | public function getSaved(): DateTime |
189 | { |
190 | return DateTime::createFromFormat('Y-m-d H:i:s', $this->saved); |
191 | } |
192 | |
193 | /** |
194 | * Set saved date. |
195 | * |
196 | * @param DateTime $dateTime Created date |
197 | * |
198 | * @return UserResourceEntityInterface |
199 | */ |
200 | public function setSaved(DateTime $dateTime): UserResourceEntityInterface |
201 | { |
202 | $this->saved = $dateTime->format('Y-m-d H:i:s'); |
203 | return $this; |
204 | } |
205 | } |