Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway;
10
11 use Doctrine\DBAL\Connection;
12 use eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway;
13 use eZ\Publish\SPI\Persistence\Bookmark\Bookmark;
14 use PDO;
15
16 class DoctrineDatabase extends Gateway
17 {
18 const TABLE_BOOKMARKS = 'ezcontentbrowsebookmark';
19
20 const COLUMN_ID = 'id';
21 const COLUMN_USER_ID = 'user_id';
22 const COLUMN_LOCATION_ID = 'node_id';
23 const COLUMN_NAME = 'name';
24
26 protected $connection;
27
28 public function __construct(Connection $connection)
29 {
30 $this->connection = $connection;
31 }
32
36 public function insertBookmark(Bookmark $bookmark): int
37 {
38 $query = $this->connection->createQueryBuilder();
39 $query
40 ->insert(self::TABLE_BOOKMARKS)
41 ->values([
42 self::COLUMN_NAME => ':name',
43 self::COLUMN_USER_ID => ':user_id',
44 self::COLUMN_LOCATION_ID => ':location_id',
45 ])
46 ->setParameter(':name', $bookmark->name, PDO::PARAM_STR)
47 ->setParameter(':user_id', $bookmark->userId, PDO::PARAM_INT)
48 ->setParameter(':location_id', $bookmark->locationId, PDO::PARAM_INT);
49
50 $query->execute();
51
52 return (int) $this->connection->lastInsertId();
53 }
54
58 public function deleteBookmark(int $id): void
59 {
60 $query = $this->connection->createQueryBuilder();
61 $query
62 ->delete(self::TABLE_BOOKMARKS)
63 ->where($query->expr()->eq(self::COLUMN_ID, ':id'))
64 ->setParameter(':id', $id, PDO::PARAM_INT);
65
66 $query->execute();
67 }
68
72 public function loadBookmarkDataById(int $id): array
73 {
74 $query = $this->connection->createQueryBuilder();
75 $query
76 ->select(...$this->getColumns())
77 ->from(self::TABLE_BOOKMARKS)
78 ->where($query->expr()->eq(self::COLUMN_ID, ':id'))
79 ->setParameter(':id', $id, PDO::PARAM_INT);
80
81 return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
82 }
83
87 public function loadBookmarkDataByUserIdAndLocationId(int $userId, array $locationIds): array
88 {
89 $query = $this->connection->createQueryBuilder();
90 $query
91 ->select(...$this->getColumns())
92 ->from(self::TABLE_BOOKMARKS)
93 ->where($query->expr()->andX(
94 $query->expr()->eq(self::COLUMN_USER_ID, ':user_id'),
95 $query->expr()->in(self::COLUMN_LOCATION_ID, ':location_id')
96 ))
97 ->setParameter(':user_id', $userId, PDO::PARAM_INT)
98 ->setParameter(':location_id', $locationIds, Connection::PARAM_INT_ARRAY);
99
100 return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
101 }
102
106 public function loadUserBookmarks(int $userId, int $offset = 0, int $limit = -1): array
107 {
108 $query = $this->connection->createQueryBuilder();
109 $query
110 ->select(...$this->getColumns())
111 ->from(self::TABLE_BOOKMARKS)
112 ->where($query->expr()->eq(self::COLUMN_USER_ID, ':user_id'))
113 ->setFirstResult($offset);
114
115 if ($limit > 0) {
116 $query->setMaxResults($limit);
117 }
118
119 $query->orderBy(self::COLUMN_ID, 'DESC');
120 $query->setParameter(':user_id', $userId, PDO::PARAM_INT);
121
122 return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
123 }
124
128 public function countUserBookmarks(int $userId): int
129 {
130 $query = $this->connection->createQueryBuilder();
131 $query
132 ->select('COUNT(' . self::COLUMN_ID . ')')
133 ->from(self::TABLE_BOOKMARKS)
134 ->where($query->expr()->eq(self::COLUMN_USER_ID, ':user_id'))
135 ->setParameter(':user_id', $userId, PDO::PARAM_INT);
136
137 return (int) $query->execute()->fetchColumn();
138 }
139
143 public function locationSwapped(int $location1Id, int $location2Id): void
144 {
145 $query = $this->connection->createQueryBuilder();
146 $query
147 ->update(self::TABLE_BOOKMARKS)
148 ->set(self::COLUMN_LOCATION_ID, '(CASE WHEN node_id = :source_id THEN :target_id ELSE :source_id END)')
149 ->where($query->expr()->orX(
150 $query->expr()->eq(self::COLUMN_LOCATION_ID, ':source_id'),
151 $query->expr()->eq(self::COLUMN_LOCATION_ID, ':target_id')
152 ));
153
154 $stmt = $this->connection->prepare($query->getSQL());
155 $stmt->bindValue('source_id', $location1Id, PDO::PARAM_INT);
156 $stmt->bindValue('target_id', $location2Id, PDO::PARAM_INT);
157 $stmt->execute();
158 }
159
160 private function getColumns(): array
161 {
162 return [
163 self::COLUMN_ID,
164 self::COLUMN_NAME,
165 self::COLUMN_USER_ID,
166 self::COLUMN_LOCATION_ID,
167 ];
168 }
169 }
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:17
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\getColumns
getColumns()
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:160
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\insertBookmark
insertBookmark(Bookmark $bookmark)
{Insert a bookmark.int ID}
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:36
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\locationSwapped
locationSwapped(int $location1Id, int $location2Id)
{Updates related bookmarks when location was swapped.ID of first location ID of second location}
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:143
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\__construct
__construct(Connection $connection)
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:28
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\$connection
$connection
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:26
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\loadBookmarkDataById
loadBookmarkDataById(int $id)
{}
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:72
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\COLUMN_NAME
const COLUMN_NAME
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:23
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\loadBookmarkDataByUserIdAndLocationId
loadBookmarkDataByUserIdAndLocationId(int $userId, array $locationIds)
{Load data for an bookmark with the given $userId and $locationId.ID of user ID of locationarray}
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:87
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\COLUMN_LOCATION_ID
const COLUMN_LOCATION_ID
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:22
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\deleteBookmark
deleteBookmark(int $id)
{Delete bookmark with the given $id.ID of bookmark}
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:58
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\COLUMN_USER_ID
const COLUMN_USER_ID
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:21
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\TABLE_BOOKMARKS
const TABLE_BOOKMARKS
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:18
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\countUserBookmarks
countUserBookmarks(int $userId)
{Count bookmarks owned by given $userId.ID of userint}
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:128
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\COLUMN_ID
const COLUMN_ID
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:20
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway\DoctrineDatabase\loadUserBookmarks
loadUserBookmarks(int $userId, int $offset=0, int $limit=-1)
{Load data for all bookmarks owned by given $userId.ID of user Offset to start listing from,...
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:106
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway
Base class for bookmark gateways.
Definition: Persistence/Legacy/Bookmark/Gateway.php:17
eZ\Publish\SPI\Persistence\Bookmark\Bookmark
Definition: SPI/Persistence/Bookmark/Bookmark.php:14
eZ\Publish\Core\Persistence\Legacy\Bookmark\Gateway
Definition: Persistence/Legacy/Bookmark/Gateway/DoctrineDatabase.php:9
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.