nextcloud-gpodder/lib/Db/EpisodeAction/EpisodeActionRepository.php

70 lines
1.8 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace OCA\GPodderSync\Db\EpisodeAction;
use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
class EpisodeActionRepository {
/**
* @var EpisodeActionMapper
*/
private EpisodeActionMapper $episodeActionMapper;
public function __construct(EpisodeActionMapper $episodeActionMapper) {
$this->episodeActionMapper = $episodeActionMapper;
}
/**
* @param int $sinceEpoch
* @param string $userId
*
* @return EpisodeAction[]
* @throws \Safe\Exceptions\DatetimeException
*/
public function findAll(int $sinceEpoch, string $userId) : array {
$episodeActions = [];
foreach ($this->episodeActionMapper->findAll($sinceEpoch, $userId) as $entity) {
$episodeActions[] = $this->mapEntityToEpisodeAction($entity);
}
return $episodeActions;
}
public function findByEpisodeIdentifier(string $identifier, string $userId): ?EpisodeAction {
$episodeActionEntity = $this->episodeActionMapper->findByEpisodeIdentifier($identifier, $userId);
if ($episodeActionEntity === null) {
return null;
}
return $this->mapEntityToEpisodeAction(
$episodeActionEntity
);
}
/**
* @param EpisodeActionEntity $episodeActionEntity
* @return EpisodeAction
* @throws \Safe\Exceptions\DatetimeException
*
*/
private function mapEntityToEpisodeAction(EpisodeActionEntity $episodeActionEntity): EpisodeAction
{
return new EpisodeAction(
$episodeActionEntity->getPodcast(),
$episodeActionEntity->getEpisode(),
$episodeActionEntity->getAction(),
\DateTime::createFromFormat(
"U",
(string)$episodeActionEntity->getTimestampEpoch())
->format("Y-m-d\TH:i:s"),
$episodeActionEntity->getStarted(),
$episodeActionEntity->getPosition(),
$episodeActionEntity->getTotal(),
$episodeActionEntity->getGuid(),
$episodeActionEntity->getId(),
);
}
}