Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserList
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUserListsAndCountsByUser
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 lastUsed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 userCanEditList
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * List view helper
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  View_Helpers
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 Wiki
28 */
29
30namespace VuFind\View\Helper\Root;
31
32use Laminas\View\Helper\AbstractHelper;
33use VuFind\Db\Entity\UserEntityInterface;
34use VuFind\Db\Entity\UserListEntityInterface;
35use VuFind\Db\Service\UserListServiceInterface;
36use VuFind\Favorites\FavoritesService;
37
38/**
39 * List view helper
40 *
41 * @category VuFind
42 * @package  View_Helpers
43 * @author   Demian Katz <demian.katz@villanova.edu>
44 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
45 * @link     https://vufind.org/wiki/development Wiki
46 */
47class UserList extends AbstractHelper
48{
49    /**
50     * Constructor
51     *
52     * @param FavoritesService         $favoritesService Favorites service
53     * @param UserListServiceInterface $userListService  List database service
54     * @param string                   $mode             List mode (enabled or disabled)
55     */
56    public function __construct(
57        protected FavoritesService $favoritesService,
58        protected UserListServiceInterface $userListService,
59        protected string $mode = 'enabled'
60    ) {
61    }
62
63    /**
64     * Get lists with counts for the provided user.
65     *
66     * @param UserEntityInterface $user User owning lists
67     *
68     * @return array
69     */
70    public function getUserListsAndCountsByUser(UserEntityInterface $user): array
71    {
72        return $this->userListService->getUserListsAndCountsByUser($user);
73    }
74
75    /**
76     * Get mode
77     *
78     * @return string
79     */
80    public function getMode()
81    {
82        return $this->mode;
83    }
84
85    /**
86     * Retrieve the ID of the last list that was accessed, if any.
87     *
88     * @return mixed User_list ID (if set) or null (if not available).
89     */
90    public function lastUsed()
91    {
92        return $this->favoritesService->getLastUsedList();
93    }
94
95    /**
96     * Is the provided user allowed to edit the provided list?
97     *
98     * @param ?UserEntityInterface    $user Logged-in user (null if none)
99     * @param UserListEntityInterface $list List to check
100     *
101     * @return bool
102     */
103    public function userCanEditList(?UserEntityInterface $user, UserListEntityInterface $list): bool
104    {
105        return $this->favoritesService->userCanEditList($user, $list);
106    }
107}