Beispiel #1
0
function wp_ulike_mailing_level($level)
{
    global $wp_ulike_class;
    $threshold = wp_ulike_get_setting("wp_ulike_mailing_level_{$level}", 'top_users_threshold');
    $step = wp_ulike_get_setting('wp_ulike_mailing_level_3', 'top_users_threshold_step');
    // Шаг для уровней выше 3
    // Определяем предел данного уровня
    if ($level < 3) {
        // Предел уровня - начало следующего
        $cutoff = wp_ulike_get_setting('wp_ulike_mailing_level_' . ($level + 1), 'top_users_threshold');
    } else {
        // Уровень 3 и выше - предел получаем добавляя шаг уровня
        $cutoff = $threshold + $step;
    }
    if ($threshold) {
        $top_users = $wp_ulike_class->get_users_we_should_prize($threshold, $cutoff, $level);
    } else {
        return;
    }
    if ($top_users) {
        // Есть кого уведомлять на этом уровне
        while (list($i, $top_user) = each($top_users)) {
            wp_ulike_prize_user($top_user->user_id, $top_user->score, $level);
        }
    }
}
Beispiel #2
0
 public function should_prize_user($user_id)
 {
     $score = $this->get_user_score($user_id);
     if (!$score) {
         return;
     }
     $score = (int) $score;
     // Набран 1 уровень
     $t1 = wp_ulike_get_setting("wp_ulike_mailing_level_1", 'top_users_threshold');
     $t2 = wp_ulike_get_setting("wp_ulike_mailing_level_2", 'top_users_threshold');
     if ($score >= $t1 && $score < $t2 && !$this->user_prized($user_id, 1)) {
         wp_ulike_prize_user($user_id, $score, 1);
         return;
     }
     // Набран 2 уровень
     $t3 = wp_ulike_get_setting("wp_ulike_mailing_level_3", 'top_users_threshold');
     if ($score >= $t2 && $score < $t3 && !$this->user_prized($user_id, 2)) {
         wp_ulike_prize_user($user_id, $score, 2);
         return;
     }
     // Набран 3 уровень
     $step = wp_ulike_get_setting('wp_ulike_mailing_level_3', 'top_users_threshold_step');
     // Шаг для уровней выше 3
     if (!$step) {
         $step = 10;
     }
     if ($score >= $t3 && $score < $t3 + $step && !$this->user_prized($user_id, 3)) {
         wp_ulike_prize_user($user_id, $score, 3);
         return;
     }
     // Уровни выше 3
     $level = floor(($score - $t3) / $step) + 3;
     // Вычисляем номер уровня
     if ($level > 3 && !$this->user_prized($user_id, $level)) {
         wp_ulike_prize_user($user_id, $score, $level);
     }
 }