public function index()
 {
     $page = 1;
     if ($this->GetData('page')) {
         $page = $this->GetData('page');
     }
     $achievements = UserAchievement::paginate("", "user_achievements.created_at DESC", $page, 25);
     $this->assign("achievements", $achievements);
     $this->title = "Achievements";
     $this->render("userachievement/index.tpl");
 }
예제 #2
0
 public function achievements($nickname = null)
 {
     $user = $this->load_user($nickname);
     $page = 1;
     if ($this->GetData('page')) {
         $page = $this->GetData('page');
     }
     $id = mysql_real_escape_string($user->id);
     $achievements = UserAchievement::paginate("users.id = '{$id}'", "", $page, 20);
     $this->assign("user", $user);
     $this->assign("page", $achievements);
     $this->title = "{$user->nickname} :: Achievements";
     $this->render("user/achievements.tpl");
 }
<?php

require "init.php";
$script = Script::find_by_code('loyalty_achievements');
$script->start();
ob_start();
$time = date("H:i:s");
echo "[{$time}] Achievement Loyalty Points\r\n\r\n";
$page = UserAchievement::paginate("user_achievements.processed = 0", "user_achievements.created_at ASC", 1, 50);
$count = count($page->collection);
echo "    Processing {$count} / {$page->total} achievements\r\n";
foreach ($page->collection as $obj) {
    mysql_query('BEGIN');
    $loyalty = true;
    if ($obj->achievement->points_value > 0) {
        $loyalty = $obj->user->award_loyalty($obj->achievement->points_value, "Achievement: {$obj->achievement->name}");
        $script->addlog("Awarded {$obj->achievement->points_value}pts to [{$obj->user}] {$obj->user->nickname} for [{$obj->achievement}] {$obj->achievement->name}");
    }
    $obj->processed = true;
    $ua = $obj->save();
    if ($loyalty && $ua) {
        mysql_query('COMMIT');
    } else {
        echo "Error processing [{$obj}]\r\n";
        print_r($obj);
        mysql_query('ROLLBACK');
        $script->addlog("Error processing [{$obj}]", 'Critical');
        print_r($obj->errors);
        print_r($obj->errors[0]);
        if (count($obj->errors) > 0 && $obj->errors[0] == 'User has already been awarded that achievement') {
            $obj->processed = true;