use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
-use Pagerfanta\Pagerfanta;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Wallabag\CoreBundle\Form\Type\EntryFilterType;
use Wallabag\CoreBundle\Form\Type\EditEntryType;
use Wallabag\CoreBundle\Form\Type\NewEntryType;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
class EntryController extends Controller
{
}
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery());
- $entries = new Pagerfanta($pagerAdapter);
- $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage());
+ $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')
+ ->prepare($pagerAdapter, $page);
+
try {
$entries->setCurrentPage($page);
} catch (OutOfRangeCurrentPageException $e) {
}
/**
- * Changes star status for an entry.
+ * Changes starred status for an entry.
*
* @param Request $request
* @param Entry $entry
*/
private function checkUserAction(Entry $entry)
{
- if ($this->getUser()->getId() != $entry->getUser()->getId()) {
+ if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) {
throw $this->createAccessDeniedException('You can not access this entry.');
}
}
{
return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
}
+
+ /**
+ * Get public URL for entry (and generate it if necessary).
+ *
+ * @param Entry $entry
+ *
+ * @Route("/share/{id}", requirements={"id" = "\d+"}, name="share")
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function shareAction(Entry $entry)
+ {
+ $this->checkUserAction($entry);
+
+ if ('' === $entry->getUuid() || null === $entry->getUuid()) {
+ $this->generateEntryUuid($entry);
+ }
+
+ return $this->redirect($this->generateUrl('share_entry', [
+ 'uuid' => $entry->getUuid(),
+ ]));
+ }
+
+ /**
+ * Disable public sharing for an entry.
+ *
+ * @param Entry $entry
+ *
+ * @Route("/share/delete/{id}", requirements={"id" = "\d+"}, name="delete_share")
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function deleteShareAction(Entry $entry)
+ {
+ $this->checkUserAction($entry);
+
+ $entry->cleanUuid();
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
+
+ return $this->redirect($this->generateUrl('view', [
+ 'id' => $entry->getId(),
+ ]));
+ }
+
+ /**
+ * Share entry content.
+ *
+ * @param Entry $entry
+ *
+ * @Route("/share/{uuid}", requirements={"uuid" = ".+"}, name="share_entry")
+ * @Cache(maxage="25200", public=true)
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function shareEntryAction(Entry $entry)
+ {
+ return $this->render(
+ '@WallabagCore/themes/share.html.twig',
+ array('entry' => $entry)
+ );
+ }
+
+ /**
+ * @param Entry $entry
+ */
+ private function generateEntryUuid(Entry $entry)
+ {
+ $entry->generateUuid();
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entry);
+ $em->flush();
+ }
}