replace numeric_score 'favorite' with 'upvoted_by=name' (and add the same for downvote)
This commit is contained in:
parent
9aa54af90a
commit
28fd3e311f
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,16 @@ class NumericScoreTest extends ShimmieWebTestCase {
|
||||
# FIXME: "remove vote" button?
|
||||
# FIXME: test that up and down are hidden if already voted up or down
|
||||
|
||||
# test search by score
|
||||
$this->get_page("post/list/score=1/1");
|
||||
$this->assertTitle("Image $image_id: pbx");
|
||||
|
||||
# test search by vote
|
||||
$this->get_page("post/list/upvoted_by=demo/1");
|
||||
$this->assertTitle("Image $image_id: pbx");
|
||||
|
||||
$this->get_page("post/list/downvoted_by=demo/1");
|
||||
$this->assertTitle("Image $image_id: pbx");
|
||||
$this->log_out();
|
||||
|
||||
$this->log_in_as_admin();
|
||||
|
@ -26,6 +26,9 @@ class SearchTermParseEvent extends Event {
|
||||
}
|
||||
}
|
||||
|
||||
class SearchTermParseException extends SCoreException {
|
||||
}
|
||||
|
||||
class PostListBuildingEvent extends Event {
|
||||
var $search_terms = null;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user