You are here

function commerce_reports_dashboard_block in Commerce Reporting 7.4

Same name and namespace in other branches
  1. 7.3 commerce_reports.dashboard.inc \commerce_reports_dashboard_block()

Renders a single block on the dashboard.

1 call to commerce_reports_dashboard_block()
commerce_reports_dashboard in ./commerce_reports.dashboard.inc
Renders the dashboard.

File

./commerce_reports.dashboard.inc, line 88
Dashboard for reporting module.

Code

function commerce_reports_dashboard_block($name, $options = array()) {
  $defaults = array(
    'title' => '',
    'sections' => array(),
  );
  $options += $defaults;
  $render = array(
    '#theme_wrappers' => array(
      'commerce_reports_dashboard_block',
    ),
    '#title' => $options['title'],
    '#name' => $name,
    '#report' => !empty($options['report']) ? l($options['report']['title'], $options['report']['path']) : NULL,
    '#width' => !empty($options['type']) ? $options['type'] : COMMERCE_REPORTS_DASHBOARD_BLOCK,
  );
  $section_links = array();
  $keys = array_keys($options['sections']);
  $first = reset($keys);
  foreach ($options['sections'] as $name => $information) {
    $block = block_load($information['module'], $information['block']);
    $block_render = module_invoke($block->module, 'block_view', $block->delta);
    $render['sections'][$name] = $block->module == 'views' ? $block_render['content'] : $block_render;
    $render['sections'][$name]['#width'] = empty($options['switchSections']) ? 100 : NULL;
    if (!empty($options['switchSections'])) {
      $link = array(
        'title' => $information['title'],
        'href' => 'admin/commerce/reports/dashboard',
        'attributes' => array(
          'class' => array(
            'switchSection',
            'overlay-exclude',
          ),
          'data-section' => $name,
        ),
      );
      if ($name === $first) {
        $link['attributes']['class'][] = 'activated';
      }
      $section_links[] = $link;
    }
  }
  $render['#operations'] = theme('links', array(
    'links' => $section_links,
    'attributes' => array(),
  ));
  if (!empty($options['switchSections'])) {
    $render['#visible'] = array(
      $first,
    );
  }
  else {
    $render['#visible'] = array_keys($options['sections']);
  }
  return $render;
}