Example #1
0
function institution_view_type_graph($type = null, $institutiondata)
{
    $institution = is_object($institutiondata) ? $institutiondata->institution : $institutiondata['name'];
    $values = array();
    // Draw a pie graph of views broken down by view type.
    $values[] = 'dashboard';
    if ($institution == 'mahara') {
        $where = 'institution IS NULL';
    } else {
        $where = 'institution = ?';
        $values[] = $institution;
    }
    $values[] = $institution;
    $viewtypes = get_records_sql_array('
        SELECT type, COUNT(id) AS views
        FROM {view} WHERE type != ?
        AND id IN (
            SELECT id FROM {view} WHERE owner IS NOT NULL AND owner IN (
                SELECT u.id FROM {usr} u LEFT JOIN {usr_institution} ui ON u.id = ui.usr
                WHERE ' . $where . ' AND u.id != 0 AND deleted = 0
            ) UNION SELECT id FROM {view} WHERE institution IS NOT NULL AND institution = ?
        ) GROUP BY type', $values);
    if (count($viewtypes) > 1) {
        $dataarray = array();
        foreach ($viewtypes as &$t) {
            $dataarray[get_string($t->type, 'view')] = $t->views;
        }
        arsort($dataarray);
        $data['graph'] = $type ? $type : 'pie';
        $data['graph_function_name'] = 'institution_view_type_graph';
        $data['title'] = get_string('viewsbytype', 'admin');
        $data['labels'] = array_keys($dataarray);
        $data['data'] = $dataarray;
        require_once get_config('libroot') . 'graph.php';
        $graphdata = get_circular_graph_json($data, null, true);
        $dbdata['type'] = 'view-type-graph';
        $dbdata['institution'] = $institution;
        $dbwhere = $dbdata;
        $dbdata['value'] = json_encode($graphdata);
        $dbdata['ctime'] = db_format_timestamp(time());
        ensure_record_exists('institution_data', (object) $dbwhere, (object) $dbdata);
    }
}
Example #2
0
                        }
                    }
                    $x = empty($colours[$x + 1]) ? 0 : $x + 1;
                }
            }
            $data['datastr'] = json_encode($jsondata[0]);
            $data['configstr'] = json_encode($data['configs']);
            json_reply(false, array('data' => $data));
        }
        $graphdata = array();
        $data['colours'] = get_graph_colours($data, $colours);
        // Now covert it to something Chart.js can understand
        switch ($data['graph']) {
            case 'Pie':
            case 'PolarArea':
            case 'Doughnut':
                list($graphdata, $configs) = get_circular_graph_json($data, $colours);
                break;
            case 'Bar':
                list($graphdata, $configs) = get_bar_graph_json($data, $colours);
                break;
            case 'Line':
                list($graphdata, $configs) = get_line_graph_json($data, $colours);
                break;
            default:
        }
        $data['datastr'] = json_encode($graphdata);
        $data['configstr'] = json_encode($configs);
        json_reply(false, array('data' => $data));
    }
}