2021-06-27 11:19:26 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Db\EpisodeAction;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
|
|
|
class EpisodeActionMapper extends \OCP\AppFramework\Db\QBMapper {
|
|
|
|
public function __construct(IDBConnection $db) {
|
2021-07-06 19:44:55 +00:00
|
|
|
parent::__construct($db, 'gpodder_episode_action', EpisodeActionEntity::class);
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function findAll(\DateTime $sinceTimestamp, string $userId): array {
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
->from($this->getTableName())
|
|
|
|
->where(
|
|
|
|
$qb->expr()->gt('timestamp', $qb->createNamedParameter($sinceTimestamp, IQueryBuilder::PARAM_DATE))
|
|
|
|
)
|
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->findEntities($qb);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function findByEpisode(string $episode, string $userId) {
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
->from($this->getTableName())
|
|
|
|
->where(
|
|
|
|
$qb->expr()->eq('episode', $qb->createNamedParameter($episode))
|
|
|
|
)
|
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
return $this->findEntity($qb);
|
|
|
|
} catch (DoesNotExistException $e) {
|
|
|
|
} catch (MultipleObjectsReturnedException $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|