Browse Source

Added offline pages

Jeroen De Meerleer 8 months ago
parent
commit
2722711b6d

+ 6 - 3
src/JeroenED/PortfolioBundle/Controller/ApiController.php

@@ -16,13 +16,16 @@ class ApiController extends Controller {
     /**
      * @Route("/api/getPage/{slug}", defaults={ "slug" = "none"})
      */
-    public function getPageAction($slug)
+    public function getPageAction($slug, UserInterface $user = null)
     {
         if($slug == 'none') throw new NotFoundHttpException('Page not found');
-                
+        $loggedin = null !== $user ? true : false;
+
+        $whereclause = "p.slug LIKE :slug";
+        $whereclause .= (!$loggedin) ? " AND online = true": "";
         $page = $this->getDoctrine()->getRepository(Page::class)
             ->createQueryBuilder('p')
-            ->where("p.slug LIKE :slug")
+            ->where($whereclause)
             ->setParameter('slug', '%;'.$slug.';%')
             ->getQuery()->getResult();
         if ($page == null ) throw new NotFoundHttpException('Page not found');

+ 30 - 2
src/JeroenED/PortfolioBundle/Entity/Page.php

@@ -34,12 +34,17 @@ class Page {
      * @ORM\Column(type="string", length=250, nullable=true)
      */
     protected $download;
-    
+
     /**
      *
-     * @ORM\Column(type="text") 
+     * @ORM\Column(type="text")
      */
     protected $html;
+    /**
+     *
+     * @ORM\Column(type="boolean", options={"default" : true})
+     */
+    protected $online;
 
     /**
      *
@@ -126,6 +131,29 @@ class Page {
         return $this->html;
     }
 
+    /**
+     * get online
+     *
+     * @return bool
+     */
+    public function getOnline()
+    {
+        return $this->online;
+    }
+
+    /**
+     * set online
+     *
+     * @param bool $online
+     * @return Page
+     */
+    public function setOnline($online)
+    {
+        $this->online = $online;
+
+        return $this;
+    }
+
     /**
      * Set slug
      *