farm_ui.farm_metrics.inc in farmOS 7
Farm metrics hooks implemented by farm_ui module.
File
modules/farm/farm_ui/farm_ui.farm_metrics.incView source
<?php
/**
* @file
* Farm metrics hooks implemented by farm_ui module.
*/
/**
* Implements hook_farm_metrics().
*/
function farm_ui_farm_metrics() {
/**
* @todo
* Move this out of farm_ui.
* Currently it depends on farm_ui_entities() function, which should be moved
* to a new general-purpose farm_entity module.
*/
// Start an empty metrics array.
$metrics = array();
// Load information about farmOS entities.
$entities = farm_ui_entities();
// Add metrics for each asset type.
foreach ($entities['farm_asset'] as $type => $info) {
// Query the database for a count.
$count = db_query('SELECT COUNT(*) FROM {farm_asset} WHERE type = :type AND archived = 0', array(
':type' => $type,
))
->fetchField();
// If no assets exist, skip.
if (empty($count)) {
continue;
}
// Build a metric.
$metrics[$type] = array(
'label' => $info['label_plural'],
'value' => $count,
'link' => farm_ui_view_page_path($info['view']),
);
}
// Return the metrics.
return $metrics;
}
Functions
Name | Description |
---|---|
farm_ui_farm_metrics | Implements hook_farm_metrics(). |