l = $l; $this->subscriptionChangeRepository = $subscriptionChangeRepository; $this->episodeActionRepository = $episodeActionRepository; $this->userId = $UserId ?? ''; } /** * * @NoAdminRequired * @NoCSRFRequired * * @return JSONResponse */ public function metrics(): JSONResponse { $sinceDatetime = (new DateTime)->setTimestamp(0); $subscriptions = $this->extractUrlList($this->subscriptionChangeRepository->findAllSubscribed($sinceDatetime, $this->userId)); $episodeActions = $this->episodeActionRepository->findAll(0, $this->userId); $subStats = array(); foreach ($episodeActions as $action) { $pod = $action->getPodcast(); $sub = $subStats[$pod] ?? array(); $sub['started']++; $subStats[$pod] = $sub; } return new JSONResponse([ 'subscriptions' => $subscriptions, 'subStats' => $subStats, ]); } /** * @param array $allSubscribed * @return mixed */ private function extractUrlList(array $allSubscribed): array { return array_map(static function (SubscriptionChangeEntity $subscription) { return $subscription->getUrl(); }, $allSubscribed); } }