Completed
Push — master ( 336c64...8fa798 )
by Łukasz
25:31
created

BookmarkHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 79
c 0
b 0
f 0
rs 10
wmc 5
lcom 1
cbo 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A delete() 0 10 1
A loadByUserIdAndLocationId() 0 21 1
A loadUserBookmarks() 0 10 1
A countUserBookmarks() 0 8 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Persistence\Cache;
10
11
use eZ\Publish\SPI\Persistence\Bookmark\Bookmark;
12
use eZ\Publish\SPI\Persistence\Bookmark\CreateStruct;
13
use eZ\Publish\SPI\Persistence\Bookmark\Handler as BookmarkHandlerInterface;
14
15
/**
16
 * @see \eZ\Publish\SPI\Persistence\Bookmark\Handler
17
 */
18
class BookmarkHandler extends AbstractHandler implements BookmarkHandlerInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function create(CreateStruct $createStruct): Bookmark
24
    {
25
        $this->logger->logCall(__METHOD__, [
26
            'createStruct' => $createStruct,
27
        ]);
28
29
        return $this->persistenceHandler->bookmarkHandler()->create($createStruct);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function delete(int $bookmarkId): void
36
    {
37
        $this->logger->logCall(__METHOD__, [
38
            'id' => $bookmarkId,
39
        ]);
40
41
        $this->persistenceHandler->bookmarkHandler()->delete($bookmarkId);
42
43
        $this->cache->invalidateTags(['bookmark-' . $bookmarkId]);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function loadByUserIdAndLocationId(int $userId, array $locationIds): array
50
    {
51
        return $this->getMultipleCacheItems(
52
            $locationIds,
53
            'ez-bookmark-' . $userId . '-',
54
            function (array $missingIds) use ($userId) {
55
                $this->logger->logCall(__METHOD__, [
56
                    'userId' => $userId,
57
                    'locationIds' => $missingIds,
58
                ]);
59
60
                return $this->persistenceHandler->bookmarkHandler()->loadByUserIdAndLocationId($userId, $missingIds);
61
            },
62
            function (Bookmark $bookmark) {
63
                return [
64
                    'bookmark-' . $bookmark->id,
65
                    'location-' . $bookmark->locationId,
66
                ];
67
            }
68
        );
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function loadUserBookmarks(int $userId, int $offset = 0, int $limit = -1): array
75
    {
76
        $this->logger->logCall(__METHOD__, [
77
            'userId' => $userId,
78
            'offset' => $offset,
79
            'limit' => $limit,
80
        ]);
81
82
        return $this->persistenceHandler->bookmarkHandler()->loadUserBookmarks($userId, $offset, $limit);
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function countUserBookmarks(int $userId): int
89
    {
90
        $this->logger->logCall(__METHOD__, [
91
            'userId' => $userId,
92
        ]);
93
94
        return $this->persistenceHandler->bookmarkHandler()->countUserBookmarks($userId);
95
    }
96
}
97