Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(tags/search): Fix search count and unique search tag redirect con…
Browse files Browse the repository at this point in the history
…dition
  • Loading branch information
Rhilip committed Jul 20, 2019
1 parent 91a2e33 commit a423577
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/controllers/TorrentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ public function actionTags()
['LIMIT :offset, :rows', 'params' => ['offset' => ($page - 1) * $limit, 'rows' => $limit]],
])->queryAll();

if (count($tags) == 1) { // If this search tag is unique, just redirect to search page
if (count($tags) == 1 && $tags[0]['tag'] == $search) { // If this search tag is unique and equal to the wanted, just redirect to search page
return app()->response->redirect('/torrents/search?tags=' . $search);
}

$tag_count = app()->pdo->createCommand('SELECT COUNT(`id`) FROM `tags`')->queryScalar(); // TODO use `site_status` tables to store those data
$tag_count = app()->pdo->createCommand([
['SELECT COUNT(tags.id) as `count` FROM tags'],
['WHERE `tags`.`tag` LIKE :tag', 'if' => !empty($search), 'params' => ['tag' => '%' . $search . '%']],
])->queryScalar();

return $this->render('torrents/tags', ['search' => $search, 'tags' => $tags, 'count' => $tag_count]);
}
Expand Down

0 comments on commit a423577

Please sign in to comment.