/**
  * View squarespace page module
  *
  * @param SquarespacePage $page
  * @return array
  *
  * @Route(
  *      path = "/course/{code}/sq-page/{id}",
  *      name = "beloop_view_module_squarespace_page",
  *      methods = {"GET"}
  * )
  *
  * @Template
  *
  * @EntityAnnotation(
  *      class = {
  *          "factory" = "beloop.factory.squarespace_page",
  *          "method" = "create",
  *          "static" = false
  *      },
  *      name = "page",
  *      mapping = {
  *          "id" = "~id~"
  *      },
  *      mappingFallback = true
  * )
  */
 public function viewSquarespacePageAction(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');
         }
     }
     $renderUrl = $this->generateUrl('beloop_render_module_squarespace_page', ['code' => $course->getCode(), 'id' => $page->getId()], UrlGeneratorInterface::ABSOLUTE_URL);
     return ['section' => $course->isDemo() ? 'public-courses' : 'my-courses', 'user' => $user, 'course' => $course, 'module' => $page, 'renderUrl' => $renderUrl];
 }