Beispiel #1
0
function percentage_table($_col, $_truncate, $_where_clause = "", $_filters = array())
{
    $config =& SlimStatConfig::get_instance();
    $thead = array("first" => array(), "last" => array($config->i18n->percentage));
    if (is_array($_col)) {
        foreach ($_col as $this_col) {
            $thead["first"][] = isset($config->i18n->fields[$this_col]) ? $config->i18n->fields[$this_col] : $this_col;
        }
    } else {
        $thead["first"][] = isset($config->i18n->fields[$_col]) ? $config->i18n->fields[$_col] : $_col;
    }
    $tbody = array();
    $total_hits = SlimStat::get_hits($_where_clause, $_filters);
    $results = SlimStat::_get_table_data($_col, $_where_clause, is_array($_col) ? implode(", ", $_col) : $_col, "hits", $_filters);
    foreach ($results as $result) {
        $row = array("first" => array(), "last" => array());
        $p = number_format($result["hits"] / $total_hits * 100);
        if (is_array($_col)) {
            foreach ($_col as $this_col) {
                $row["first"][] = get_td($_col, $result, $this_col, $_truncate + 5, isset($config->i18n->name_lookups[$this_col]) ? $config->i18n->name_lookups[$this_col] : null, $this_col == $_col[0]);
            }
        } else {
            $row["first"][] = get_td(array($_col), $result, $_col, $_truncate + 5, isset($config->i18n->name_lookups[$_col]) ? $config->i18n->name_lookups[$_col] : null, true);
        }
        $row["last"][] = ($p < 1 ? "&lt;1" : $p) . "%";
        $tbody[] = $row;
    }
    return SlimStat::render_table($thead, $tbody);
}