Example #1
0
function GetRating($type, $login = null, $width = null)
{
    session_start();
    $objResponse = new xajaxResponse();
    $login = change_q_x($login, TRUE);
    $user = new users();
    $user->GetUser($login);
    $uid = $user->uid;
    if (!$uid) {
        $uid = get_uid(false);
    }
    if (!$uid) {
        $objResponse->script('this.document.location.reload();');
        return $objResponse;
    }
    $user->GetUserByUID($uid);
    $rating = new rating();
    switch ($type) {
        case 'year':
            $TIME = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
            $pro_periods_date = date('Y-01-01', $TIME);
            $res = $rating->getRatingByYear($uid, date('Y', $TIME));
            $periods = rating::getMonthParts(date('Y-01-01'));
            $data = array();
            if ($res) {
                foreach ($periods as $m => $mm) {
                    if ($m < date('m')) {
                        foreach ($mm as $d) {
                            if ($d > time() || $d < strtotime($user->reg_date)) {
                                continue;
                            }
                            $data[$m][date('Y-m-d', $d)] = null;
                            if ($d >= strtotime($user->reg_date)) {
                                $data[$m][date('Y-m-d', $d)] = 0;
                            }
                        }
                    }
                }
            }
            $start_r = null;
            if ($res) {
                if (date('Y', strtotime($res[0]['_date'])) == date('Y') - 1) {
                    $start_r = $res[0]['rating'];
                    if (isset($res[1]) && strtotime($res[1]['_date']) != $periods[0][0]) {
                        $res[0]['_date'] = date('Y-m-d', $periods[0][0]);
                    } else {
                        $res = array_slice($res, 1);
                    }
                }
            } else {
                $res = array();
            }
            $verify_factor = 0;
            $verify_date = rating::GetVerifyDate($uid);
            foreach ($res as $row) {
                $t = strtotime($row['_date']);
                $m = (int) date('m', $t);
                $verify_factor = 0;
                if ($row['is_verify'] == 't') {
                    if ($verify_date) {
                        if (strtotime($verify_date) < $t) {
                            $verify_factor = 0.2;
                        }
                    } else {
                        $verify_factor = 0.2;
                    }
                }
                $data[$m - 1][date('Y-m-d', $t)] = array('rating' => floatval($row['rating']), 'verify' => floatval($row['rating'] * $verify_factor), 'pro' => 0);
            }
            $lastval = null;
            foreach ($data as $i => $mon) {
                foreach ($mon as $d => $prt) {
                    $vl = !$prt ? $lastval : $prt;
                    $data[$i][$d] = $vl;
                    //                    if($prt !== null)
                    $lastval = $vl;
                }
            }
            $pro_periods = promotion::GetUserProPeriods($uid, $pro_periods_date, TRUE);
            if ($pro_periods) {
                $pro = array();
                foreach ($pro_periods as $p => $period) {
                    if (date('Y', strtotime($period['from_time'])) > date('Y', $TIME) && date('Y', strtotime($period['to_time']) > date('Y', $TIME))) {
                        continue;
                    }
                    $d1 = (int) date('z', strtotime($period['from_time']));
                    $d2 = (int) date('z', strtotime($period['to_time']));
                    if (date('Y', strtotime($period['from_time'])) < date('Y', $TIME)) {
                        $d1 = 0;
                    }
                    if (date('Y', strtotime($period['to_time'])) > date('Y', $TIME)) {
                        $d2 = (int) date('z', mktime(0, 0, 0, 12, 31, date('Y')));
                    }
                    $_factor = 0.2;
                    if ($period['is_profi'] == 1) {
                        $_factor = 0.4;
                    }
                    foreach ($data as $mon => $val) {
                        foreach ($val as $per => $r) {
                            $day = (int) date('z', strtotime($per));
                            if ($d1 < $day && $d2 >= $day) {
                                $data[$mon][$per]['pro'] = floatval($data[$mon][$per]['rating'] * $_factor);
                            }
                        }
                    }
                    $pro[$p] = $d1 != $d2 ? array($d1, $d2) : array($d1);
                }
                $config['pro'] = $pro;
            }
            $new_data = array();
            if ($data) {
                foreach ($data as $mon => $val) {
                    foreach ($val as $per => $r) {
                        $new_data[$mon][$per] = $r['rating'] + $r['verify'] + $r['pro'];
                    }
                }
            }
            $config['data'] = $new_data;
            $config['cur'] = intval(date('m', $TIME));
            $config['days'] = date('z', mktime(0, 0, 0, 12, 31, date('Y'))) + 1;
            $config['regdate'] = $user->reg_date;
            break;
        case 'prev':
        default:
            $config = array();
            $data = array();
            $config['hilight'] = array();
            if ($type == 'prev') {
                $TIME = mktime(0, 0, 0, date('m') - 1, 1, date('Y'));
                $res = $rating->getRatingByMonth($uid, date('Y-m-d', $TIME));
                if (!$res) {
                    $res = array();
                }
                $graphstart = strtotime($user->reg_date);
                if (count($res) && date('Ym', strtotime($res[0]['_date'])) == date('Ym', $TIME)) {
                    $graphstart = strtotime($res[0]['_date']);
                } else {
                    if (!count($res)) {
                        $graphstart = time();
                    }
                }
                $rating_data = array();
                $verify_date = null;
                $verify_factor = 0;
                $n = 0;
                foreach ($res as $d) {
                    if (date('Y-m', strtotime($d['_date'])) != date('Y-m', $TIME)) {
                        continue;
                    }
                    //$rating_data[intval(date('d', strtotime($d['_date'])))] = $d['rating'];
                    $verify_factor = 0;
                    if ($verify_date === null) {
                        $verify_date = rating::GetVerifyDate($d['user_id']);
                    }
                    if ($d['is_verify'] == 't') {
                        if ($verify_date) {
                            if (strtotime($verify_date) < strtotime($d['_date'])) {
                                $verify_factor = 0.2;
                            }
                        } else {
                            $verify_factor = 0.2;
                        }
                    }
                    if ($n == 0) {
                        $res[0]['verify_factor'] = $verify_factor;
                    }
                    $rating_data[intval(date('d', strtotime($d['_date'])))] = array('rating' => floatval($d['rating']), 'verify' => floatval($d['rating'] * $verify_factor), 'pro' => 0);
                    ++$n;
                }
                $last = null;
                for ($i = 0; $i < date('t', $TIME); ++$i) {
                    if (strtotime(date('Y-m-' . ($i + 1), $TIME)) < $graphstart) {
                        $last = null;
                    } else {
                        $last = $last !== null ? $last : 0;
                        if ($i == 0 && !isset($rating_data[$i + 1])) {
                            $last = array('rating' => floatval($res[0]['rating']), 'verify' => floatval($res[0]['rating'] * $res[0]['verify_factor']), 'pro' => 0);
                        }
                    }
                    if (isset($rating_data[$i + 1])) {
                        $last = $rating_data[$i + 1];
                    }
                    $data[$i] = $last;
                }
            } else {
                $TIME = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
                $res = $rating->getRatingByMonth($uid, date('Y-m-d', $TIME));
                if (!$res) {
                    $res = array();
                }
                $graphstart = strtotime($user->reg_date);
                if (count($res) && date('Ym', strtotime($res[0]['_date'])) == date('Ym', $TIME)) {
                    $graphstart = strtotime($res[0]['_date']);
                }
                $rating_data = array();
                $verify_date = null;
                $verify_factor = 0;
                $n = 0;
                foreach ($res as $d) {
                    if (date('Y-m', strtotime($d['_date'])) != date('Y-m', $TIME)) {
                        continue;
                    }
                    $verify_factor = 0;
                    if ($verify_date === null) {
                        $verify_date = rating::GetVerifyDate($d['user_id']);
                    }
                    if ($d['is_verify'] == 't') {
                        if ($verify_date) {
                            if (strtotime($verify_date) < strtotime($d['_date'])) {
                                $verify_factor = 0.2;
                            }
                        } else {
                            $verify_factor = 0.2;
                        }
                    }
                    if ($n == 0) {
                        $res[0]['verify_factor'] = $verify_factor;
                    }
                    $rating_data[intval(date('d', strtotime($d['_date'])))] = array('rating' => floatval($d['rating']), 'verify' => floatval($d['rating'] * $verify_factor), 'pro' => 0);
                    ++$n;
                }
                $config['cur'] = intval(date('d', $TIME));
                $last = 0;
                for ($i = 0; $i < date('d', $TIME); ++$i) {
                    if (strtotime(date('Y-m-' . ($i + 1), $TIME)) < $graphstart) {
                        $last = null;
                    } else {
                        $last = $last !== null ? $last : 0;
                        if ($i == 0 && !isset($rating_data[$i + 1])) {
                            $last = array('rating' => floatval($res[0]['rating']), 'verify' => floatval($res[0]['rating'] * $res[0]['verify_factor']), 'pro' => 0);
                        }
                    }
                    if (isset($rating_data[$i + 1])) {
                        $last = $rating_data[$i + 1];
                    }
                    $data[$i] = $last;
                }
            }
            $pro_periods_date = date('Y-01-01', $TIME);
            for ($i = 1; $i <= date('t', $TIME); ++$i) {
                $t = mktime(0, 0, 0, date('m', $TIME), $i, date('Y', $TIME));
                if (date('w', $t) == 0 || date('w', $t) == 6) {
                    $config['hilight'][] = $i;
                }
            }
            $pro_periods = promotion::GetUserProPeriods($uid, $pro_periods_date, TRUE);
            if ($pro_periods) {
                $pro = array();
                $tmp = array();
                foreach ($pro_periods as $p => $period) {
                    if (date('Ym', strtotime($period['from_time'])) > date('Ym', $TIME)) {
                        continue;
                    }
                    if (date('Ym', strtotime($period['to_time'])) < date('Ym', $TIME)) {
                        continue;
                    }
                    $d1 = (int) date('d', strtotime($period['from_time']));
                    $d2 = (int) date('d', strtotime($period['to_time']));
                    if (date('Ym', strtotime($period['from_time'])) < date('Ym', $TIME)) {
                        $d1 = 1;
                    }
                    if (date('Ym', strtotime($period['to_time'])) > date('Ym', $TIME)) {
                        $d2 = (int) date('t', $TIME);
                    }
                    $_factor = 0.2;
                    //PRO ONLY
                    if ($period['is_profi'] == 1) {
                        $_factor = 0.4;
                        //PROFI
                    }
                    foreach ($data as $day => $val) {
                        if (isset($tmp[$day]) || $val === null) {
                            continue;
                        }
                        if ($d1 <= $day + 1 && $d2 >= $day + 1) {
                            $data[$day]['pro'] = floatval($data[$day]['rating'] * $_factor);
                            //rating::PRO_FACTOR;
                            $tmp[$day] = 1;
                        }
                    }
                    $pro[$p] = $d1 != $d2 ? array($d1, $d2) : array($d1);
                }
                $config['pro'] = $pro;
            }
            if (strtotime($user->reg_date) > strtotime($pro_periods_date)) {
                $config['regdate'] = date('Y-m-d', strtotime($user->reg_date));
            }
            $new_data = array();
            if ($data) {
                foreach ($data as $day => $value) {
                    $new_data[$day] = $value['rating'] + $value['verify'] + $value['pro'];
                }
            }
            // сегодняшний рейтинг берем из $user - тут он актуальный и не зависит от кэша
            if ($type === 'month') {
                array_pop($new_data);
                $new_data[] = floatval($user->rating);
            }
            $config['data'] = $new_data;
            $config['days'] = date('t', $TIME);
            $config['startdate'] = date('Y-m-01', $TIME);
    }
    if ($width) {
        $config['w'] = (int) $width;
    }
    $config = json_encode($config);
    $objResponse->script("loadGraph('{$type}', {$config});");
    return $objResponse;
}
Example #2
0
$u_today['from_t'] = $u_today['by_e_from_t'] + $u_today['by_f_from_t'] + $u_today['by_u_from_t'];
$u_today['from_o'] = $u_today['by_e_from_o'] + $u_today['by_f_from_o'] + $u_today['by_u_from_o'];
$u_today['from_s'] = $u_today['by_e_from_s'] + $u_today['by_f_from_s'] + $u_today['by_u_from_s'];
if ($u_today['from_a'] > $cur_month_max_h) {
    $cur_month_max_h = $u_today['from_a'];
}
if ($u_today['from_a'] > $cur_year_max_h) {
    $cur_year_max_h = $u_today['from_a'];
}
$u_month_sum['by_a'] = $u_today['from_a'];
$u_month_sum['by_e'] = $u_today['by_e'];
$u_month_sum['by_f'] = $u_today['by_f'];
$u_month_sum['by_u'] = $u_today['by_u'];
$u_last30 = array('from_c' => $u_summary['by_e_from_c_30d'] + $u_summary['by_f_from_c_30d'] + $u_summary['by_u_from_c_30d'], 'from_b' => $u_summary['by_e_from_b_30d'] + $u_summary['by_f_from_b_30d'] + $u_summary['by_u_from_b_30d'], 'from_p' => $u_summary['by_e_from_p_30d'] + $u_summary['by_f_from_p_30d'] + $u_summary['by_u_from_p_30d'], 'from_t' => $u_summary['by_e_from_t_30d'] + $u_summary['by_f_from_t_30d'] + $u_summary['by_u_from_t_30d'], 'from_o' => $u_summary['by_e_from_o_30d'] + $u_summary['by_f_from_o_30d'] + $u_summary['by_u_from_o_30d'], 'from_s' => $u_summary['by_e_from_s_30d'] + $u_summary['by_f_from_s_30d'] + $u_summary['by_u_from_s_30d'], 'from_a' => $u_summary['by_e_30d'] + $u_summary['by_f_30d'] + $u_summary['by_u_30d']);
// Находим параметры прогнозируемого параметра юзера.
if ($prm_is_PRO && ($y_prm_p = promotion::GetUserProPeriods($uid, $YEAR . '-01-01', TRUE)) || $prm_is_FP && ($y_prm_p = promotion::GetUserPsPeriods($uid, $YEAR . '-01-01')) || $prm_is_CTG && ($y_prm_p = promotion::GetUserPsPeriods($uid, $YEAR . '-01-01', -1, '<>'))) {
    // периоды в каталоге за год.
    // Вычисляем последний период использованный(зуемый) юзером, плюс склеиваем
    // смежные периоды в один отрезок (нужно для страницы прогнозов платных мест в каталоге).
    foreach ($y_prm_p as $pp) {
        $fday = substr($pp['from_time'], 0, 10);
        $tday = substr($pp['to_time'], 0, 10);
        $ltime = 0;
        if ($u_last_prm_period && ($ltime = strtotime($u_last_prm_period['to_day'])) >= strtotime($tday)) {
            continue;
        }
        if ($ltime >= strtotime($fday)) {
            $u_last_prm_period['to_day'] = $tday;
            $u_last_prm_period['to_time'] = $pp['to_time'];
        } else {
            if ($u_last_prm_period) {
Example #3
0
//        header('Content-type: image/svg+xml');
//    echo $svg;
//    exit();
$overwrite = true;
if (!$cfile->id || $overwrite) {
    if ($cfile->id) {
        $cfile->Delete($cfile->id);
    }
    $file2 = "/users/" . substr($u_login, 0, 2) . "/{$u_login}/upload/{$file_name}." . ($file_ext == 'svg' ? 'html' : 'svg');
    $cf2 = new CFile($file2);
    if ($cf2->id) {
        $cf2->Delete($cf2->id);
    }
    $data = $rating->{$get_rating_by}($uid, $get_rating_date);
    $graph = new $graph_class($TIME, $data);
    $graph->setPro(promotion::GetUserProPeriods($uid, $pro_periods_date));
    //    $graph->setPro(array(
    //        array(
    //            'from_time' => '2010-01-03',
    //            'to_time' => '2010-06-15'
    //        ),
    //        array(
    //            'from_time' => '2010-12-02',
    //            'to_time' => '2010-12-28'
    //        )
    //    ));
    $svg = $graph->render();
    $cfile = new CFile();
    $cfile->name = "{$file_name}.{$file_ext}";
    $cfile->path = "/users/" . substr($u_login, 0, 2) . "/{$u_login}/upload/";
    $cfile->modified = '';