farmOS/farm_sensor.module

69 lines
1.3 KiB
Plaintext
Raw Normal View History

<?php
/**
* @file
* Code for the Farm Sensor feature.
*/
include_once 'farm_sensor.features.inc';
/**
* Implements hook_farm_sensor_type_info().
*/
function farm_sensor_farm_sensor_type_info() {
return array(
'none' => array(
'label' => t('None'),
'description' => t('No sensor type.'),
),
);
}
/**
* Get farm sensor types.
*
* @return array
* Returns an array of sensors type information provided by other modules.
*/
function farm_sensor_types() {
// Gather type information from other modules.
$sensor_types = module_invoke_all('farm_sensor_type_info');
// Return it.
return $sensor_types;
}
/**
* Helper function for saving farm sensor information.
*
* @param int $id
* The farm sensor asset id.
* @param string $type
* The sensor type.
* @param array $settings
* An array of sensor settings.
*/
function farm_sensor_save($id, $type, $settings = array()) {
// Delete any existing
farm_sensor_delete($id);
// Insert a new record.
$record = array(
'id' => $id,
'type' => $type,
'settings' => $settings,
);
drupal_write_record('farm_sensor', $record);
}
/**
* Helper function for deleting farm sensor information.
*
* @param int $id
* The farm sensor asset id.
*/
function farm_sensor_delete($id) {
db_delete('farm_sensor')->condition('id', $id)->execute();
}