View source
<?php
function quant_hook_info() {
$hooks = array();
$hooks['quants'] = array(
'group' => 'quant',
);
$hooks['quant_charts'] = array(
'group' => 'quant',
);
return $hooks;
}
function quant_permission() {
return array(
'administer quant' => array(
'title' => t('Administer quant'),
'description' => t('Permits access to the administration page and analytics page.'),
),
'view analytics page' => array(
'title' => t('View the analytics page'),
'description' => t('Permits access to view the analytics page.'),
),
);
}
function quant_menu() {
$items = array();
$items['analytics'] = array(
'title' => 'Site analytics',
'description' => 'View charts depicting action over time for many Drupal components.',
'page callback' => 'quant_page',
'access arguments' => array(
'view analytics page',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'quant.pages.inc',
);
$items['admin/reports/analytics'] = $items['analytics'];
$items['admin/config/media/quant'] = array(
'title' => 'Quant (analytics)',
'description' => 'Configure the quantitative analytics page',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quant_admin_settings',
),
'access arguments' => array(
'administer quant',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'quant.admin.inc',
);
return $items;
}
function quant_theme($existing, $type, $theme, $path) {
$items = array();
$items['quant_page'] = array(
'variables' => array(
'form' => NULL,
'charts' => NULL,
),
'file' => 'quant.theme.inc',
);
$items['quant_time_form'] = array(
'render element' => 'form',
'file' => 'quant.theme.inc',
);
$items['quant_table'] = array(
'arguments' => array(
'table' => NULL,
'title' => NULL,
'width' => NULL,
),
'path' => $path . '/theme',
'template' => 'quant_table',
);
return $items;
}
function quant_get_quants() {
return _quant_get_data('quants');
}
function quant_get_quant($id) {
$quants = quant_get_quants();
return isset($quants[$id]) ? $quants[$id] : NULL;
}
function quant_get_quant_charts() {
static $charts = NULL;
if ($charts === NULL) {
$charts = _quant_get_data('quant_charts');
foreach ($charts as $key => $plugin) {
quant_include($plugin->plugin['file'], $plugin->plugin['path'], NULL);
$charts[$key]->chart = new $plugin->plugin['class'](NULL, $plugin);
}
}
return $charts;
}
function quant_get_quant_chart($id) {
$charts = quant_get_quant_charts();
return isset($charts[$id]) ? $charts[$id] : NULL;
}
function quant_get_chart_plugin() {
return quant_get_quant_chart(variable_get('quant_chart', 'table'));
}
function _quant_get_data($hook, $reset = FALSE) {
static $data = array();
if (!isset($data[$hook]) || $reset) {
$cache = !$reset ? cache_get($hook) : NULL;
if (isset($cache->data)) {
$data[$hook] = $cache->data;
}
else {
$data[$hook] = module_invoke_all($hook);
drupal_alter($hook, $data[$hook]);
cache_set($hook, $data[$hook], 'cache', CACHE_TEMPORARY);
}
}
return $data[$hook];
}
function quant_include($file, $dir = 'includes', $module = 'quant') {
static $used = array();
if ($module) {
$dir = '/' . ($dir ? $dir . '/' : '');
if (!isset($used[$module][$dir][$file])) {
require_once './' . drupal_get_path('module', $module) . "{$dir}{$file}.inc";
$used[$module][$dir][$file] = TRUE;
}
}
else {
if (!isset($used[$dir][$file])) {
require_once "{$dir}/{$file}";
$user[$dir][$file] = TRUE;
}
}
}