userSession = $userSession; $this->recommendationService = $recommendationService; $this->config = $config; } /** * Get recommendations, but only if enabled * * @NoAdminRequired * @return DataResponse}, array{}> * * 200: Recommendations returned */ public function index(): DataResponse { $user = $this->userSession->getUser(); if (is_null($user)) { throw new Exception("Not logged in"); } $response = []; $response['enabled'] = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled', 'true') === 'true'; if ($response['enabled']) { $response['recommendations'] = array_map(static fn (IRecommendation $recommendation) => $recommendation->jsonSerialize(), $this->recommendationService->getRecommendations($user)); } return new DataResponse( $response ); } /** * Get recommendations * * @NoAdminRequired * @return DataResponse}, array{}> * * 200: Recommendations returned */ public function always(): DataResponse { $user = $this->userSession->getUser(); if (is_null($user)) { throw new Exception("Not logged in"); } $response = [ 'enabled' => $this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled', 'true') === 'true', 'recommendations' => array_map(static fn (IRecommendation $recommendation) => $recommendation->jsonSerialize(), $this->recommendationService->getRecommendations($user)), ]; return new DataResponse( $response ); } }