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)) { if(preg_match("/^score(<|<=|=|>=|>)(\d+)$/", $event->term, $matches)) {
$cmp = $matches[1]; $cmp = $matches[1];
$score = $matches[2]; $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)) { if(preg_match("/^upvoted_by=(.*)$/", $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))); $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)));
} }
} }
} }

View File

@ -12,8 +12,16 @@ class NumericScoreTest extends ShimmieWebTestCase {
# FIXME: "remove vote" button? # FIXME: "remove vote" button?
# FIXME: test that up and down are hidden if already voted up or down # 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->get_page("post/list/score=1/1");
$this->assertTitle("Image $image_id: pbx"); $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_out();
$this->log_in_as_admin(); $this->log_in_as_admin();

View File

@ -26,6 +26,9 @@ class SearchTermParseEvent extends Event {
} }
} }
class SearchTermParseException extends SCoreException {
}
class PostListBuildingEvent extends Event { class PostListBuildingEvent extends Event {
var $search_terms = null; var $search_terms = null;