From 3ea424693be99372087ad144ee7854cbe9945f53 Mon Sep 17 00:00:00 2001 From: fcki1984 <39592566+fcki1984@users.noreply.github.com> Date: Fri, 12 May 2023 21:19:47 +0800 Subject: [PATCH] Update BookmarkMapper.php --- lib/Db/BookmarkMapper.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/Db/BookmarkMapper.php b/lib/Db/BookmarkMapper.php index c7f5c7a..c8a26c3 100644 --- a/lib/Db/BookmarkMapper.php +++ b/lib/Db/BookmarkMapper.php @@ -36,21 +36,24 @@ class BookmarkMapper extends ReaderMapper { * @param string $name * @return array */ - public function get($fileId, $name, $type=null) { - $sql = "SELECT * FROM `*PREFIX*reader_bookmarks` WHERE file_id=? AND `user_id`=?"; - $args = [ $fileId, $this->userId ]; - if (!(null === $type)) { - $sql .= " AND `type`=?"; - $args[] = $type; - } - if (!(null === $name)) { - $sql .= " AND `name`=?"; - $args[] = $name; - } + public function get($fileId, $name, $type = null) { + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->from($this->getTableName()) + ->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId))) + ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId))); - return $this->findEntities($sql, $args); + if ($type !== null) { + $query->andWhere($query->expr()->eq('type', $query->createNamedParameter($type))); } + if ($name !== null) { + $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name))); + } + + return $this->findEntities($query); +} + /** * @brief write bookmark to database *