Skip to content

Commit

Permalink
fixed filtering by topic
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Jan 20, 2015
1 parent 56ff91a commit 3fff3ef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
23 changes: 10 additions & 13 deletions newscoop/classes/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -2574,22 +2574,19 @@ public static function GetList(array $p_parameters, $p_order = null,
} elseif ($leftOperand == 'matchalltopics') {
// set the matchAllTopics flag
$matchAllTopics = true;
} elseif ($leftOperand == 'topic') {
} elseif ($leftOperand == 'topic' || $leftOperand == 'topic_strict') {
// add the topic to the list of match/do not match topics depending
// on the operator
$topic = new Topic($comparisonOperation['right']);
if ($topic->exists()) {
$topicIds = $topic->getSubtopics(true, 0);
$topicIds[] = $comparisonOperation['right'];
if ($comparisonOperation['symbol'] == '=') {
$hasTopics[] = $topicIds;
} else {
$hasNotTopics[] = $topicIds;
$em = Zend_Registry::get('container')->getService('em');
$request = Zend_Registry::get('container')->getService('request');
$repository = $em->getRepository('Newscoop\NewscoopBundle\Entity\Topic');
$topic = $repository->getTopicByIdOrName($comparisonOperation['right'], $request->getLocale())->getOneOrNullResult();
if ($topic) {
$topicIds = array();
foreach($topic->getChildren() as $child) {
$topicIds[] = $child->getId();
}
}
} elseif ($leftOperand == 'topic_strict') {
$topic = new Topic($comparisonOperation['right']);
if ($topic->exists()) {

$topicIds[] = $comparisonOperation['right'];
if ($comparisonOperation['symbol'] == '=') {
$hasTopics[] = $topicIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class TopicsController extends Controller
*/
public function getTopicsAction(Request $request)
{

$term = $request->query->get('term', '');
$limit = $request->query->get('limit', null);

if (trim($term) === '') {
return new JsonResponse(array());
}

$locale = $request->get('_code', $request->getLocale());
$topics = $this->container->get('em')
->getRepository('Newscoop\NewscoopBundle\Entity\Topic')
->searchTopics($term, array('title' => 'asc'), $limit)
->searchTopics($term, array('title' => 'asc'), $limit, $locale)
->getArrayResult();

return new JsonResponse($topics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function getArticlesQueryByTopicIdAndLanguage($topicId, $languageCode, $d
*
* @return Query
*/
public function searchTopics($query, $sort = array(), $limit = null)
public function searchTopics($query, $sort = array(), $limit = null, $locale = null)
{
$meta = $this->getClassMetadata();
$config = $this->listener->getConfiguration($this->_em, $meta->name);
Expand All @@ -244,7 +244,7 @@ public function searchTopics($query, $sort = array(), $limit = null)
$qb->setMaxResults($limit);
}

return $this->setTranslatableHint($qb->getQuery());
return $this->setTranslatableHint($qb->getQuery(), $locale);
}

/**
Expand Down

0 comments on commit 3fff3ef

Please sign in to comment.