aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2019-05-21 11:18:19 +0200
committerGitHub <noreply@github.com>2019-05-21 11:18:19 +0200
commita2b5d67560341011e791b678422578ab8d6b1e3f (patch)
treebfe5a7d8f3d8cfbbe8131d8ee6ade29dfea88853 /src/Wallabag/CoreBundle/Repository
parentb8b37ccdea6b453aa228cb79755752b5738b98b9 (diff)
parent2c290747cb0d235392f6e5d22205a706c6474168 (diff)
downloadwallabag-a2b5d67560341011e791b678422578ab8d6b1e3f.tar.gz
wallabag-a2b5d67560341011e791b678422578ab8d6b1e3f.tar.zst
wallabag-a2b5d67560341011e791b678422578ab8d6b1e3f.zip
Merge pull request #3960 from wallabag/api-entries-2817
api/entries: add parameter detail to exclude or include content in response
Diffstat (limited to 'src/Wallabag/CoreBundle/Repository')
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index f5089729..3990932e 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -139,15 +139,30 @@ class EntryRepository extends EntityRepository
139 * @param string $order 139 * @param string $order
140 * @param int $since 140 * @param int $since
141 * @param string $tags 141 * @param string $tags
142 * @param string $detail 'metadata' or 'full'. Include content field if 'full'
143 *
144 * @todo Breaking change: replace default detail=full by detail=metadata in a future version
142 * 145 *
143 * @return Pagerfanta 146 * @return Pagerfanta
144 */ 147 */
145 public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '') 148 public function findEntries($userId, $isArchived = null, $isStarred = null, $isPublic = null, $sort = 'created', $order = 'asc', $since = 0, $tags = '', $detail = 'full')
146 { 149 {
150 if (!\in_array(strtolower($detail), ['full', 'metadata'], true)) {
151 throw new \Exception('Detail "' . $detail . '" parameter is wrong, allowed: full or metadata');
152 }
153
147 $qb = $this->createQueryBuilder('e') 154 $qb = $this->createQueryBuilder('e')
148 ->leftJoin('e.tags', 't') 155 ->leftJoin('e.tags', 't')
149 ->where('e.user = :userId')->setParameter('userId', $userId); 156 ->where('e.user = :userId')->setParameter('userId', $userId);
150 157
158 if ('metadata' === $detail) {
159 $fieldNames = $this->getClassMetadata()->getFieldNames();
160 $fields = array_filter($fieldNames, function ($k) {
161 return 'content' !== $k;
162 });
163 $qb->select(sprintf('partial e.{%s}', implode(',', $fields)));
164 }
165
151 if (null !== $isArchived) { 166 if (null !== $isArchived) {
152 $qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived); 167 $qb->andWhere('e.isArchived = :isArchived')->setParameter('isArchived', (bool) $isArchived);
153 } 168 }