replace numeric_score 'favorite' with 'upvoted_by=name' (and add the same for downvote)

This commit is contained in:
Shish
2009-08-13 19:26:23 +01:00
parent 9aa54af90a
commit 28fd3e311f
3 changed files with 31 additions and 3 deletions

View File

@ -69,10 +69,27 @@ class NumericScore implements Extension {
if(preg_match("/^score(<|<=|=|>=|>)(\d+)$/", $event->term, $matches)) {
$cmp = $matches[1];
$score = $matches[2];
$event->set_querylet(new Querylet("numeric_score $cmp $score"));
$event->add_querylet(new Querylet("numeric_score $cmp $score"));
}
if(preg_match("/^favou?rite$/", $event->term, $matches)) {
$event->set_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", array($user->id)));
if(preg_match("/^upvoted_by=(.*)$/", $event->term, $matches)) {
$duser = User::by_name($matches[1]);
if(is_null($duser)) {
throw new SearchTermParseException(
"Can't find the user named ".html_escape($matches[1]));
}
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)",
array($duser->id)));
}
if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) {
$duser = User::by_name($matches[1]);
if(is_null($duser)) {
throw new SearchTermParseException(
"Can't find the user named ".html_escape($matches[1]));
}
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)",
array($duser->id)));
}
}
}