Merge remote-tracking branch 'fcki1984/QBMapper'
This commit is contained in:
commit
5d6e3431b2
@ -36,19 +36,22 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
namespace OCA\Epubreader\Db;
|
||||
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCA\Epubreader\Utility\Time;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
@ -29,22 +30,18 @@ class PreferenceMapper extends ReaderMapper {
|
||||
* @return array
|
||||
*/
|
||||
public function get($scope, $fileId, $name=null) {
|
||||
if(!empty($name)) {
|
||||
$sql = "SELECT * FROM `*PREFIX*reader_prefs` WHERE `scope`=? AND `file_id`=? AND `user_id`=? AND `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);
|
||||
$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)) {
|
||||
$query->andWhere($query->expr()->eq('name', $query->createNamedParameter($name)));
|
||||
}
|
||||
|
||||
return $this->findEntities($sql, $args);
|
||||
return $this->findEntities($query);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,12 +11,12 @@
|
||||
namespace OCA\Epubreader\Db;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\AppFramework\Db\QBMapper;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
use OCA\Epubreader\Utility\Time;
|
||||
|
||||
abstract class ReaderMapper extends Mapper {
|
||||
abstract class ReaderMapper extends QBMapper {
|
||||
|
||||
/**
|
||||
* @var Time
|
||||
@ -28,12 +28,12 @@ abstract class ReaderMapper extends Mapper {
|
||||
$this->time = $time;
|
||||
}
|
||||
|
||||
public function update(Entity $entity) {
|
||||
public function update(Entity $entity): Entity {
|
||||
$entity->setLastModified($this->time->getMicroTime());
|
||||
return parent::update($entity);
|
||||
}
|
||||
|
||||
public function insert(Entity $entity) {
|
||||
public function insert(Entity $entity): Entity {
|
||||
$entity->setLastModified($this->time->getMicroTime());
|
||||
return parent::insert($entity);
|
||||
}
|
||||
|
Reference in New Issue
Block a user