]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/WallabagBundle/Controller/EntryController.php
some parameters, new entry form, etc.
[github/wallabag/wallabag.git] / src / WallabagBundle / Controller / EntryController.php
index fbbb76aa2054dbedc06ee391e3ca273c39de03f5..dc1876fac4416652a670599d2a59a46c347d7e22 100644 (file)
@@ -7,9 +7,51 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
 use WallabagBundle\Repository;
 use WallabagBundle\Entity\Entries;
+use Wallabag\Wallabag\Tools;
+use Wallabag\Wallabag\Url;
 
 class EntryController extends Controller
 {
+
+    /**
+     * @param Request $request
+     * @Route("/new", name="new_entry")
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function addEntryAction(Request $request)
+    {
+        $entry = new Entries();
+        $entry->setUserId(1);
+
+        $form = $this->createFormBuilder($entry)
+            ->add('url', 'url')
+            ->add('save', 'submit')
+            ->getForm();
+
+        $form->handleRequest($request);
+
+        if ($form->isValid()) {
+
+            $content = Tools::getPageContent(new Url($entry->getUrl()));
+            var_dump($content);die;
+
+            $em = $this->getDoctrine()->getEntityManager();
+            $em->persist($entry);
+            $em->flush();
+
+            $this->get('session')->getFlashBag()->add(
+                'notice',
+                'Entry saved'
+            );
+
+            return $this->redirect($this->generateUrl('homepage'));
+        }
+
+        return $this->render('WallabagBundle:Entry:new.html.twig', array(
+            'form' => $form->createView(),
+        ));
+    }
+
     /**
      * Shows unread entries for current user
      *