*/ /** * Implements hook_menu(). */ function og_analytics_menu() { $items = array(); // Define dashboard page $items['node/%node/og/analytics'] = array( 'title' => 'Analytics Dashboard', 'page callback' => 'og_analytics_dashboard_report', 'page arguments' => array(1), 'access callback' => 'og_analytics_dashboard_access', 'access arguments' => array(1), 'type' => MENU_LOCAL_TASK, ); return $items; } /** * Implements hook_perm(). */ function og_analytics_perm() { return array( 'view og analytics', ); } /** * Implements hook_init(). * Defining our module's js and css files. */ function og_analytics_init() { drupal_add_js(drupal_get_path('module', 'og_analytics') . '/js/og_analytics_dashboard.js'); drupal_add_css(drupal_get_path('module', 'og_analytics') . '/css/og_analytics.css'); drupal_set_html_head(''); } /** * Implements hook_theme(). */ function og_analytics_theme() { $content = NULL; return array( 'og_analytics' => array( 'template' => 'og_analytics', 'arguments' => array('content' => $content, 'navigation_current' => 'Dashboard', 'node' => $node), ), 'og_analytics_dashboard' => array( 'template' => 'og_analytics_dashboard', 'arguments' => array('content' => $content), ), 'og_analytics_widget' => array( 'template' => 'og_analytics_widget', 'arguments' => array('content' => $content), ), 'og_analytics_widget_members_count' => array( 'template' => 'og_analytics_widget_members_count', 'arguments' => array('content' => $content), ), 'og_analytics_widget_posts_count' => array( 'template' => 'og_analytics_widget_posts_count', 'arguments' => array('content' => $content), ), ); } /** * Access check for dashboard menu item. * * @param object $node * the node object. * @return bool */ function og_analytics_dashboard_access($node) { // Make sure this group is actually a group if (!isset($node->type) || !og_is_group_type($node->type)) { return FALSE; } if (user_access('view og analytics')) return TRUE; } /** * Implements hook_form(). * * @param array $form_state * * @param array $node * The group object. * * @param string $navigation_current * The current page (it's string name) that is being viewed. * */ function og_analytics_navigation_form(&$form_state, $node, $navigation_current) { global $base_url; // Call all modules to get their links to be put on the navigation select box. $modules_nav_links = module_invoke_all('og_analytics_navigation_links', $node); $own_nav_links = array( $base_url . '/node/' . $node->nid . '/og/analytics/dashboard' => 'Dashboard', ); if (!$modules_nav_links || !is_array($modules_nav_links)) $modules_nav_links = array(); $navigation_links = array_unique(array_merge($modules_nav_links, $own_nav_links)); asort($navigation_links, SORT_STRING); // Setting the default option for the select box. // This is used to set in the select box the current report page that is viewed. $default = array_search($navigation_current, $navigation_links); // Container div for the whole form. $form['og_analytics_navigation']['navigation'] = array( '#type' => 'fieldset', '#attributes' => array('class' => 'og_analytics'), '#collapsed' => FALSE, '#collapsible' => TRUE, ); $form['og_analytics_navigation']['navigation']['report'] = array( '#type' => 'select', '#title' => t('Navigate to Report'), '#options' => $navigation_links, '#default_value' => $default, '#attributes' => array('id' => 'og_analytics_navigation'), ); $form['#attributes'] = array( //'class' => 'og_analytics_form', 'id' => 'og_analytics_navigation' ); return $form; } function og_analytics_dashboard_report($node) { drupal_set_title(''); $output = ''; if (!isset($node->nid) && !og_is_group_type($node->type)) { if ($group_node = og_get_group_context()) { $node = $group_node; } } if (!$node) drupal_access_denied(); $content = ''; module_load_include('inc', 'og_analytics', 'inc/og_analytics_dashboard.model'); $members_count = og_analytics_group_members_count($node->nid); $content['widgets']['group_members_count']['html'] = theme('og_analytics_widget_members_count', $members_count); $posts_types = node_get_types('names'); unset($posts_types['other_content_directory']); unset($posts_types['other_content_file']); unset($posts_types['content_directory']); unset($posts_types['content_file']); $posts_count = og_analytics_group_posts_count($node->nid, TRUE, array_keys($posts_types)); $content['widgets']['group_activity']['html'] = theme('og_analytics_widget_posts_count', $posts_count); // it's possible to theme a generic widget with data and text description as follows: //$content['widgets']['group_members_count']['data'] = $og_statistics['members_count']; //$content['widgets']['group_members_count']['description'] = t('total members in community'); $output = theme('og_analytics_dashboard', $content); return theme('og_analytics', $output, 'Dashboard', $node); } /** * OG Analytics Return JSON. * helper function to return a json encoded string and exit immediately. */ function og_analytics_return_json($data) { echo json_encode($data); exit; }