extendable user stats rather than hardcoded with assumptions of extensions

This commit is contained in:
Shish
2009-08-18 22:30:52 +01:00
parent f058d5dd5b
commit b1bcb8252f
8 changed files with 79 additions and 33 deletions

View File

@ -57,6 +57,14 @@ class Favorites extends SimpleExtension {
}
}
public function onUserPageBuilding($event) {
$i_favorites_count = Image::count_images(array("favorited_by={$event->display_user->name}"));
$i_days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1;
$h_favorites_rate = sprintf("%.1f", ($i_favorites_count / $i_days_old));
$favorites_link = make_link("post/list/favorited_by={$event->display_user->name}/1");
$event->add_stats("<a href='$favorites_link'>Images favorited</a>: $i_favorites_count, $h_favorites_rate per day");
}
public function onImageInfoSet($event) {
global $user;
if(($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) {

View File

@ -15,6 +15,11 @@ class FavoritesTest extends ShimmieWebTestCase {
$this->assertTitle("Image $image_id: test");
$this->assertText("Favorited By");
$this->get_page("user/test");
$this->assertText("Images favorited: 1");
$this->click("Images favorited");
$this->assertTitle("Image $image_id: test");
$this->click("Un-Favorite");
$this->assertNoText("Favorited By");