2020-04-21 20:37:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Frank de Lange
|
|
|
|
* @copyright 2017 Frank de Lange
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2020-04-21 21:45:26 +00:00
|
|
|
namespace OCA\Epubreader\Db;
|
2020-04-21 20:37:42 +00:00
|
|
|
|
2023-06-16 14:58:23 +00:00
|
|
|
use OCA\Epubreader\Utility\Time;
|
2020-04-21 20:37:42 +00:00
|
|
|
use OCP\AppFramework\Db\Entity;
|
2023-06-16 14:58:23 +00:00
|
|
|
use OCP\AppFramework\Db\QBMapper;
|
|
|
|
use OCP\IDBConnection;
|
2020-04-21 20:37:42 +00:00
|
|
|
|
2023-06-16 14:58:23 +00:00
|
|
|
/**
|
|
|
|
* @template-extends QBMapper<ReaderEntity>
|
|
|
|
*/
|
2023-08-02 20:04:03 +00:00
|
|
|
abstract class ReaderMapper extends QBMapper
|
|
|
|
{
|
2023-06-16 19:20:03 +00:00
|
|
|
private Time $time;
|
|
|
|
|
2023-06-16 14:58:23 +00:00
|
|
|
/**
|
2023-08-02 20:04:03 +00:00
|
|
|
* @param IDBConnection $db Instance of the Db abstraction layer
|
|
|
|
* @param string $table the name of the table. set this to allow entity
|
2023-06-17 10:12:40 +00:00
|
|
|
* @param class-string<ReaderEntity> $entity the name of the entity that the sql should be mapped to queries without using sql
|
2023-06-16 14:58:23 +00:00
|
|
|
*/
|
2023-08-02 20:04:03 +00:00
|
|
|
public function __construct(IDBConnection $db, string $table, string $entity, Time $time)
|
|
|
|
{
|
2023-06-16 14:58:23 +00:00
|
|
|
parent::__construct($db, $table, $entity);
|
|
|
|
$this->time = $time;
|
|
|
|
}
|
|
|
|
|
2023-08-02 20:04:03 +00:00
|
|
|
public function update(Entity $entity): Entity
|
|
|
|
{
|
2023-06-16 14:58:23 +00:00
|
|
|
$entity->setLastModified($this->time->getMicroTime());
|
2023-08-02 20:04:03 +00:00
|
|
|
|
2023-06-16 14:58:23 +00:00
|
|
|
return parent::update($entity);
|
|
|
|
}
|
|
|
|
|
2023-08-02 20:04:03 +00:00
|
|
|
public function insert(Entity $entity): Entity
|
|
|
|
{
|
2023-06-16 14:58:23 +00:00
|
|
|
$entity->setLastModified($this->time->getMicroTime());
|
2023-08-02 20:04:03 +00:00
|
|
|
|
2023-06-16 14:58:23 +00:00
|
|
|
return parent::insert($entity);
|
|
|
|
}
|
|
|
|
}
|