2021-06-27 11:19:26 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Db\EpisodeAction;
|
|
|
|
|
2021-10-07 12:33:16 +00:00
|
|
|
use DateTime;
|
2021-10-05 18:45:06 +00:00
|
|
|
use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
|
|
|
|
|
2021-06-27 11:19:26 +00:00
|
|
|
class EpisodeActionRepository {
|
|
|
|
/**
|
|
|
|
* @var EpisodeActionMapper
|
|
|
|
*/
|
|
|
|
private EpisodeActionMapper $episodeActionMapper;
|
|
|
|
|
|
|
|
public function __construct(EpisodeActionMapper $episodeActionMapper) {
|
|
|
|
$this->episodeActionMapper = $episodeActionMapper;
|
|
|
|
}
|
|
|
|
|
2021-10-06 12:02:31 +00:00
|
|
|
/**
|
|
|
|
* @param int $sinceEpoch
|
|
|
|
* @param string $userId
|
|
|
|
*
|
|
|
|
* @return EpisodeAction[]
|
|
|
|
*/
|
|
|
|
public function findAll(int $sinceEpoch, string $userId) : array {
|
2021-10-05 18:45:06 +00:00
|
|
|
$episodeActions = [];
|
2021-10-06 12:02:31 +00:00
|
|
|
foreach ($this->episodeActionMapper->findAll($sinceEpoch, $userId) as $entity) {
|
2021-10-05 18:45:06 +00:00
|
|
|
$episodeActions[] = $this->mapEntityToEpisodeAction($entity);
|
|
|
|
}
|
|
|
|
return $episodeActions;
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
2021-10-07 12:33:16 +00:00
|
|
|
/**
|
|
|
|
* @param string $identifier
|
|
|
|
* @param string $userId
|
|
|
|
* @return EpisodeAction|null
|
|
|
|
*/
|
2021-10-05 18:45:06 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
private function mapEntityToEpisodeAction(EpisodeActionEntity $episodeActionEntity): EpisodeAction
|
|
|
|
{
|
|
|
|
return new EpisodeAction(
|
|
|
|
$episodeActionEntity->getPodcast(),
|
|
|
|
$episodeActionEntity->getEpisode(),
|
|
|
|
$episodeActionEntity->getAction(),
|
2021-10-07 12:33:16 +00:00
|
|
|
DateTime::createFromFormat(
|
2021-10-05 18:45:06 +00:00
|
|
|
"U",
|
|
|
|
(string)$episodeActionEntity->getTimestampEpoch())
|
|
|
|
->format("Y-m-d\TH:i:s"),
|
|
|
|
$episodeActionEntity->getStarted(),
|
|
|
|
$episodeActionEntity->getPosition(),
|
|
|
|
$episodeActionEntity->getTotal(),
|
|
|
|
$episodeActionEntity->getGuid(),
|
|
|
|
$episodeActionEntity->getId(),
|
|
|
|
);
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
2021-08-24 21:19:21 +00:00
|
|
|
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|