namespace Wallabag\CoreBundle\Controller;
+use Doctrine\ORM\NoResultException;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
return $this->showEntries('starred', $request, $page);
}
+ /**
+ * Shows random unread entry.
+ *
+ * @param Entry $entry
+ *
+ * @Route("/unread/random", name="unread_random")
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function showRandomUnreadEntryAction()
+ {
+ $repository = $this->get('wallabag_core.entry_repository');
+
+ try {
+ $entry = $repository->getRandomEntry($this->getUser()->getId(), 'unread');
+ } catch (NoResultException $e) {
+ $bag = $this->get('session')->getFlashBag();
+ $bag->clear();
+ $bag->add('notice', 'flashes.entry.notice.no_random_entry');
+
+ return $this->redirect($this->generateUrl('homepage'));
+ }
+
+ return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
+ }
+
+ /**
+ * Shows random favorite entry.
+ *
+ * @param Entry $entry
+ *
+ * @Route("/starred/random", name="starred_random")
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function showRandomStarredEntryAction()
+ {
+ $repository = $this->get('wallabag_core.entry_repository');
+
+ try {
+ $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
+ } catch (NoResultException $e) {
+ $bag = $this->get('session')->getFlashBag();
+ $bag->clear();
+ $bag->add('notice', 'flashes.entry.notice.no_random_entry');
+
+ return $this->redirect($this->generateUrl('homepage'));
+ }
+
+ return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
+ }
+
+ /**
+ * Shows random archived entry.
+ *
+ * @param Entry $entry
+ *
+ * @Route("/archive/random", name="archive_random")
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function showRandomArchiveEntryAction()
+ {
+ $repository = $this->get('wallabag_core.entry_repository');
+
+ try {
+ $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
+ } catch (NoResultException $e) {
+ $bag = $this->get('session')->getFlashBag();
+ $bag->clear();
+ $bag->add('notice', 'flashes.entry.notice.no_random_entry');
+
+ return $this->redirect($this->generateUrl('homepage'));
+ }
+
+ return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
+ }
+
+ /**
+ * Shows random all entry.
+ *
+ * @param Entry $entry
+ *
+ * @Route("/all/random", name="all_random")
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function showRandomAllEntryAction()
+ {
+ $repository = $this->get('wallabag_core.entry_repository');
+
+ try {
+ $entry = $repository->getRandomEntry($this->getUser()->getId());
+ } catch (NoResultException $e) {
+ $bag = $this->get('session')->getFlashBag();
+ $bag->clear();
+ $bag->add('notice', 'flashes.entry.notice.no_random_entry');
+
+ return $this->redirect($this->generateUrl('homepage'));
+ }
+
+ return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
+ }
+
/**
* Shows entry content.
*
*/
public function getBuilderForUntaggedByUser($userId)
{
- return $this
- ->sortQueryBuilder($this->getRawBuilderForUntaggedByUser($userId));
+ return $this->sortQueryBuilder($this->getRawBuilderForUntaggedByUser($userId));
}
/**
->getResult();
}
+ /**
+ * Returns a random entry, filtering by status.
+ *
+ * @param $userId
+ * @param string $status can be unread, archive or starred
+ *
+ * @throws \Doctrine\ORM\NoResultException
+ * @throws \Doctrine\ORM\NonUniqueResultException
+ *
+ * @return Entry
+ */
+ public function getRandomEntry($userId, $status = '')
+ {
+ $max = $this->getEntityManager()
+ ->createQuery('SELECT MAX(e.id) FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = :userId')
+ ->setParameter('userId', $userId)
+ ->getSingleScalarResult();
+
+ $qb = $this->createQueryBuilder('e')
+ ->where('e.user = :user_id')->setParameter('user_id', $userId);
+
+ if ('unread' === $status) {
+ $qb->andWhere('e.isArchived = false');
+ }
+
+ if ('archive' === $status) {
+ $qb->andWhere('e.isArchived = true');
+ }
+
+ if ('starred' === $status) {
+ $qb->andWhere('e.isStarred = true');
+ }
+
+ return $qb->andWhere('e.id >= :rand')
+ ->setParameter('rand', rand(0, $max))
+ ->setMaxResults(1)
+ ->getQuery()
+ ->getSingleResult();
+ }
+
/**
* Return a query builder to be used by other getBuilderFor* method.
*
*/
private function sortQueryBuilder(QueryBuilder $qb, $sortBy = 'createdAt', $direction = 'desc')
{
- return $qb
- ->orderBy(sprintf('e.%s', $sortBy), $direction);
+ return $qb->orderBy(sprintf('e.%s', $sortBy), $direction);
}
}
entry_starred: 'Artikel markeret som favorit'
entry_unstarred: 'Artikel ikke længere markeret som favorit'
entry_deleted: 'Artikel slettet'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
# tag_added: 'Tag added'
entry_starred: 'Eintrag favorisiert'
entry_unstarred: 'Eintrag defavorisiert'
entry_deleted: 'Eintrag gelöscht'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Tag hinzugefügt'
entry_starred: 'Entry starred'
entry_unstarred: 'Entry unstarred'
entry_deleted: 'Entry deleted'
+ no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Tag added'
entry_starred: 'Artículo marcado como favorito'
entry_unstarred: 'Artículo desmarcado como favorito'
entry_deleted: 'Artículo eliminado'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Etiqueta añadida'
entry_starred: 'مقاله برگزیده شد'
entry_unstarred: 'مقاله نابرگزیده شد'
entry_deleted: 'مقاله پاک شد'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'برچسب افزوده شد'
entry_starred: "Article ajouté dans les favoris"
entry_unstarred: "Article retiré des favoris"
entry_deleted: "Article supprimé"
+ no_random_entry: "Aucun article correspond aux critères n'a été trouvé"
tag:
notice:
tag_added: "Tag ajouté"
entry_starred: 'Contenuto segnato come preferito'
entry_unstarred: 'Contenuto rimosso dai preferiti'
entry_deleted: 'Contenuto eliminato'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Etichetta aggiunta'
entry_starred: 'Article ajustat dins los favorits'
entry_unstarred: 'Article quitat dels favorits'
entry_deleted: 'Article suprimit'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Etiqueta ajustada'
entry_starred: 'Wpis oznaczony gwiazdką'
entry_unstarred: 'Wpis odznaczony gwiazdką'
entry_deleted: 'Wpis usunięty'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Tag dodany'
entry_starred: 'Entrada destacada'
entry_unstarred: 'Entrada não destacada'
entry_deleted: 'Entrada apagada'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Tag adicionada'
entry_starred: 'Articol adăugat la favorite'
entry_unstarred: 'Articol șters de la favorite'
entry_deleted: 'Articol șters'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
# tag_added: 'Tag added'
entry_starred: 'Запись помечена звездочкой'
entry_unstarred: 'Пометка звездочкой у записи убрана'
entry_deleted: 'Запись удалена'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Тег добавлен'
notice:
added: 'Пользователь "%username%" добавлен'
updated: 'Пользователь "%username%" обновлен'
- deleted: 'Пользователь "%username%" удален'
\ No newline at end of file
+ deleted: 'Пользователь "%username%" удален'
entry_starred: 'รายการที่แสดง'
entry_unstarred: 'รายการที่ไม่ได้แสดง'
entry_deleted: 'รายการที่ถูกลบ'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'แท็กที่เพิ่ม'
entry_starred: 'Makale favorilere eklendi'
entry_unstarred: 'Makale favorilerden çıkartıldı'
entry_deleted: 'Makale silindi'
+ # no_random_entry: 'No article with these criterias was found'
tag:
notice:
tag_added: 'Etiket eklendi'
{% block content %}
{% set currentRoute = app.request.attributes.get('_route') %}
+ {% if currentRoute == 'homepage' %}
+ {% set currentRoute = 'unread' %}
+ {% endif %}
{% set listMode = app.user.config.listMode %}
<div class="results">
<div class="nb-results">{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}</div>
<div class="pagination">
<a href="{{ path('switch_view_mode') }}"><i class="listMode-btn material-icons md-24">{% if listMode == 0 %}list{% else %}view_module{% endif %}</i></a>
+ <a href="{{ path(currentRoute ~ '_random') }}">random</a>
{% if app.user.config.rssToken %}
{% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
{% endif %}
{% set currentTag = null %}
{% if tag is defined %}
{% set currentTag = tag %}
- {% endif %}
- {% if currentRoute == 'homepage' %}
- {% set currentRoute = 'unread' %}
{% endif %}
<h2>{{ 'entry.list.export_title'|trans }}</h2>
<a href="javascript: void(null);" id="download-form-close" class="close-button--popup close-button">×</a>
{% block content %}
{% set listMode = app.user.config.listMode %}
{% set currentRoute = app.request.attributes.get('_route') %}
+ {% if currentRoute == 'homepage' %}
+ {% set currentRoute = 'unread' %}
+ {% endif %}
<div class="results">
<div class="nb-results">
{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}
<a href="{{ path('switch_view_mode') }}"><i class="material-icons">{% if listMode == 0 %}view_list{% else %}view_module{% endif %}</i></a>
+ <a href="{{ path(currentRoute ~ '_random') }}">random</a>
{% if app.user.config.rssToken %}
{% include "@WallabagCore/themes/common/Entry/_rss_link.html.twig" %}
{% endif %}
{% set currentTag = null %}
{% if tag is defined %}
{% set currentTag = tag.slug %}
- {% endif %}
- {% if currentRoute == 'homepage' %}
- {% set currentRoute = 'unread' %}
{% endif %}
<h4 class="center">{{ 'entry.list.export_title'|trans }}</h4>
<ul>