mirror of
https://github.com/thrillfall/nextcloud-gpodder.git
synced 2024-12-24 14:52:14 +01:00
62 lines
1.6 KiB
PHP
62 lines
1.6 KiB
PHP
<?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)
|
|
{
|
|
parent::__construct($db, 'gpodder_episode_action', EpisodeActionEntity::class);
|
|
}
|
|
|
|
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 findByEpisodeIdentifier(string $episodeIdentifier, string $userId) : ?EpisodeActionEntity
|
|
{
|
|
$qb = $this->db->getQueryBuilder();
|
|
|
|
$qb->select('*')
|
|
->from($this->getTableName())
|
|
->where(
|
|
$qb->expr()->orX(
|
|
$qb->expr()->eq('episode', $qb->createNamedParameter($episodeIdentifier)),
|
|
$qb->expr()->eq('guid', $qb->createNamedParameter($episodeIdentifier)))
|
|
)
|
|
->andWhere(
|
|
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
|
);
|
|
|
|
try {
|
|
/** @var EpisodeActionEntity $episodeActionEntity*/
|
|
$episodeActionEntity = $this->findEntity($qb);
|
|
|
|
return $episodeActionEntity;
|
|
} catch (DoesNotExistException $e) {
|
|
} catch (MultipleObjectsReturnedException $e) {
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|