more features, more todos
git-svn-id: file:///home/shish/svn/shimmie2/trunk@529 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
0e937d4af0
commit
6344c8f3e2
@ -7,6 +7,16 @@
|
||||
* Description: Allow users to score images
|
||||
*/
|
||||
|
||||
class ScoreSetEvent extends Event {
|
||||
var $image_id, $user, $score;
|
||||
|
||||
public function ScoreSetEvent($image_id, $user, $score) {
|
||||
$this->image_id = $image_id;
|
||||
$this->user = $user;
|
||||
$this->score = $score;
|
||||
}
|
||||
}
|
||||
|
||||
class Score extends Extension {
|
||||
var $theme;
|
||||
|
||||
@ -31,20 +41,26 @@ class Score extends Extension {
|
||||
$i_image_id = int_escape($_POST['image_id']);
|
||||
|
||||
if($i_score >= -2 || $i_score <= 2) {
|
||||
$this->add_vote($i_image_id, $event->user->id, $i_score);
|
||||
send_event(new ScoreSetEvent($i_image_id, $event->user->id, $i_score));
|
||||
}
|
||||
|
||||
$event->page->set_mode("redirect");
|
||||
$event->page->set_redirect(make_link("post/view/$i_image_id"));
|
||||
}
|
||||
|
||||
if(is_a($event, 'ScoreSetEvent')) {
|
||||
$this->add_vote($event->image_id, $event->user->id, $event->score);
|
||||
}
|
||||
|
||||
if(is_a($event, 'DisplayingImageEvent')) {
|
||||
$this->theme->display_rater($event->page, $event->image->id, $event->image->score);
|
||||
// TODO: scorer vs voter
|
||||
$this->theme->display_scorer($event->page, $event->image->id, $event->image->score);
|
||||
}
|
||||
|
||||
if(is_a($event, 'SetupBuildingEvent')) {
|
||||
/*
|
||||
TODO: disable anon voting
|
||||
TODO: switch between average and sum modes
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,47 @@
|
||||
<?php
|
||||
|
||||
class ScoreTheme extends Themelet {
|
||||
public function display_rater($page, $image_id, $score) {
|
||||
public function display_scorer($page, $image_id, $score) {
|
||||
$i_image_id = int_escape($image_id);
|
||||
|
||||
$words = array();
|
||||
$words[-2] = "Delete";
|
||||
$words[-1] = "Bad";
|
||||
$words[ 0] = "Ok";
|
||||
$words[ 1] = "Good";
|
||||
$words[ 2] = "Favourite";
|
||||
$s_score = $words[$score];
|
||||
$html = "
|
||||
Current score is \"$s_score\"
|
||||
<br><form action='".make_link("score/set")."' method='POST'>
|
||||
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||
<input type='radio' name='score' value='-2' id='-2'><label for='-2'>Delete</label>
|
||||
<input type='radio' name='score' value='-1' id='-1'><label for='-1'>Bad</label>
|
||||
<input type='radio' name='score' value='0' id='0' ><label for='0' >Ok</label>
|
||||
<input type='radio' name='score' value='1' id='1' ><label for='1' >Good</label>
|
||||
<input type='radio' name='score' value='2' id='2' ><label for='2' >Favourite</label>
|
||||
<input type='submit' value='Vote' />
|
||||
</form>
|
||||
";
|
||||
$page->add_block(new Block(null, $html, "main", 7));
|
||||
}
|
||||
|
||||
public function display_voter($page, $image_id, $score) {
|
||||
$i_image_id = int_escape($image_id);
|
||||
$i_score = int_escape($score) / 2;
|
||||
|
||||
$html = "
|
||||
Current score is $i_score
|
||||
<br>
|
||||
<form action='".make_link("score/set")."' method='POST'>
|
||||
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||
<input type='radio' name='score' value='--2' id='-2'><label for='-2'>Delete</label>
|
||||
<input type='radio' name='score' value='-1' id='-1'><label for='-1'>Bad</label>
|
||||
<input type='radio' name='score' value='0' id='0'><label for='0'>Ok</label>
|
||||
<input type='radio' name='score' value='1' id='1'><label for='1'>Good</label>
|
||||
<input type='radio' name='score' value='2' id='2'><label for='2'>Awesome</label>
|
||||
<input type='submit' value='Vote' />
|
||||
<input type='hidden' name='score' value='-2'>
|
||||
<input type='submit' value='Vote Down' />
|
||||
</form>
|
||||
<form action='".make_link("score/set")."' method='POST'>
|
||||
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||
<input type='hidden' name='score' value='2'>
|
||||
<input type='submit' value='Vote Up' />
|
||||
</form>
|
||||
";
|
||||
$page->add_block(new Block(null, $html, "main", 7));
|
||||
|
Loading…
x
Reference in New Issue
Block a user