From 95b2eec461c4123ae8e620793cd711befa5b2cee Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 22 Nov 2013 11:15:38 +0100 Subject: [PATCH] Search queries: added search by likes/dislikes --- data/help.md | 1 + src/Models/Model_Post_QueryBuilder.php | 37 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/data/help.md b/data/help.md index c5ff7830..98d707ac 100644 --- a/data/help.md +++ b/data/help.md @@ -29,6 +29,7 @@ You can use your keyboard to navigate around the site. There are a few shortcuts - having specific ID: [search]id:1,2,3,8[/search] - having ID no less than specified value: [search]idmin:28[/search] - by content type: [search]type:img[/search], [search]type:swf[/search], [search]type:yt[/search] (images, flash files and YouTube videos, respectively) +- scored up/down by currently logged in user: [search]special:likes[/search] and [search]special:dislikes[/search] You can combine tags and negate any of them for interesting results. [search]sea -favmin:8 type:swf submit:Pirate[/search] will show you **flash files** tagged as **sea**, that were **liked by seven people** at most, uploaded by user **Pirate**. diff --git a/src/Models/Model_Post_QueryBuilder.php b/src/Models/Model_Post_QueryBuilder.php index 29a242b9..d4625b62 100644 --- a/src/Models/Model_Post_QueryBuilder.php +++ b/src/Models/Model_Post_QueryBuilder.php @@ -131,6 +131,43 @@ class Model_Post_QueryBuilder implements AbstractQueryBuilder $dbQuery->addSql('comment_count <= ?')->put(intval($val)); } + protected static function filterTokenSpecial($dbQuery, $val) + { + $context = \Chibi\Registry::getContext(); + + switch (strtolower($val)) + { + case 'liked': + case 'likes': + $dbQuery + ->exists() + ->open() + ->select('1') + ->from('postscore') + ->where('post_id = post.id') + ->and('score > 0') + ->and('user_id = ?')->put($context->user->id) + ->close(); + break; + + case 'disliked': + case 'dislikes': + $dbQuery + ->exists() + ->open() + ->select('1') + ->from('postscore') + ->where('post_id = post.id') + ->and('score < 0') + ->and('user_id = ?')->put($context->user->id) + ->close(); + break; + + default: + throw new SimpleException('Unknown special "' . $val . '"'); + } + } + protected static function filterTokenType($dbQuery, $val) { switch (strtolower($val))