You are here

function farm_metrics in farmOS 7

Returns a sorted array of all metrics.

2 calls to farm_metrics()
farm_metrics_dashboard_pane in modules/farm/farm_metrics/farm_metrics.farm_dashboard.inc
Metrics dashboard callback.
farm_metrics_farm_info in modules/farm/farm_metrics/farm_metrics.module
Implements hook_farm_info().
2 string references to 'farm_metrics'
farm_metrics_hook_info in modules/farm/farm_metrics/farm_metrics.module
Implements hook_hook_info().
farm_update_7052 in ./farm.install
Install the Farm Metrics module.

File

modules/farm/farm_metrics/farm_metrics.module, line 55
Farm metrics module.

Code

function farm_metrics() {

  // Ask modules for metrics.
  $metrics = module_invoke_all('farm_metrics');

  // If no metrics are available, return an empty array.
  if (empty($metrics)) {
    return array();
  }

  // Make sure all metrics have defaults set.
  $defaults = array(
    'label' => '',
    'value' => '0',
    'link' => 'farm',
    'weight' => 0,
  );
  foreach ($metrics as $key => $metric) {
    $metrics[$key] = array_merge($defaults, $metric);
  }

  // Sort the metrics by weight ascending, value descending.
  $weight_index = array();
  $value_index = array();
  foreach ($metrics as $key => $row) {
    $weight_index[$key] = $row['weight'];
    $value_index[$key] = $row['value'];
  }
  array_multisort($weight_index, SORT_ASC, $value_index, SORT_DESC, $metrics);

  // Return metrics.
  return $metrics;
}