2015-01-22 16:18:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace WallabagBundle\Controller;
|
|
|
|
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2015-01-23 11:45:24 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2015-01-22 16:18:56 +00:00
|
|
|
use WallabagBundle\Repository;
|
2015-01-23 11:45:24 +00:00
|
|
|
use WallabagBundle\Entity\Entries;
|
2015-01-22 16:18:56 +00:00
|
|
|
|
|
|
|
class EntryController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2015-01-23 11:45:24 +00:00
|
|
|
* Shows unread entries for current user
|
|
|
|
*
|
2015-01-22 16:18:56 +00:00
|
|
|
* @Route("/unread", name="unread")
|
2015-01-23 11:45:24 +00:00
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
2015-01-22 16:18:56 +00:00
|
|
|
*/
|
2015-01-22 20:11:22 +00:00
|
|
|
public function showUnreadAction()
|
2015-01-22 16:18:56 +00:00
|
|
|
{
|
|
|
|
$repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries');
|
2015-01-23 11:45:24 +00:00
|
|
|
$entries = $repository->findUnreadByUser(1, 0);
|
2015-01-22 16:18:56 +00:00
|
|
|
|
|
|
|
return $this->render(
|
|
|
|
'WallabagBundle:Entry:entries.html.twig',
|
|
|
|
array('entries' => $entries)
|
|
|
|
);
|
|
|
|
}
|
2015-01-22 20:11:22 +00:00
|
|
|
|
|
|
|
/**
|
2015-01-23 11:45:24 +00:00
|
|
|
* Shows read entries for current user
|
|
|
|
*
|
2015-01-22 20:11:22 +00:00
|
|
|
* @Route("/archive", name="archive")
|
2015-01-23 11:45:24 +00:00
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
2015-01-22 20:11:22 +00:00
|
|
|
*/
|
|
|
|
public function showArchiveAction()
|
|
|
|
{
|
|
|
|
$repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries');
|
2015-01-23 11:45:24 +00:00
|
|
|
$entries = $repository->findArchiveByUser(1, 0);
|
2015-01-22 20:11:22 +00:00
|
|
|
|
|
|
|
return $this->render(
|
|
|
|
'WallabagBundle:Entry:entries.html.twig',
|
|
|
|
array('entries' => $entries)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-23 11:45:24 +00:00
|
|
|
* Shows starred entries for current user
|
|
|
|
*
|
2015-01-22 20:11:22 +00:00
|
|
|
* @Route("/starred", name="starred")
|
2015-01-23 11:45:24 +00:00
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
2015-01-22 20:11:22 +00:00
|
|
|
*/
|
|
|
|
public function showStarredAction()
|
|
|
|
{
|
|
|
|
$repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries');
|
2015-01-23 11:45:24 +00:00
|
|
|
$entries = $repository->findStarredByUser(1, 0);
|
2015-01-22 20:11:22 +00:00
|
|
|
|
|
|
|
return $this->render(
|
|
|
|
'WallabagBundle:Entry:entries.html.twig',
|
|
|
|
array('entries' => $entries)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-23 11:45:24 +00:00
|
|
|
* Shows entry content
|
|
|
|
*
|
|
|
|
* @param Entries $entry
|
2015-01-22 20:11:22 +00:00
|
|
|
* @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
|
2015-01-23 11:45:24 +00:00
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
2015-01-22 20:11:22 +00:00
|
|
|
*/
|
2015-01-23 11:45:24 +00:00
|
|
|
public function viewAction(Entries $entry)
|
2015-01-22 20:11:22 +00:00
|
|
|
{
|
|
|
|
return $this->render(
|
|
|
|
'WallabagBundle:Entry:entry.html.twig',
|
|
|
|
array('entry' => $entry)
|
|
|
|
);
|
2015-01-23 11:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes read status for an entry
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Entries $entry
|
|
|
|
* @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
|
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function toggleArchiveAction(Request $request, Entries $entry)
|
|
|
|
{
|
|
|
|
$entry->toggleArchive();
|
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
|
|
|
$this->get('session')->getFlashBag()->add(
|
|
|
|
'notice',
|
|
|
|
'Entry archived'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->redirect($request->headers->get('referer'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes favorite status for an entry
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Entries $entry
|
|
|
|
* @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
|
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function toggleStarAction(Request $request, Entries $entry)
|
|
|
|
{
|
|
|
|
$entry->toggleStar();
|
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
|
|
|
$this->get('session')->getFlashBag()->add(
|
|
|
|
'notice',
|
|
|
|
'Entry starred'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->redirect($request->headers->get('referer'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes entry
|
|
|
|
*
|
|
|
|
* @param Request $request
|
|
|
|
* @param Entries $entry
|
|
|
|
* @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
|
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function deleteEntryAction(Request $request, Entries $entry)
|
|
|
|
{
|
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->remove($entry);
|
|
|
|
$em->flush();
|
|
|
|
|
|
|
|
$this->get('session')->getFlashBag()->add(
|
|
|
|
'notice',
|
|
|
|
'Entry deleted'
|
|
|
|
);
|
2015-01-22 20:11:22 +00:00
|
|
|
|
2015-01-23 11:45:24 +00:00
|
|
|
return $this->redirect($request->headers->get('referer'));
|
2015-01-22 20:11:22 +00:00
|
|
|
}
|
2015-01-22 16:18:56 +00:00
|
|
|
}
|