Merge remote-tracking branch 'fcki1984/QBMapper'

This commit is contained in:
Michel Roux 2023-06-15 17:41:22 +02:00
commit 5d6e3431b2
3 changed files with 30 additions and 30 deletions

View File

@ -36,19 +36,22 @@ class BookmarkMapper extends ReaderMapper {
* @param string $name * @param string $name
* @return array * @return array
*/ */
public function get($fileId, $name, $type=null) { public function get($fileId, $name, $type = null) {
$sql = "SELECT * FROM `*PREFIX*reader_bookmarks` WHERE file_id=? AND `user_id`=?"; $query = $this->db->getQueryBuilder();
$args = [ $fileId, $this->userId ]; $query->select('*')
if (!(null === $type)) { ->from($this->getTableName())
$sql .= " AND `type`=?"; ->where($query->expr()->eq('file_id', $query->createNamedParameter($fileId)))
$args[] = $type; ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId)));
}
if (!(null === $name)) {
$sql .= " AND `name`=?";
$args[] = $name;
}
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);
} }
/** /**

View File

@ -10,6 +10,7 @@
namespace OCA\Epubreader\Db; namespace OCA\Epubreader\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCA\Epubreader\Utility\Time; use OCA\Epubreader\Utility\Time;
use OCP\IDBConnection; use OCP\IDBConnection;
@ -29,22 +30,18 @@ class PreferenceMapper extends ReaderMapper {
* @return array * @return array
*/ */
public function get($scope, $fileId, $name=null) { public function get($scope, $fileId, $name=null) {
if(!empty($name)) { $query = $this->db->getQueryBuilder();
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=? AND `name`=?"; $query->select('*')
$args = array( ->from($this->getTableName())
$scope, ->where($query->expr()->eq('scope', $query->createNamedParameter($scope)))
$fileId, ->andWhere($query->expr()->eq('file_id', $query->createNamedParameter($fileId)))
$this->userId, ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId)));
$name);
} else { if (!empty($name)) {
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=?"; $query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
$args = array(
$scope,
$fileId,
$this->userId);
} }
return $this->findEntities($sql, $args); return $this->findEntities($query);
} }
/** /**

View File

@ -11,12 +11,12 @@
namespace OCA\Epubreader\Db; namespace OCA\Epubreader\Db;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\AppFramework\Db\Mapper; use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\Entity;
use OCA\Epubreader\Utility\Time; use OCA\Epubreader\Utility\Time;
abstract class ReaderMapper extends Mapper { abstract class ReaderMapper extends QBMapper {
/** /**
* @var Time * @var Time
@ -28,12 +28,12 @@ abstract class ReaderMapper extends Mapper {
$this->time = $time; $this->time = $time;
} }
public function update(Entity $entity) { public function update(Entity $entity): Entity {
$entity->setLastModified($this->time->getMicroTime()); $entity->setLastModified($this->time->getMicroTime());
return parent::update($entity); return parent::update($entity);
} }
public function insert(Entity $entity) { public function insert(Entity $entity): Entity {
$entity->setLastModified($this->time->getMicroTime()); $entity->setLastModified($this->time->getMicroTime());
return parent::insert($entity); return parent::insert($entity);
} }