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 {
|
2021-11-03 12:47:24 +00:00
|
|
|
|
2021-06-27 11:19:26 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-02-24 15:48:16 +00:00
|
|
|
public function findByEpisodeUrl(string $episodeUrl, string $userId): ?EpisodeAction {
|
|
|
|
$episodeActionEntity = $this->episodeActionMapper->findByEpisodeUrl($episodeUrl, $userId);
|
2021-10-05 18:45:06 +00:00
|
|
|
|
2023-02-24 15:48:16 +00:00
|
|
|
if ($episodeActionEntity === null) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-10-05 18:45:06 +00:00
|
|
|
|
2023-02-24 15:48:16 +00: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 18:45:06 +00:00
|
|
|
|
2023-02-24 19:48:53 +00:00
|
|
|
public function deleteEpisodeActionByEpisodeUrl(string $episodeUrl, string $userId) : void {
|
|
|
|
$episodeAction = $this->episodeActionMapper->findByEpisodeUrl($episodeUrl, $userId);
|
|
|
|
$this->episodeActionMapper->delete($episodeAction);
|
|
|
|
}
|
|
|
|
|
2021-10-05 18:45:06 +00:00
|
|
|
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
|
|
|
}
|