Skip to content

Commit

Permalink
add support to filter articles by section in /articles api resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilles107 committed Dec 13, 2015
1 parent 1fd9944 commit 967b131
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ArticleRepository extends DatatableSource implements RepositoryInterface
*
* @return \Doctrine\ORM\Query
*/
public function getArticles($publication, $type = null, $language = null, $issue = null)
public function getArticles($publication, $type = null, $language = null, $issue = null, $section = null)
{
$em = $this->getEntityManager();

Expand Down Expand Up @@ -68,6 +68,14 @@ public function getArticles($publication, $type = null, $language = null, $issue
->setParameter('issue', $issue);
}

if ($section) {
$countQueryBuilder->andWhere('a.sectionId = :section')
->setParameter('section', $section);

$queryBuilder->andWhere('a.sectionId = :section')
->setParameter('section', $section);
}

if ($language) {
$languageId = $em->getRepository('Newscoop\Entity\Language')
->findOneByCode($language);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ private function postAddUpdate($article)
* parameters={
* {"name"="type", "dataType"="integer", "required"=true, "description"="Article type"},
* {"name"="language", "dataType"="string", "required"=false, "description"="Language code"},
* {"name"="issue", "dataType"="string", "required"=false, "description"="Issue number"}
* {"name"="issue", "dataType"="string", "required"=false, "description"="Issue number"},
* {"name"="section", "dataType"="string", "required"=false, "description"="Section number"}
* }
* )
*
Expand All @@ -218,7 +219,7 @@ public function getArticlesAction(Request $request)
$publication = $this->get('newscoop_newscoop.publication_service')->getPublication()->getId();

$articles = $em->getRepository('Newscoop\Entity\Article')
->getArticles($publication, $request->get('type', null), $request->get('language', null), $request->get('issue', null));
->getArticles($publication, $request->get('type', null), $request->get('language', null), $request->get('issue', null), $request->get('section', null));

$paginator = $this->get('newscoop.paginator.paginator_service');
$articles = $paginator->paginate($articles, array(
Expand Down

0 comments on commit 967b131

Please sign in to comment.