2022-08-28 18:44:30 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Core\PodcastData;
|
|
|
|
|
2022-09-17 15:20:26 +00:00
|
|
|
use JsonSerializable;
|
|
|
|
|
|
|
|
class PodcastMetrics implements JsonSerializable {
|
2022-08-28 18:44:30 +00:00
|
|
|
private string $url;
|
|
|
|
private int $listenedSeconds;
|
|
|
|
private PodcastActionCounts $actionCounts;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
string $url,
|
|
|
|
int $listenedSeconds = 0,
|
2022-10-26 20:32:59 +00:00
|
|
|
?PodcastActionCounts $actionCounts = null
|
2022-08-28 18:44:30 +00:00
|
|
|
) {
|
|
|
|
$this->url = $url;
|
|
|
|
$this->actionCounts = $actionCounts ?? new PodcastActionCounts;
|
|
|
|
$this->listenedSeconds = $listenedSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUrl(): string {
|
|
|
|
return $this->url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return PodcastActionCounts
|
|
|
|
*/
|
|
|
|
public function getActionCounts(): PodcastActionCounts {
|
|
|
|
return $this->actionCounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getListenedSeconds(): int {
|
|
|
|
return $this->listenedSeconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $seconds
|
|
|
|
*/
|
|
|
|
public function addListenedSeconds(int $seconds): void {
|
|
|
|
$this->listenedSeconds += $seconds;
|
|
|
|
}
|
|
|
|
|
2022-09-17 15:20:26 +00:00
|
|
|
/**
|
|
|
|
* @return array<string,mixed>
|
|
|
|
*/
|
2022-08-28 18:44:30 +00:00
|
|
|
public function toArray(): array {
|
|
|
|
return
|
|
|
|
[
|
|
|
|
'url' => $this->url,
|
|
|
|
'listenedSeconds' => $this->listenedSeconds,
|
|
|
|
'actionCounts' => $this->actionCounts->toArray(),
|
|
|
|
];
|
|
|
|
}
|
2022-09-17 15:20:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string,mixed>
|
|
|
|
*/
|
2022-10-27 07:10:16 +00:00
|
|
|
public function jsonSerialize(): array {
|
2022-09-17 15:20:26 +00:00
|
|
|
return $this->toArray();
|
|
|
|
}
|
2022-08-28 18:44:30 +00:00
|
|
|
}
|