示例#1
0
文件: panel.php 项目: Kuzat/kofradia
    /**
     * Statistikk over betalinger for driftskostnad
     */
    protected function page_paystats()
    {
        ess::$b->page->add_title("Statistikk over driftskostnad");
        // antall betalinger vi skal vise
        $limit = 15;
        $ff_reset = "";
        if ($this->ff->data['ff_time_reset'] && !$this->ff->mod) {
            $date = ess::$b->date->get($this->ff->data['ff_time_reset']);
            $ff_reset = " AND ffsp_date > '" . $date->format("Y-m-d") . "'";
        }
        // hent statistikk
        $result = \Kofradia\DB::get()->query("\n\t\t\tSELECT ffsp_id, ffsp_date, ffsp_manual, ffsp_points, ffsp_up_limit, ffsp_cost\n\t\t\tFROM ff_stats_pay\n\t\t\tWHERE ffsp_ff_id = {$this->ff->id}{$ff_reset}\n\t\t\tORDER BY ffsp_date\n\t\t\tLIMIT {$limit}");
        $periods = array();
        $ffsp_ids = array();
        while ($row = $result->fetch()) {
            $periods[] = $row;
            $ffsp_ids[] = $row['ffsp_id'];
        }
        $periode = array_reverse($periods);
        $ffsp_ids = implode(",", $ffsp_ids);
        // ingen statistikk?
        if (count($periods) == 0) {
            ess::$b->page->add_message("Det er ikke utført noen betalinger enda og ingen statistikk foreligger.", "error");
            redirect::handle();
        }
        $limit_data = $this->ff->members_limit_max_info();
        // sett opp liste for data
        $stats = array();
        $labels = array();
        $cost = array();
        $up_limit = array();
        $points_max = 0;
        // for å finne 100 %
        foreach ($periods as $row) {
            $stats[0][$row['ffsp_id']] = 0;
            $labels[] = $row['ffsp_date'];
            $cost[] = (int) round($row['ffsp_cost'] / 1000000);
            $up_limit[] = (int) $row['ffsp_up_limit'];
            foreach ($this->ff->members['members'] as $member) {
                $stats[$member->id][$row['ffsp_id']] = 0;
            }
        }
        foreach ($this->ff->members['members'] as $member) {
            $v = 0;
            if ($member->data['up_access_level'] < ess::$g['access_noplay']) {
                $v = $member->data['up_points_rel'] - $member->data['ffm_pay_points'];
            }
            $stats[$member->id][] = $v;
            $points_max = max($points_max, abs($v));
        }
        $pay_info = $this->ff->pay_info();
        $labels[] = "Inneværende periode";
        $cost[] = round($pay_info['price'] / 1000000);
        $up_limit[] = $limit_data['min'] + $limit_data['extra_max'];
        $stats[0][] = (int) $this->ff->data['ff_pay_points'];
        $points_max = max($points_max, abs($this->ff->data['ff_pay_points']));
        // hent inn statistikk over medlemmene
        $result = \Kofradia\DB::get()->query("\n\t\t\tSELECT ffspm_ffsp_id, ffspm_up_id, ffspm_points\n\t\t\tFROM ff_stats_pay_members\n\t\t\tWHERE ffspm_ffsp_id IN ({$ffsp_ids})");
        while ($row = $result->fetch()) {
            if (!isset($stats[$row['ffspm_up_id']][$row['ffspm_ffsp_id']])) {
                $stats[0][$row['ffspm_ffsp_id']] += $row['ffspm_points'];
                $points_max = max($points_max, abs($stats[0][$row['ffspm_ffsp_id']]));
            } else {
                $stats[$row['ffspm_up_id']][$row['ffspm_ffsp_id']] += $row['ffspm_points'];
                $points_max = max($points_max, abs($stats[$row['ffspm_up_id']][$row['ffspm_ffsp_id']]));
            }
        }
        // omregn til prosentverdier
        foreach ($stats as &$ffsp) {
            foreach ($ffsp as &$num) {
                $num = round($num / $points_max * 100, 2);
            }
        }
        unset($num);
        // sett opp data for rank
        $data_rank = array(array("Tidligere medlemmer", "Tidligere medlemmer: #val# %", array_values($stats[0]), OFC_Colours::$colours[0]));
        $i = 0;
        foreach ($this->ff->members['members'] as $member) {
            $data_rank[] = array($member->data['up_name'], "{$member->data['up_name']}: #val# %", array_values($stats[$member->id]), OFC_Colours::$colours[++$i % count(OFC_Colours::$colours)]);
        }
        // sett opp data for pengeflyt og medlemsbegrensning
        $data_flow = array(array("Driftskostnad", "Driftskostnad: #val# mill kr", $cost, OFC_Colours::$colours[0]), array("Medlemsbegrensning", "Medlemsbegrensning: #val#", $up_limit, OFC_Colours::$colours[1]));
        // sett opp diagrammer
        $elm_id_rank = $this->stats_ofc_build("pay_rank", $data_rank, $labels, 400);
        $elm_id_flow = $this->stats_ofc_build("pay_flow", $data_flow, $labels, 400);
        echo '
<div class="bg1_c">
	<h1 class="bg1">Statistikk over driftskostnad for ' . $this->ff->type['refobj'] . '<span class="left2"></span><span class="right2"></span></h1>
	<div class="bg1">
		<p>Denne siden viser hvor mye en spiller i ' . $this->ff->type['refobj'] . ' har ranket mellom hver driftsperiode. Statistikken gjelder for maksimalt 15 driftskostnader tilbake i tid, i tillegg til driftskostnaden så langt i nåværende periode.</p>
		<p class="c"><a href="panel?ff_id=' . $this->ff->id . '">Tilbake</a></p>
		<p>Rankutvikling:</p>
		<div style="margin: 10px 0"><div id="' . $elm_id_rank . '"></div></div>
		<p>Driftskostnad og medlemsbegrensning: <span class="dark">(Driftskostnaden er i millioner kr.)</span></p>
		<div style="margin: 10px 0"><div id="' . $elm_id_flow . '"></div></div>
		<p class="c"><a href="panel?ff_id=' . $this->ff->id . '">Tilbake</a></p>
	</div>
</div>';
        $this->ff->load_page();
    }