3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Provide metrics for asset type counts.

This commit is contained in:
Michael Stenta 2019-03-25 09:53:42 -04:00
parent 986900255b
commit 19752aff93

View file

@ -0,0 +1,40 @@
<?php
/**
* @file
* Farm dashboard hooks implemented by farm_ui module.
*/
/**
* Implements hook_farm_dashboard_metrics().
*/
function farm_ui_farm_dashboard_metrics() {
// 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[] = array(
'label' => $info['label_plural'],
'value' => $count,
'link' => farm_ui_view_page_path($info['view']),
);
}
// Return the metrics.
return $metrics;
}