Merge remote-tracking branch 'fcki1984/QBMapper'
This commit is contained in:
commit
5d6e3431b2
@ -37,18 +37,21 @@ class BookmarkMapper extends ReaderMapper {
|
|||||||
* @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)) {
|
if ($type !== null) {
|
||||||
$sql .= " AND `name`=?";
|
$query->andWhere($query->expr()->eq('type', $query->createNamedParameter($type)));
|
||||||
$args[] = $name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->findEntities($sql, $args);
|
if ($name !== null) {
|
||||||
|
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->findEntities($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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) {
|
||||||
|
$query = $this->db->getQueryBuilder();
|
||||||
|
$query->select('*')
|
||||||
|
->from($this->getTableName())
|
||||||
|
->where($query->expr()->eq('scope', $query->createNamedParameter($scope)))
|
||||||
|
->andWhere($query->expr()->eq('file_id', $query->createNamedParameter($fileId)))
|
||||||
|
->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($this->userId)));
|
||||||
|
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=? AND `name`=?";
|
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
|
||||||
$args = array(
|
|
||||||
$scope,
|
|
||||||
$fileId,
|
|
||||||
$this->userId,
|
|
||||||
$name);
|
|
||||||
} else {
|
|
||||||
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=?";
|
|
||||||
$args = array(
|
|
||||||
$scope,
|
|
||||||
$fileId,
|
|
||||||
$this->userId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->findEntities($sql, $args);
|
return $this->findEntities($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user