'Project usage settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('project_usage_settings_form'), 'access arguments' => array('administer projects'), 'description' => 'Configure how long usage data is retained.', 'weight' => 1, 'file' => 'includes/admin.inc', ); $items['project/usage'] = array( 'title' => 'Project usage overview', 'page callback' => 'project_usage_overview', 'access arguments' => array('view project usage'), 'file' => 'includes/pages.inc', ); $items['project/usage/%'] = array( 'title' => 'Project usage', 'page callback' => 'project_usage_dispatch', 'page arguments' => array(2), 'access arguments' => array('view project usage'), 'file' => 'includes/pages.inc', ); return $items; } /** * Implementation of hook_theme(). */ function project_usage_theme() { $path = drupal_get_path('module', 'project_usage') .'/includes'; return array( 'project_usage_chart' => array( 'arguments' => array('args' => NULL), 'file' => 'pages.inc', 'path' => $path, ), 'project_usage_chart_by_release' => array( 'arguments' => array( 'title' => NULL, 'header' => NULL, 'rows' => NULL, ), 'file' => 'pages.inc', 'path' => $path, ), 'project_usage_header_links' => array( 'arguments' => array( 'project' => NULL, 'release' => NULL, ), 'file' => 'pages.inc', 'path' => $path, ), 'project_usage_project_page' => array( 'arguments' => array( 'project' => NULL, 'release_header' => NULL, 'release_rows' => NULL, 'project_header' => NULL, 'project_rows' => NULL, ), 'file' => 'pages.inc', 'path' => $path, ), 'project_usage_release_page' => array( 'arguments' => array( 'project' => NULL, 'release' => NULL, 'header' => NULL, 'rows' => NULL, ), 'file' => 'pages.inc', 'path' => $path, ), ); } /** * Implementation of hook_help(). */ function project_usage_help($path, $arg) { switch ($path) { case 'project/usage': case 'project/usage/%': module_load_include('inc', 'project_usage', 'includes/pages'); return _project_usage_help($arg[2]); } } /** * Implementation of hook_perm(). */ function project_usage_perm() { return array( 'view project usage', ); } /** * Implementation of hook_simpletest(). */ function project_usage_simpletest() { $dir = drupal_get_path('module', 'project_usage'). '/tests'; $tests = file_scan_directory($dir, '\.test$'); return array_keys($tests); } /** * Implementation of hook_devel_caches(). * * Lets the devel module know about our cache table so it can clear it. */ function project_usage_flush_caches() { return array('cache_project_usage'); } /** * Implementation of hook_project_page_link_alter(). */ function project_usage_project_page_link_alter(&$links, $node) { if (user_access('view project usage') && $node->project_release['releases']) { $links['resources']['links']['project_usage'] = l(t('View usage statistics'), 'project/usage/'. $node->project['uri']); } } /** * Return the total usage data for a given project across all versions. * * @param $nid * The project node ID. * * @return * The total reported usage for all versions of the given project. */ function project_usage_get_project_total_usage($nid) { $active_tids = project_release_compatibility_list(); static $total = array(); if (empty($total[$nid])) { $total[$nid] = 0; foreach ($active_tids as $tid => $term_name) { $total[$nid] += project_usage_get_project_usage($nid, $tid); } } return $total[$nid]; } /** * Return usage data for a given API version of a project. * * @param $nid * The project node ID. * @param $tid * The API compatibility taxonomy term ID to get usage for. * * @return * The total reported usage for the given version of the given project. */ function project_usage_get_project_usage($nid, $tid) { static $usage = array(); module_load_include('inc', 'project_usage', 'includes/date_api'); if (empty($usage[$nid][$tid])) { $usage[$nid][$tid] = db_result(db_query("SELECT count FROM {project_usage_week_project} WHERE nid = %d AND tid = %d AND timestamp = %d", $nid, $tid, project_usage_get_current_active_week())); } return $usage[$nid][$tid]; } /** * Return usage data for a given release. * * @param $nid * The release node ID. * * @return * The total reported usage for the given release. */ function project_usage_get_release_usage($nid) { static $usage = array(); module_load_include('inc', 'project_usage', 'includes/date_api'); if (empty($usage[$nid])) { $usage[$nid] = db_result(db_query("SELECT count FROM {project_usage_week_release} WHERE nid = %d AND timestamp = %d", $nid, project_usage_get_current_active_week())); } return $usage[$nid]; }