/** * @param Tag $tag * @param int $page * * @Route("/tag/list/{slug}/{page}", name="tag_entries", defaults={"page" = "1"}) * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) * * @return \Symfony\Component\HttpFoundation\Response */ public function showEntriesForTagAction(Tag $tag, $page, Request $request) { $entriesByTag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry')->findAllByTagId($this->getUser()->getId(), $tag->getId()); $pagerAdapter = new ArrayAdapter($entriesByTag); $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter, $page); try { $entries->setCurrentPage($page); } catch (OutOfRangeCurrentPageException $e) { if ($page > 1) { return $this->redirect($this->generateUrl($request->get('_route'), ['slug' => $tag->getSlug(), 'page' => $entries->getNbPages()]), 302); } } return $this->render('WallabagCoreBundle:Entry:entries.html.twig', ['form' => null, 'entries' => $entries, 'currentPage' => $page]); }
/** * Remove a tag from all user entries. * * We need to loop on each entry attached to the given tag to remove it, since Doctrine doesn't know EntryTag entity because it's a ManyToMany relation. * It could be faster with one query but I don't know how to retrieve the table name `entry_tag` which can have a prefix: * * DELETE et FROM entry_tag et WHERE et.entry_id IN ( SELECT e.id FROM entry e WHERE e.user_id = :userId ) AND et.tag_id = :tagId * * @param int $userId * @param Tag $tag */ public function removeTag($userId, Tag $tag) { $entries = $this->getBuilderByUser($userId)->innerJoin('e.tags', 't')->andWhere('t.id = :tagId')->setParameter('tagId', $tag->getId())->getQuery()->getResult(); foreach ($entries as $entry) { $entry->removeTag($tag); } $this->getEntityManager()->flush(); }