You are here

function drush_better_statistics_stats_ls in Better Statistics 7

Drush command callback for stats-ls.

File

./better_statistics.drush.inc, line 71
Drush integration of Better Statistics.

Code

function drush_better_statistics_stats_ls() {
  module_load_include('inc', 'better_statistics', 'better_statistics.admin');
  $available = _better_statistics_get_custom_fields_by_module();
  $active = variable_get('better_statistics_fields', better_statistics_get_default_fields());

  // Options.
  $options['enabled'] = drush_get_option('enabled');
  $options['disabled'] = drush_get_option('disabled');

  // Assemble the list of fields to print.
  foreach ($available as $module => $fields) {
    $module_info = system_get_info('module', $module);
    $fields_by_module[$module_info['name']] = array();
    foreach ($fields as $field => $data) {
      $description = '';
      if (isset($data['views_field']['help'])) {
        $description = dt($data['views_field']['help']);
      }
      elseif (isset($data['schema']['description'])) {
        $description = dt($data['schema']['description']);
      }

      // Print according to the supplied options, if any.
      $enabled = $options['enabled'] && isset($active[$field]);
      $disabled = $options['disabled'] && !isset($active[$field]);
      $neither = !$options['enabled'] && !$options['disabled'];
      if ($enabled || $disabled || $neither) {
        $fields_by_module[$module_info['name']][$field] = $description;
        $fields[$field] = $description;
      }
    }
  }

  // Print either an ini-format list or a formatted ASCII table
  if (drush_get_option('pipe')) {
    drush_print_pipe(array_keys($fields));
  }
  else {
    foreach ($fields_by_module as $module => $mod_fields) {
      if (count($mod_fields) > 0) {
        drush_print($module);
        drush_print_table(drush_key_value_to_array_table($mod_fields));
      }
    }
  }
}