crm_core_report.module 2.85 KB
Newer Older
1
<?php
2 3 4 5 6 7 8 9 10 11 12

/**
 * @file
 * Provides a simple reporting interface for CRM Core and related modules.
 */

/**
 * Implements hook_hook_info().
 */
function crm_core_report_hook_info() {
  $hooks = array(
13
    // Registers reports from submodules within CRM Core, for central display.
14 15 16 17
    'crm_core_report_register' => array(
      'group' => 'crm_core_report',
    ),
  );
18 19

  return $hooks;
20 21 22 23 24 25 26 27 28
}

/**
 * Implements hook_permission().
 */
function crm_core_report_permission() {
  return array(
    'view crm report index' => array(
      'title' => t('View CRM Core report index'),
29
      'description' => t('View CRM Core report index page.'),
30 31 32 33 34 35 36 37
    ),
  );
}

/**
 * Implements hook_menu().
 */
function crm_core_report_menu() {
38

39 40
  $items = array();

41
  // Provides a listing of all reports registered for CRM Core.
42
  $items['crm-core/reports'] = array(
43
    'title' => 'Reports',
44 45 46 47 48 49 50 51 52 53 54 55 56
    'page callback' => 'crm_core_report_list',
    'access arguments' => array('view crm report index'),
    'type' => MENU_LOCAL_TASK,
    'file' => 'pages/crm_core_report.pages.inc',
  );

  return $items;
}

/**
 * Implements hook_theme().
 */
function crm_core_report_theme() {
57

58
  // We want a themable function for
59 60
  // - report items
  // - widgets
61
  // - report index.
62 63 64
  return array(
    'crm_core_report_index' => array(
      'template' => 'crm-core-report-index',
65
      'variables' => array('reports' => NULL, 'report_items' => array()),
66
      'path' => drupal_get_path('module', 'crm_core_report') . '/templates',
67 68 69 70
    ),
  );
}

71
/**
72
 * Preprocess report index.
73 74 75 76 77 78 79 80 81 82
 */
function crm_core_report_preprocess_crm_core_report_index(&$variables) {
  $report_items = array();
  $reports = $variables['reports'];
  if (!empty($reports)) {
    foreach ($reports as $key => $item) {
      $items = array();
      foreach ($item['reports'] as $report) {
        $items[] = l($report['title'], $report['path']) . '<br />' . $report['description'];
      }
83 84
      $report_items[] = theme('item_list', array(
        'items' => $items,
85
        'title' => $item['title'],
86
      ));
87 88
    }
  }
89

90 91
  $variables['report_items'] = $report_items;
}
92 93

/**
94
 * Constructs a list of registered reports and widgets for CRM Core.
95
 *
96 97 98 99
 * Reports registered via this hook will be listed on the reports page
 * and should include appropriate access controls, unless you want
 * everyone with access to the main reports page to see them.
 */
100
function hook_crm_core_report_register() {
101 102 103 104 105
  $reports = array();
  foreach (module_implements('crm_core_report_register') as $module) {
    $function = $module . '_crm_core_report_register';
    $reports = array_merge($reports, $function());
  }
106

107 108
  return $reports;
}
109 110 111 112 113 114 115 116 117 118 119

/**
 * Implements hook_init().
 *
 * Add basic CSS styles for crm-core/reports path.
 */
function crm_core_report_init() {
  if (arg(0) == 'crm-core' && arg(1) == 'reports') {
    drupal_add_css(drupal_get_path('module', 'crm_core_report') . '/css/reports.css');
  }
}