コード例 #1
0
ファイル: PageRenderer.php プロジェクト: beloop/components
 /**
  *
  * @param SquarespacePage $page
  * @return mixed
  */
 public function render(SquarespacePage $page)
 {
     $response = $this->client->get($this->extractResourceFromUri($this->base_url, $page->getUrl()), ['exceptions' => false, 'cookies' => $this->authenticationService->jar]);
     if ($response->getStatusCode() === Response::HTTP_UNAUTHORIZED) {
         $this->authenticationService->authenticate();
         $response = $this->client->get($this->extractResourceFromUri($this->base_url, $page->getUrl()), ['exceptions' => false, 'cookies' => $this->authenticationService->jar]);
     }
     return $this->buildAbsolutePaths($this->client->getConfig('base_uri'), $response->getBody());
 }
コード例 #2
0
 /**
  * Render password protected page
  *
  * @param SquarespacePage $page
  * @return array
  *
  * @Route(
  *      path = "/course/{code}/sq-page/render/{id}",
  *      name = "beloop_render_module_squarespace_page",
  *      methods = {"GET"}
  * )
  *
  * @EntityAnnotation(
  *      class = {
  *          "factory" = "beloop.factory.squarespace_page",
  *          "method" = "create",
  *          "static" = false
  *      },
  *      name = "page",
  *      mapping = {
  *          "id" = "~id~"
  *      },
  *      mappingFallback = true
  * )
  */
 public function renderSquarespacePageAction(SquarespacePage $page)
 {
     $user = $this->getUser();
     $course = $page->getCourse();
     // Extra checks if user is not TEACHER or ADMIN
     if (false === $this->get('security.authorization_checker')->isGranted('ROLE_TEACHER') && false === $course->isDemo()) {
         $userEnrolled = $course->getEnrolledUsers()->contains($user);
         if (!$userEnrolled) {
             throw $this->createNotFoundException('The course does not exist');
         }
         if (!$page->isAvailable()) {
             throw $this->createNotFoundException('The course does not exist');
         }
     }
     $content = $this->get('beloop.squarespace.page_renderer')->render($page);
     return new Response($content);
 }