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;
|
2021-10-07 12:33:16 +00:00
|
|
|
use OCP\AppFramework\Db\QBMapper;
|
|
|
|
use OCP\DB\Exception;
|
2021-06-27 11:19:26 +00:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
2021-10-07 12:33:16 +00:00
|
|
|
class EpisodeActionMapper extends QBMapper
|
2021-08-24 21:19:21 +00:00
|
|
|
{
|
|
|
|
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-10-07 12:33:16 +00:00
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-10-06 12:02:31 +00:00
|
|
|
public function findAll(int $sinceTimestamp, string $userId): array
|
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-10-06 12:02:31 +00:00
|
|
|
$qb->expr()->gt('timestamp_epoch', $qb->createNamedParameter($sinceTimestamp, IQueryBuilder::PARAM_INT))
|
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
|
|
|
|
2021-08-24 21:19:21 +00:00
|
|
|
);
|
2021-06-27 11:19:26 +00:00
|
|
|
|
|
|
|
return $this->findEntities($qb);
|
2021-10-05 18:45:06 +00:00
|
|
|
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2021-10-07 12:33:16 +00:00
|
|
|
/**
|
|
|
|
* @param string $episodeIdentifier
|
|
|
|
* @param string $userId
|
|
|
|
* @return EpisodeActionEntity|null
|
|
|
|
*/
|
2023-02-24 15:48:16 +00:00
|
|
|
public function findByEpisodeUrl(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(
|
2023-02-24 15:48:16 +00:00
|
|
|
$qb->expr()->eq('episode', $qb->createNamedParameter($episodeIdentifier))
|
|
|
|
)
|
2021-08-24 21:19:21 +00:00
|
|
|
->andWhere(
|
2023-02-24 15:48:16 +00:00
|
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
|
|
);
|
2021-06-27 11:19:26 +00:00
|
|
|
|
|
|
|
try {
|
2021-10-05 18:45:06 +00:00
|
|
|
/** @var EpisodeActionEntity $episodeActionEntity */
|
2021-10-07 12:33:16 +00:00
|
|
|
return $this->findEntity($qb);
|
|
|
|
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) {
|
|
|
|
return null;
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-05 18:45:06 +00:00
|
|
|
|
2023-02-24 15:48:16 +00:00
|
|
|
public function findByGuid(string $guid, string $userId) : ?EpisodeActionEntity
|
|
|
|
{
|
|
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
|
|
|
|
$qb->select('*')
|
|
|
|
->from($this->getTableName())
|
|
|
|
->where(
|
|
|
|
$qb->expr()->eq('guid', $qb->createNamedParameter($guid))
|
|
|
|
)
|
|
|
|
->andWhere(
|
|
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
/** @var EpisodeActionEntity $episodeActionEntity */
|
|
|
|
return $this->findEntity($qb);
|
|
|
|
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception $e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-05 18:45:06 +00:00
|
|
|
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|