Пример #1
0
function downloadCSV($info, $header, $filename, $options = array())
{
    global $Opt;
    if (defval($options, "type", "csv") == "csv" && !isset($Opt["disableCsv"])) {
        $csvt = CsvGenerator::TYPE_COMMA;
    } else {
        $csvt = CsvGenerator::TYPE_TAB;
    }
    if (get($options, "always_quote")) {
        $csvt |= CsvGenerator::FLAG_ALWAYS_QUOTE;
    }
    if (get($options, "crlf")) {
        $csvt |= CsvGenerator::FLAG_CRLF;
    }
    $csvg = new CsvGenerator($csvt);
    if ($header) {
        $csvg->set_header($header, true);
    }
    if (get($options, "selection")) {
        $csvg->set_selection($options["selection"] === true ? $header : $options["selection"]);
    }
    $csvg->download_headers($Opt["downloadPrefix"] . $filename . $csvg->extension(), !get($options, "inline"));
    if ($info === false) {
        return $csvg;
    } else {
        $csvg->add($info);
        if (get($options, "sort")) {
            $csvg->sort($options["sort"]);
        }
        $csvg->download();
        exit;
    }
}
Пример #2
0
function get_pcassignment_csv()
{
    global $user_chair;
    list($header, $texts) = SearchAction::pcassignments_csv_data($user_chair, range(1, 30));
    $csvg = new CsvGenerator();
    $csvg->set_header($header);
    $csvg->set_selection($header);
    $csvg->add($texts);
    return $csvg->unparse();
}
Пример #3
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;
}
Пример #4
0
 public function unparse()
 {
     $csvg = new CsvGenerator();
     $csvg->set_header($this->header, true);
     $csvg->set_selection($this->header);
     $csvg->add($this->data);
     return $csvg->unparse();
 }