From be463487cc195026b11e92f1d6d6276f5851b97e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 6 Feb 2015 07:45:32 +0100 Subject: rename Entries to Entry --- .../CoreBundle/Controller/EntryController.php | 26 +- .../Controller/WallabagRestController.php | 25 +- src/Wallabag/CoreBundle/Entity/Entries.php | 417 --------------------- src/Wallabag/CoreBundle/Entity/Entry.php | 412 ++++++++++++++++++++ src/Wallabag/CoreBundle/Helper/Entries.php | 7 - src/Wallabag/CoreBundle/Helper/Entry.php | 7 + .../CoreBundle/Repository/EntriesRepository.php | 115 ------ .../CoreBundle/Repository/EntryRepository.php | 114 ++++++ 8 files changed, 560 insertions(+), 563 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Entity/Entries.php create mode 100644 src/Wallabag/CoreBundle/Entity/Entry.php delete mode 100644 src/Wallabag/CoreBundle/Helper/Entries.php create mode 100644 src/Wallabag/CoreBundle/Helper/Entry.php delete mode 100644 src/Wallabag/CoreBundle/Repository/EntriesRepository.php create mode 100644 src/Wallabag/CoreBundle/Repository/EntryRepository.php diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index eb5b43ad..6326d31f 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php @@ -5,8 +5,8 @@ namespace Wallabag\CoreBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; +use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Repository; -use Wallabag\CoreBundle\Entity\Entries; use Wallabag\CoreBundle\Service\Extractor; use Wallabag\CoreBundle\Helper\Url; @@ -19,7 +19,7 @@ class EntryController extends Controller */ public function addEntryAction(Request $request) { - $entry = new Entries(); + $entry = new Entry(); $entry->setUserId(1); $form = $this->createFormBuilder($entry) @@ -60,7 +60,7 @@ class EntryController extends Controller */ public function showUnreadAction() { - $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); + $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); // TODO don't give the user ID like this // TODO change pagination $entries = $repository->findUnreadByUser(1, 0); @@ -79,7 +79,7 @@ class EntryController extends Controller */ public function showArchiveAction() { - $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); + $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); // TODO don't give the user ID like this // TODO change pagination $entries = $repository->findArchiveByUser(1, 0); @@ -98,7 +98,7 @@ class EntryController extends Controller */ public function showStarredAction() { - $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries'); + $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); // TODO don't give the user ID like this // TODO change pagination $entries = $repository->findStarredByUser(1, 0); @@ -112,11 +112,11 @@ class EntryController extends Controller /** * Shows entry content * - * @param Entries $entry + * @param Entry $entry * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view") * @return \Symfony\Component\HttpFoundation\Response */ - public function viewAction(Entries $entry) + public function viewAction(Entry $entry) { return $this->render( 'WallabagCoreBundle:Entry:entry.html.twig', @@ -128,11 +128,11 @@ class EntryController extends Controller * Changes read status for an entry * * @param Request $request - * @param Entries $entry + * @param Entry $entry * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function toggleArchiveAction(Request $request, Entries $entry) + public function toggleArchiveAction(Request $request, Entry $entry) { $entry->toggleArchive(); $this->getDoctrine()->getManager()->flush(); @@ -149,11 +149,11 @@ class EntryController extends Controller * Changes favorite status for an entry * * @param Request $request - * @param Entries $entry + * @param Entry $entry * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function toggleStarAction(Request $request, Entries $entry) + public function toggleStarAction(Request $request, Entry $entry) { $entry->toggleStar(); $this->getDoctrine()->getManager()->flush(); @@ -170,11 +170,11 @@ class EntryController extends Controller * Deletes entry * * @param Request $request - * @param Entries $entry + * @param Entry $entry * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry") * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function deleteEntryAction(Request $request, Entries $entry) + public function deleteEntryAction(Request $request, Entry $entry) { $em = $this->getDoctrine()->getManager(); $entry->setDeleted(1); diff --git a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php index 75de58f7..1df18247 100644 --- a/src/Wallabag/CoreBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/CoreBundle/Controller/WallabagRestController.php @@ -6,7 +6,7 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Wallabag\CoreBundle\Entity\Entries; +use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tags; use Wallabag\CoreBundle\Service\Extractor; @@ -27,7 +27,7 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="api%2Crest", "description"="a list of tags url encoded. Will returns entries that matches ALL tags."}, * } * ) - * @return Entries + * @return Entry */ public function getEntriesAction(Request $request) { @@ -42,7 +42,7 @@ class WallabagRestController extends Controller $entries = $this ->getDoctrine() - ->getRepository('WallabagCoreBundle:Entries') + ->getRepository('WallabagCoreBundle:Entry') ->findEntries(1, $isArchived, $isStarred, $isDeleted, $sort, $order); if (!is_array($entries)) { @@ -60,9 +60,9 @@ class WallabagRestController extends Controller * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) - * @return Entries + * @return Entry */ - public function getEntryAction(Entries $entry) + public function getEntryAction(Entry $entry) { return $entry; } @@ -77,6 +77,7 @@ class WallabagRestController extends Controller * {"name"="tags", "dataType"="string", "required"=false, "format"="tag1,tag2,tag3", "description"="a comma-separated list of tags."}, * } * ) + * @return Entry */ public function postEntriesAction(Request $request) { @@ -84,7 +85,7 @@ class WallabagRestController extends Controller $url = $request->request->get('url'); $content = Extractor::extract($url); - $entry = new Entries(); + $entry = new Entry(); $entry->setUserId(1); $entry->setUrl($url); $entry->setTitle($request->request->get('title') ?: $content->getTitle()); @@ -111,8 +112,9 @@ class WallabagRestController extends Controller * {"name"="delete", "dataType"="boolean", "required"=false, "format"="true or false", "description"="flag as deleted. Default false. In case that you don't want to *really* remove it.."}, * } * ) + * @return Entry */ - public function patchEntriesAction(Entries $entry, Request $request) + public function patchEntriesAction(Entry $entry, Request $request) { $title = $request->request->get("title"); $tags = $request->request->get("tags", array()); @@ -150,8 +152,9 @@ class WallabagRestController extends Controller * {"name"="entry", "dataType"="integer", "requirement"="\w+", "description"="The entry ID"} * } * ) + * @return Entry */ - public function deleteEntriesAction(Entries $entry) + public function deleteEntriesAction(Entry $entry) { if ($entry->isDeleted()) { throw new NotFoundHttpException('This entry is already deleted'); @@ -173,7 +176,7 @@ class WallabagRestController extends Controller * } * ) */ - public function getEntriesTagsAction(Entries $entry) + public function getEntriesTagsAction(Entry $entry) { } @@ -189,7 +192,7 @@ class WallabagRestController extends Controller * } * ) */ - public function postEntriesTagsAction(Entries $entry) + public function postEntriesTagsAction(Entry $entry) { } @@ -203,7 +206,7 @@ class WallabagRestController extends Controller * } * ) */ - public function deleteEntriesTagsAction(Entries $entry, Tags $tag) + public function deleteEntriesTagsAction(Entry $entry, Tags $tag) { } diff --git a/src/Wallabag/CoreBundle/Entity/Entries.php b/src/Wallabag/CoreBundle/Entity/Entries.php deleted file mode 100644 index f06a2940..00000000 --- a/src/Wallabag/CoreBundle/Entity/Entries.php +++ /dev/null @@ -1,417 +0,0 @@ -id; - } - - /** - * Set title - * - * @param string $title - * @return Entries - */ - public function setTitle($title) - { - $this->title = $title; - - return $this; - } - - /** - * Get title - * - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * Set url - * - * @param string $url - * @return Entries - */ - public function setUrl($url) - { - $this->url = $url; - - return $this; - } - - /** - * Get url - * - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * Set isArchived - * - * @param string $isArchived - * @return Entries - */ - public function setArchived($isArchived) - { - $this->isArchived = $isArchived; - - return $this; - } - - /** - * Get isArchived - * - * @return string - */ - public function isArchived() - { - return $this->isArchived; - } - - public function toggleArchive() - { - $this->isArchived = $this->isArchived() ^ 1; - - return $this; - } - - /** - * Set isStarred - * - * @param string $isStarred - * @return Entries - */ - public function setStarred($isStarred) - { - $this->isStarred = $isStarred; - - return $this; - } - - /** - * Get isStarred - * - * @return string - */ - public function isStarred() - { - return $this->isStarred; - } - - public function toggleStar() - { - $this->isStarred = $this->isStarred() ^ 1; - - return $this; - } - - /** - * Set content - * - * @param string $content - * @return Entries - */ - public function setContent($content) - { - $this->content = $content; - - return $this; - } - - /** - * Get content - * - * @return string - */ - public function getContent() - { - return $this->content; - } - - /** - * Set userId - * - * @param string $userId - * @return Entries - */ - public function setUserId($userId) - { - $this->userId = $userId; - - return $this; - } - - /** - * Get userId - * - * @return string - */ - public function getUserId() - { - return $this->userId; - } - - /** - * @return string - */ - public function isDeleted() - { - return $this->isDeleted; - } - - /** - * @param string $isDeleted - */ - public function setDeleted($isDeleted) - { - $this->isDeleted = $isDeleted; - } - - /** - * @return mixed - */ - public function getCreatedAt() - { - return $this->createdAt; - } - - /** - * @param mixed $createdAt - * @ORM\PrePersist - */ - public function setCreatedAt() - { - $this->createdAt = new \DateTime(); - } - - /** - * @return string - */ - public function getUpdatedAt() - { - return $this->updatedAt; - } - - /** - * @param string $updatedAt - * @ORM\PreUpdate - */ - public function setUpdatedAt() - { - $this->updatedAt = new \DateTime(); - } - - /** - * @return string - */ - public function getComments() - { - return $this->comments; - } - - /** - * @param string $comments - */ - public function setComments($comments) - { - $this->comments = $comments; - } - - /** - * @return string - */ - public function getMimetype() - { - return $this->mimetype; - } - - /** - * @param string $mimetype - */ - public function setMimetype($mimetype) - { - $this->mimetype = $mimetype; - } - - /** - * @return int - */ - public function getReadingTime() - { - return $this->readingTime; - } - - /** - * @param int $readingTime - */ - public function setReadingTime($readingTime) - { - $this->readingTime = $readingTime; - } - - /** - * @return string - */ - public function getDomainName() - { - return $this->domainName; - } - - /** - * @param string $domainName - */ - public function setDomainName($domainName) - { - $this->domainName = $domainName; - } - - /** - * @return boolean - */ - public function isPublic() - { - return $this->isPublic; - } - - /** - * @param boolean $isPublic - */ - public function setPublic($isPublic) - { - $this->isPublic = $isPublic; - } -} diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php new file mode 100644 index 00000000..70c1dc08 --- /dev/null +++ b/src/Wallabag/CoreBundle/Entity/Entry.php @@ -0,0 +1,412 @@ +id; + } + + /** + * Set title + * + * @param string $title + * @return Entry + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Set url + * + * @param string $url + * @return Entry + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * Get url + * + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * Set isArchived + * + * @param string $isArchived + * @return Entry + */ + public function setArchived($isArchived) + { + $this->isArchived = $isArchived; + + return $this; + } + + /** + * Get isArchived + * + * @return string + */ + public function isArchived() + { + return $this->isArchived; + } + + public function toggleArchive() + { + $this->isArchived = $this->isArchived() ^ 1; + + return $this; + } + + /** + * Set isStarred + * + * @param string $isStarred + * @return Entry + */ + public function setStarred($isStarred) + { + $this->isStarred = $isStarred; + + return $this; + } + + /** + * Get isStarred + * + * @return string + */ + public function isStarred() + { + return $this->isStarred; + } + + public function toggleStar() + { + $this->isStarred = $this->isStarred() ^ 1; + + return $this; + } + + /** + * Set content + * + * @param string $content + * @return Entry + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * Get content + * + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Set userId + * + * @param string $userId + * @return Entry + */ + public function setUserId($userId) + { + $this->userId = $userId; + + return $this; + } + + /** + * Get userId + * + * @return string + */ + public function getUserId() + { + return $this->userId; + } + + /** + * @return string + */ + public function isDeleted() + { + return $this->isDeleted; + } + + /** + * @param string $isDeleted + */ + public function setDeleted($isDeleted) + { + $this->isDeleted = $isDeleted; + } + + /** + * @return mixed + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * @return string + */ + public function getUpdatedAt() + { + return $this->updatedAt; + } + + /** + * @ORM\PrePersist + * @ORM\PreUpdate + */ + public function timestamps() + { + if (is_null($this->createdAt)) { + $this->createdAt = new \DateTime(); + } + + $this->updatedAt = new \DateTime(); + } + + /** + * @return string + */ + public function getComments() + { + return $this->comments; + } + + /** + * @param string $comments + */ + public function setComments($comments) + { + $this->comments = $comments; + } + + /** + * @return string + */ + public function getMimetype() + { + return $this->mimetype; + } + + /** + * @param string $mimetype + */ + public function setMimetype($mimetype) + { + $this->mimetype = $mimetype; + } + + /** + * @return int + */ + public function getReadingTime() + { + return $this->readingTime; + } + + /** + * @param int $readingTime + */ + public function setReadingTime($readingTime) + { + $this->readingTime = $readingTime; + } + + /** + * @return string + */ + public function getDomainName() + { + return $this->domainName; + } + + /** + * @param string $domainName + */ + public function setDomainName($domainName) + { + $this->domainName = $domainName; + } + + /** + * @return boolean + */ + public function isPublic() + { + return $this->isPublic; + } + + /** + * @param boolean $isPublic + */ + public function setPublic($isPublic) + { + $this->isPublic = $isPublic; + } +} diff --git a/src/Wallabag/CoreBundle/Helper/Entries.php b/src/Wallabag/CoreBundle/Helper/Entries.php deleted file mode 100644 index 6eeca4ff..00000000 --- a/src/Wallabag/CoreBundle/Helper/Entries.php +++ /dev/null @@ -1,7 +0,0 @@ -createQueryBuilder('e') - ->select('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) - ->where('e.isArchived = false') - ->andWhere('e.userId =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') - ->orderBy('e.createdAt', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); - - return $paginator; - } - - /** - * Retrieves read entries for a user - * - * @param $userId - * @param $firstResult - * @param int $maxResults - * @return Paginator - */ - public function findArchiveByUser($userId, $firstResult, $maxResults = 12) - { - $qb = $this->createQueryBuilder('e') - ->select('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) - ->where('e.isArchived = true') - ->andWhere('e.userId =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') - ->orderBy('e.createdAt', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); - - return $paginator; - } - - /** - * Retrieves starred entries for a user - * - * @param $userId - * @param $firstResult - * @param int $maxResults - * @return Paginator - */ - public function findStarredByUser($userId, $firstResult, $maxResults = 12) - { - $qb = $this->createQueryBuilder('e') - ->select('e') - ->setFirstResult($firstResult) - ->setMaxResults($maxResults) - ->where('e.isStarred = true') - ->andWhere('e.userId =:userId')->setParameter('userId', $userId) - ->andWhere('e.isDeleted=false') - ->orderBy('e.createdAt', 'desc') - ->getQuery(); - - $paginator = new Paginator($qb); - - return $paginator; - } - - public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) - { - $qb = $this->createQueryBuilder('e') - ->select('e') - ->where('e.userId =:userId')->setParameter('userId', $userId); - - if (!is_null($isArchived)) { - $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', $isArchived); - } - - if (!is_null($isStarred)) { - $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', $isStarred); - } - - if (!is_null($isDeleted)) { - $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted); - } - - if ('created' === $sort) { - $qb->orderBy('e.createdAt', $order); - } elseif ('updated' === $sort) { - $qb->orderBy('e.updatedAt', $order); - } - - return $qb - ->getQuery() - ->getResult(Query::HYDRATE_ARRAY); - } -} diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php new file mode 100644 index 00000000..f4c803f9 --- /dev/null +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -0,0 +1,114 @@ +createQueryBuilder('e') + ->select('e') + ->setFirstResult($firstResult) + ->setMaxResults($maxResults) + ->where('e.isArchived = false') + ->andWhere('e.userId =:userId')->setParameter('userId', $userId) + ->andWhere('e.isDeleted=false') + ->orderBy('e.createdAt', 'desc') + ->getQuery(); + + $paginator = new Paginator($qb); + + return $paginator; + } + + /** + * Retrieves read entries for a user + * + * @param $userId + * @param $firstResult + * @param int $maxResults + * @return Paginator + */ + public function findArchiveByUser($userId, $firstResult, $maxResults = 12) + { + $qb = $this->createQueryBuilder('e') + ->select('e') + ->setFirstResult($firstResult) + ->setMaxResults($maxResults) + ->where('e.isArchived = true') + ->andWhere('e.userId =:userId')->setParameter('userId', $userId) + ->andWhere('e.isDeleted=false') + ->orderBy('e.createdAt', 'desc') + ->getQuery(); + + $paginator = new Paginator($qb); + + return $paginator; + } + + /** + * Retrieves starred entries for a user + * + * @param $userId + * @param $firstResult + * @param int $maxResults + * @return Paginator + */ + public function findStarredByUser($userId, $firstResult, $maxResults = 12) + { + $qb = $this->createQueryBuilder('e') + ->select('e') + ->setFirstResult($firstResult) + ->setMaxResults($maxResults) + ->where('e.isStarred = true') + ->andWhere('e.userId =:userId')->setParameter('userId', $userId) + ->andWhere('e.isDeleted=false') + ->orderBy('e.createdAt', 'desc') + ->getQuery(); + + $paginator = new Paginator($qb); + + return $paginator; + } + + public function findEntries($userId, $isArchived, $isStarred, $isDeleted, $sort, $order) + { + $qb = $this->createQueryBuilder('e') + ->select('e') + ->where('e.userId =:userId')->setParameter('userId', $userId); + + if (!is_null($isArchived)) { + $qb->andWhere('e.isArchived =:isArchived')->setParameter('isArchived', $isArchived); + } + + if (!is_null($isStarred)) { + $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', $isStarred); + } + + if (!is_null($isDeleted)) { + $qb->andWhere('e.isDeleted =:isDeleted')->setParameter('isDeleted', $isDeleted); + } + + if ('created' === $sort) { + $qb->orderBy('e.createdAt', $order); + } elseif ('updated' === $sort) { + $qb->orderBy('e.updatedAt', $order); + } + + return $qb + ->getQuery() + ->getResult(Query::HYDRATE_ARRAY); + } +} -- cgit v1.2.3