Пример #1
0
function downloadText($text, $filename, $inline = false)
{
    global $Opt;
    $csvg = new CsvGenerator(CsvGenerator::TYPE_TAB);
    $csvg->download_headers($Opt["downloadPrefix"] . $filename . $csvg->extension(), !$inline);
    if ($text !== false) {
        $csvg->add($text);
        $csvg->download();
        exit;
    }
}
Пример #2
0
function download_psets_report($request)
{
    global $Conf;
    $where = array();
    $report = $request["report"];
    $nonanonymous = false;
    foreach (explode(" ", strtolower($report)) as $rep) {
        if ($rep === "college") {
            $where[] = "not c.extension";
        } else {
            if ($rep === "extension") {
                $where[] = "c.extension";
            } else {
                if ($rep === "nonanonymous") {
                    $nonanonymous = true;
                }
            }
        }
    }
    if (count($where)) {
        $where = array("(" . join(" or ", $where) . ")");
    }
    $where[] = "(c.roles&" . Contact::ROLE_PCLIKE . ")=0";
    $where[] = "not c.dropped";
    $where = join(" and ", $where);
    $sel_pset = null;
    if (get($request, "pset") && !($sel_pset = $Conf->pset_by_key($request["pset"]))) {
        return $Conf->errorMsg("No such pset");
    }
    $students = array();
    if (isset($request["fields"])) {
        $selection = explode(",", $request["fields"]);
    } else {
        $selection = array("name", "grade", "username", "huid", "extension");
    }
    $maxbyg = array();
    $max = $max_noextra = 0;
    foreach ($Conf->psets() as $pset) {
        if (!$pset->disabled && (!$sel_pset || $sel_pset === $pset)) {
            collect_pset_info($students, $pset, $where, !!$sel_pset, $nonanonymous);
            if ($g = $pset->group) {
                if (!isset($maxbyg[$g])) {
                    $maxbyg[$g] = $maxbyg["{$g}_noextra"] = 0;
                }
                foreach ($pset->grades as $ge) {
                    if ($ge->max && !$ge->no_total) {
                        $maxbyg[$g] += $ge->max;
                        if (!$ge->is_extra) {
                            $maxbyg["{$g}_noextra"] += $ge->max;
                        }
                    }
                }
            }
        }
    }
    foreach ($Conf->psets() as $pset) {
        if (!$pset->disabled && (!$sel_pset || $sel_pset === $pset)) {
            set_ranks($students, $selection, $pset->psetkey);
            if ($pset->has_extra) {
                set_ranks($students, $selection, $pset->psetkey . "_noextra");
            }
            if ($sel_pset) {
                foreach ($pset->grades as $ge) {
                    $selection[] = $ge->name;
                }
            }
        }
    }
    if (!$sel_pset) {
        set_ranks($students, $selection, "psets");
        set_ranks($students, $selection, "psets_noextra");
        set_ranks($students, $selection, "tests");
        $m_noextra = $maxbyg["psets_noextra"];
        $m_psets = $maxbyg["psets"];
        $m_tests = $maxbyg["tests"];
        foreach ($students as $s) {
            $s->performance = sprintf("%.1f", 100 * (0.9 * ($s->psets_noextra / $m_noextra) + 0.75 * ($s->psets / $m_psets) + 1.2 * ($s->tests / $m_tests)));
        }
        set_ranks($students, $selection, "performance");
    }
    $csv = new CsvGenerator();
    $csv->set_header($selection);
    $csv->set_selection($selection);
    foreach ($students as $s) {
        $csv->add($s);
    }
    $csv->download_headers("gradereport.csv");
    $csv->download();
    exit;
}