From 50f35f0db2be9586205e793f315608eec59c9666 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 19 Jan 2019 22:08:29 +0100 Subject: Move icon into the top menu bar Change the way to select a random entry: - select all ids from the given user (with filters) - choose randomly one in php - find that entry --- .../CoreBundle/Controller/EntryController.php | 2 +- .../CoreBundle/Repository/EntryRepository.php | 33 ++++++++-------------- .../Resources/translations/messages.da.yml | 1 + .../Resources/translations/messages.de.yml | 1 + .../Resources/translations/messages.en.yml | 1 + .../Resources/translations/messages.es.yml | 1 + .../Resources/translations/messages.fa.yml | 1 + .../Resources/translations/messages.fr.yml | 1 + .../Resources/translations/messages.it.yml | 1 + .../Resources/translations/messages.oc.yml | 1 + .../Resources/translations/messages.pl.yml | 1 + .../Resources/translations/messages.pt.yml | 1 + .../Resources/translations/messages.ro.yml | 1 + .../Resources/translations/messages.ru.yml | 1 + .../Resources/translations/messages.th.yml | 1 + .../Resources/translations/messages.tr.yml | 1 + .../views/themes/baggy/Entry/entries.html.twig | 4 ++- .../views/themes/material/Entry/entries.html.twig | 1 - .../views/themes/material/layout.html.twig | 11 +++++++- 19 files changed, 40 insertions(+), 25 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index dfb5eb54..5c8ecb40 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -253,7 +253,7 @@ class EntryController extends Controller * * @param string $type * - * @Route("/{type}/random", name="random_entry", requirements={"_locale": "unread|starred|archive|untagged|all"}) + * @Route("/{type}/random", name="random_entry", requirements={"type": "unread|starred|archive|untagged|all"}) * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 879e6671..fabb1963 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -325,8 +325,8 @@ class EntryRepository extends EntityRepository * Find an entry by its url and its owner. * If it exists, return the entry otherwise return false. * - * @param $url - * @param $userId + * @param string $url + * @param int $userId * * @return Entry|bool */ @@ -417,8 +417,8 @@ class EntryRepository extends EntityRepository /** * Find all entries by url and owner. * - * @param $url - * @param $userId + * @param string $url + * @param int $userId * * @return array */ @@ -434,20 +434,17 @@ class EntryRepository extends EntityRepository /** * Returns a random entry, filtering by status. * - * @param $userId - * @param string $type can be unread, archive, starred, etc + * @param int $userId + * @param string $type Can be unread, archive, starred, etc * * @throws \Doctrine\ORM\NoResultException - * @throws \Doctrine\ORM\NonUniqueResultException - * - * @see https://github.com/doctrine/doctrine2/issues/5479#issuecomment-403862934 * * @return Entry */ public function getRandomEntry($userId, $type = '') { $qb = $this->getQueryBuilderByUser($userId) - ->select('MIN(e.id)', 'MAX(e.id)'); + ->select('e.id'); switch ($type) { case 'unread': @@ -465,18 +462,12 @@ class EntryRepository extends EntityRepository break; } - $idLimits = $qb - ->getQuery() - ->getOneOrNullResult(); - $randomPossibleIds = rand($idLimits[1], $idLimits[2]); + $ids = $qb->getQuery()->getArrayResult(); - return $qb - ->select('e') - ->andWhere('e.id >= :random_id') - ->setParameter('random_id', $randomPossibleIds) - ->setMaxResults(1) - ->getQuery() - ->getSingleResult(); + // random select one in the list + $randomId = $ids[mt_rand(0, \count($ids) - 1)]['id']; + + return $this->find($randomId); } /** diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 0099148a..5a770dff 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Tilføj ny artikel' search: 'Søg' filter_entries: 'Filtrer artikler' + # random_entry: Jump to a random entry from that list # export: 'Export' search_form: input_label: 'Indtast søgning' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index 5e531b78..2ae8f08e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Neuen Artikel hinzufügen' search: 'Suche' filter_entries: 'Artikel filtern' + # random_entry: Jump to a random entry from that list export: 'Exportieren' search_form: input_label: 'Suchbegriff hier eingeben' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 2b952bd5..d1d74159 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Add a new entry' search: 'Search' filter_entries: 'Filter entries' + random_entry: Jump to a random entry from that list export: 'Export' search_form: input_label: 'Enter your search here' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 2e2fbb93..741d3e9f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Añadir un nuevo artículo' search: 'Buscar' filter_entries: 'Filtrar los artículos' + # random_entry: Jump to a random entry from that list export: 'Exportar' search_form: input_label: 'Introduzca su búsqueda aquí' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index c58bbccb..2ef5dd52 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'افزودن مقالهٔ تازه' search: 'جستجو' filter_entries: 'فیلترکردن مقاله‌ها' + # random_entry: Jump to a random entry from that list export: 'برون‌بری' search_form: input_label: 'جستجوی خود را این‌جا بنویسید:' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index c3887f24..7a2029b4 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -37,6 +37,7 @@ menu: add_new_entry: "Sauvegarder un nouvel article" search: "Rechercher" filter_entries: "Filtrer les articles" + random_entry: Aller à un article aléatoire de cette liste export: "Exporter" search_form: input_label: "Saisissez votre terme de recherche" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index c2135ac0..3a459445 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Aggiungi un nuovo contenuto' search: 'Cerca' filter_entries: 'Filtra contenuti' + # random_entry: Jump to a random entry from that list export: 'Esporta' search_form: input_label: 'Inserisci qui la tua ricerca' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 6e2c1cf9..9df9e645 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Enregistrar un novèl article' search: 'Cercar' filter_entries: 'Filtrar los articles' + # random_entry: Jump to a random entry from that list export: 'Exportar' search_form: input_label: 'Picatz vòstre mot-clau a cercar aquí' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 18156cbe..684c40e2 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Dodaj nowy wpis' search: 'Szukaj' filter_entries: 'Filtruj wpisy' + # random_entry: Jump to a random entry from that list export: 'Eksportuj' search_form: input_label: 'Wpisz swoje zapytanie tutaj' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 8493af47..7932d7ab 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Adicionar uma nova entrada' search: 'Pesquisa' filter_entries: 'Filtrar entradas' + # random_entry: Jump to a random entry from that list export: 'Exportar' search_form: input_label: 'Digite aqui sua pesquisa' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 8fba13dc..4d091f03 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Introdu un nou articol' search: 'Căutare' filter_entries: 'Filtrează articolele' + # random_entry: Jump to a random entry from that list # export: 'Export' search_form: input_label: 'Introdu căutarea ta' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml index 56a63b14..cc327ae4 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml @@ -36,6 +36,7 @@ menu: add_new_entry: 'Добавить новую запись' search: 'Поиск' filter_entries: 'Фильтр записей' + # random_entry: Jump to a random entry from that list export: 'Экспорт' search_form: input_label: 'Введите текст для поиска' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index 9f0a6532..148aa541 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'เพิ่มรายการใหม่' search: 'ค้นหา' filter_entries: 'ตัวกรองรายการ' + # random_entry: Jump to a random entry from that list export: 'นำข้อมูลออก' search_form: input_label: 'ค้นหาที่นี้' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index a2093223..6fb9852a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -37,6 +37,7 @@ menu: add_new_entry: 'Yeni bir makale ekle' search: 'Ara' filter_entries: 'Filtrele' + # random_entry: Jump to a random entry from that list export: 'Dışa Aktar' search_form: input_label: 'Aramak istediğiniz herhangi bir şey yazın' diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig index f3baae2c..549d60e7 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Entry/entries.html.twig @@ -28,10 +28,12 @@
{{ 'entry.list.number_on_the_page'|transchoice(entries.count) }}
-- cgit v1.2.3