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;
|
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
public function findAll(\DateTime $sinceTimestamp, string $userId): array
|
|
|
|
{
|
2021-06-27 11:19:26 +00:00
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
->from($this->getTableName())
|
|
|
|
->where(
|
|
|
|
$qb->expr()->gt('timestamp', $qb->createNamedParameter($sinceTimestamp, IQueryBuilder::PARAM_DATE))
|
|
|
|
)
|
2021-08-24 21:19:21 +00:00
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
2021-06-27 11:19:26 +00:00
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
);
|
2021-06-27 11:19:26 +00:00
|
|
|
|
|
|
|
return $this->findEntities($qb);
|
|
|
|
}
|
|
|
|
|
2021-08-25 17:33:00 +00:00
|
|
|
public function findByEpisodeIdentifier(string $episodeIdentifier, string $userId) : ?EpisodeActionEntity
|
2021-08-24 21:19:21 +00:00
|
|
|
{
|
2021-06-27 11:19:26 +00:00
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
->from($this->getTableName())
|
|
|
|
->where(
|
2021-08-24 21:19:21 +00:00
|
|
|
$qb->expr()->orX(
|
|
|
|
$qb->expr()->eq('episode', $qb->createNamedParameter($episodeIdentifier)),
|
|
|
|
$qb->expr()->eq('guid', $qb->createNamedParameter($episodeIdentifier)))
|
2021-06-27 11:19:26 +00:00
|
|
|
)
|
2021-08-24 21:19:21 +00:00
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
|
|
);
|
2021-06-27 11:19:26 +00:00
|
|
|
|
|
|
|
try {
|
2021-08-24 21:19:21 +00:00
|
|
|
/** @var EpisodeActionEntity $episodeActionEntity*/
|
|
|
|
$episodeActionEntity = $this->findEntity($qb);
|
|
|
|
|
|
|
|
return $episodeActionEntity;
|
2021-06-27 11:19:26 +00:00
|
|
|
} catch (DoesNotExistException $e) {
|
|
|
|
} catch (MultipleObjectsReturnedException $e) {
|
|
|
|
}
|
2021-08-25 17:33:00 +00:00
|
|
|
|
|
|
|
return null;
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
}
|