2021-06-27 13:19:26 +02:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Db\EpisodeAction;
|
|
|
|
|
2021-10-07 14:33:16 +02:00
|
|
|
use DateTime;
|
2021-10-05 20:45:06 +02:00
|
|
|
use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
|
|
|
|
|
2021-06-27 13:19:26 +02:00
|
|
|
class EpisodeActionRepository {
|
2021-11-03 13:47:24 +01:00
|
|
|
|
2021-06-27 13:19:26 +02:00
|
|
|
private EpisodeActionMapper $episodeActionMapper;
|
|
|
|
|
|
|
|
public function __construct(EpisodeActionMapper $episodeActionMapper) {
|
|
|
|
$this->episodeActionMapper = $episodeActionMapper;
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:02:31 +02:00
|
|
|
/**
|
|
|
|
* @param int $sinceEpoch
|
|
|
|
* @param string $userId
|
|
|
|
*
|
|
|
|
* @return EpisodeAction[]
|
|
|
|
*/
|
|
|
|
public function findAll(int $sinceEpoch, string $userId) : array {
|
2021-10-05 20:45:06 +02:00
|
|
|
$episodeActions = [];
|
2021-10-06 14:02:31 +02:00
|
|
|
foreach ($this->episodeActionMapper->findAll($sinceEpoch, $userId) as $entity) {
|
2021-10-05 20:45:06 +02:00
|
|
|
$episodeActions[] = $this->mapEntityToEpisodeAction($entity);
|
|
|
|
}
|
|
|
|
return $episodeActions;
|
2021-06-27 13:19:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-24 16:48:16 +01:00
|
|
|
public function findByEpisodeUrl(string $episodeUrl, string $userId): ?EpisodeAction {
|
|
|
|
$episodeActionEntity = $this->episodeActionMapper->findByEpisodeUrl($episodeUrl, $userId);
|
2021-10-05 20:45:06 +02:00
|
|
|
|
2023-02-24 16:48:16 +01:00
|
|
|
if ($episodeActionEntity === null) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-10-05 20:45:06 +02:00
|
|
|
|
2023-02-24 16:48:16 +01:00
|
|
|
return $this->mapEntityToEpisodeAction(
|
|
|
|
$episodeActionEntity
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function findByGuid(string $guid, string $userId): ?EpisodeAction {
|
|
|
|
$episodeActionEntity = $this->episodeActionMapper->findByGuid($guid, $userId);
|
|
|
|
|
|
|
|
if ($episodeActionEntity === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->mapEntityToEpisodeAction(
|
|
|
|
$episodeActionEntity
|
|
|
|
);
|
|
|
|
}
|
2021-10-05 20:45:06 +02:00
|
|
|
|
2023-02-24 20:48:53 +01:00
|
|
|
public function deleteEpisodeActionByEpisodeUrl(string $episodeUrl, string $userId) : void {
|
|
|
|
$episodeAction = $this->episodeActionMapper->findByEpisodeUrl($episodeUrl, $userId);
|
|
|
|
$this->episodeActionMapper->delete($episodeAction);
|
|
|
|
}
|
|
|
|
|
2021-10-05 20:45:06 +02:00
|
|
|
private function mapEntityToEpisodeAction(EpisodeActionEntity $episodeActionEntity): EpisodeAction
|
|
|
|
{
|
|
|
|
return new EpisodeAction(
|
|
|
|
$episodeActionEntity->getPodcast(),
|
|
|
|
$episodeActionEntity->getEpisode(),
|
|
|
|
$episodeActionEntity->getAction(),
|
2021-10-07 14:33:16 +02:00
|
|
|
DateTime::createFromFormat(
|
2021-10-05 20:45:06 +02: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 13:19:26 +02:00
|
|
|
}
|
2021-08-24 23:19:21 +02:00
|
|
|
|
2021-06-27 13:19:26 +02:00
|
|
|
}
|