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

Issue #2871165: Any log can be a movement

This commit is contained in:
Michael Stenta 2017-04-27 10:24:02 -04:00
parent b9c2ee6df1
commit 5b516eca7c
19 changed files with 718 additions and 227 deletions

View file

@ -20,6 +20,10 @@ function farm_log_update_dependencies() {
$dependencies['log'][7002] = array('farm_log' => 7000);
$dependencies['farm_log'][7001] = array('log' => 7002);
// Update 7006 (Add movement field to activities, harvests, inputs, and
// observations.) depends on farm_log_movement_update_7000().
$dependencies['farm_log'][7006] = array('farm_log_movement' => 7000);
return $dependencies;
}
@ -318,3 +322,18 @@ function farm_log_update_7005(&$sandbox) {
$sandbox['#finished'] = 1;
}
}
/**
* Add movement field to activities, harvests, inputs, and observations.
*/
function farm_log_update_7006(&$sandbox) {
$modules = array(
'farm_log_activity',
'farm_log_harvest',
'farm_log_input',
'farm_log_observation',
);
foreach ($modules as $module) {
features_revert(array($module => array('field_instance')));
}
}

View file

@ -159,6 +159,8 @@ function farm_log_entity_presave($entity, $type) {
*
* @param Entity $entity
* The entity to act upon.
*
* @see farm_log_entity_movement_presave().
*/
function farm_log_populate_geometry($entity) {

View file

@ -13,7 +13,7 @@ function farm_log_activity_field_default_field_instances() {
// Exported field_instance: 'log-farm_activity-field_farm_area'.
$field_instances['log-farm_activity-field_farm_area'] = array(
'bundle' => 'farm_activity',
'default_value' => NULL,
'default_value' => array(),
'deleted' => 0,
'description' => 'What areas did this activity take place in?',
'display' => array(
@ -114,7 +114,7 @@ function farm_log_activity_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'file_generic',
'weight' => 7,
'weight' => 8,
),
);
@ -224,6 +224,39 @@ function farm_log_activity_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'image_image',
'weight' => 7,
),
);
// Exported field_instance: 'log-farm_activity-field_farm_movement'.
$field_instances['log-farm_activity-field_farm_movement'] = array(
'bundle' => 'farm_activity',
'default_value' => NULL,
'deleted' => 0,
'description' => 'Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.',
'display' => array(
'default' => array(
'label' => 'hidden',
'module' => 'field_collection',
'settings' => array(
'view_mode' => 'full',
),
'type' => 'field_collection_fields',
'weight' => 7,
),
),
'entity_type' => 'log',
'field_name' => 'field_farm_movement',
'label' => 'Movement',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 0,
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 6,
),
);
@ -268,9 +301,11 @@ function farm_log_activity_field_default_field_instances() {
t('Assets');
t('Files');
t('Geometry');
t('Movement');
t('Notes');
t('Photo(s)');
t('This field is optional. It allows you to store geospatial data along with this activity.');
t('Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.');
t('What areas did this activity take place in?');
t('What assets do this activity log pertain to?');

View file

@ -13,8 +13,10 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_area
dependencies[] = farm_asset
dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map
dependencies[] = features
dependencies[] = field_collection
dependencies[] = file
dependencies[] = geofield
dependencies[] = geophp
@ -33,6 +35,7 @@ features[field_instance][] = log-farm_activity-field_farm_asset
features[field_instance][] = log-farm_activity-field_farm_files
features[field_instance][] = log-farm_activity-field_farm_geofield
features[field_instance][] = log-farm_activity-field_farm_images
features[field_instance][] = log-farm_activity-field_farm_movement
features[field_instance][] = log-farm_activity-field_farm_notes
features[log_type][] = farm_activity
features[views_view][] = farm_log_activity

View file

@ -94,7 +94,7 @@ function farm_log_harvest_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'file_generic',
'weight' => 7,
'weight' => 9,
),
);
@ -216,7 +216,40 @@ function farm_log_harvest_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'image_image',
'weight' => 6,
'weight' => 8,
),
);
// Exported field_instance: 'log-farm_harvest-field_farm_movement'.
$field_instances['log-farm_harvest-field_farm_movement'] = array(
'bundle' => 'farm_harvest',
'default_value' => NULL,
'deleted' => 0,
'description' => 'Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.',
'display' => array(
'default' => array(
'label' => 'hidden',
'module' => 'field_collection',
'settings' => array(
'view_mode' => 'full',
),
'type' => 'field_collection_fields',
'weight' => 7,
),
),
'entity_type' => 'log',
'field_name' => 'field_farm_movement',
'label' => 'Movement',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 0,
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 7,
),
);
@ -305,10 +338,12 @@ function farm_log_harvest_field_default_field_instances() {
t('Describe the quantity of this harvest, using a value and a unit of measurement. For example, if you harvested 100 pounds of potatoes, enter "100" in the Value field, and "lbs" in the Units field. As you type the unit, you will have the option of selecting from units that you\'ve entered in the past.');
t('Files');
t('Geometry');
t('Movement');
t('Notes');
t('Photo(s)');
t('Quantity');
t('This field is optional. It allows you to store geospatial data along with this harvest.');
t('Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.');
t('What assets do this harvest log pertain to?');
return $field_instances;

View file

@ -12,6 +12,7 @@ dependencies[] = entityreference
dependencies[] = entityreference_view_widget
dependencies[] = farm_asset
dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map
dependencies[] = farm_quantity
dependencies[] = features
@ -31,6 +32,7 @@ features[field_instance][] = log-farm_harvest-field_farm_asset
features[field_instance][] = log-farm_harvest-field_farm_files
features[field_instance][] = log-farm_harvest-field_farm_geofield
features[field_instance][] = log-farm_harvest-field_farm_images
features[field_instance][] = log-farm_harvest-field_farm_movement
features[field_instance][] = log-farm_harvest-field_farm_notes
features[field_instance][] = log-farm_harvest-field_farm_quantity
features[log_type][] = farm_harvest

View file

@ -13,7 +13,7 @@ function farm_log_input_field_default_field_instances() {
// Exported field_instance: 'log-farm_input-field_farm_area'.
$field_instances['log-farm_input-field_farm_area'] = array(
'bundle' => 'farm_input',
'default_value' => NULL,
'default_value' => array(),
'deleted' => 0,
'description' => 'What areas is this input being applied to?',
'display' => array(
@ -131,7 +131,7 @@ function farm_log_input_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'file_generic',
'weight' => 12,
'weight' => 14,
),
);
@ -253,7 +253,7 @@ function farm_log_input_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'image_image',
'weight' => 11,
'weight' => 13,
),
);
@ -417,6 +417,39 @@ function farm_log_input_field_default_field_instances() {
),
);
// Exported field_instance: 'log-farm_input-field_farm_movement'.
$field_instances['log-farm_input-field_farm_movement'] = array(
'bundle' => 'farm_input',
'default_value' => NULL,
'deleted' => 0,
'description' => 'Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.',
'display' => array(
'default' => array(
'label' => 'hidden',
'module' => 'field_collection',
'settings' => array(
'view_mode' => 'full',
),
'type' => 'field_collection_fields',
'weight' => 13,
),
),
'entity_type' => 'log',
'field_name' => 'field_farm_movement',
'label' => 'Movement',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 0,
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 12,
),
);
// Exported field_instance: 'log-farm_input-field_farm_notes'.
$field_instances['log-farm_input-field_farm_notes'] = array(
'bundle' => 'farm_input',
@ -506,12 +539,14 @@ function farm_log_input_field_default_field_instances() {
t('Geometry');
t('How was this input applied?');
t('Material');
t('Movement');
t('Notes');
t('Photo(s)');
t('Purpose');
t('Quantity');
t('Source/Manufacturer');
t('This field is optional. It allows you to store geospatial data along with this input.');
t('Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.');
t('What areas is this input being applied to?');
t('What assets do this input log pertain to?');
t('What material is being applied? As you type, you will have the option of selecting from materials that you\'ve entered in the past.');

View file

@ -13,6 +13,7 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_area
dependencies[] = farm_asset
dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map
dependencies[] = farm_quantity
dependencies[] = farm_taxonomy
@ -44,6 +45,7 @@ features[field_instance][] = log-farm_input-field_farm_input_method
features[field_instance][] = log-farm_input-field_farm_input_purpose
features[field_instance][] = log-farm_input-field_farm_input_source
features[field_instance][] = log-farm_input-field_farm_material
features[field_instance][] = log-farm_input-field_farm_movement
features[field_instance][] = log-farm_input-field_farm_notes
features[field_instance][] = log-farm_input-field_farm_quantity
features[log_type][] = farm_input

View file

@ -62,5 +62,27 @@ function farm_log_movement_field_default_field_bases() {
'type' => 'taxonomy_term_reference',
);
// Exported field_base: 'field_farm_movement'.
$field_bases['field_farm_movement'] = array(
'active' => 1,
'cardinality' => 1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'field_farm_movement',
'indexes' => array(
'revision_id' => array(
0 => 'revision_id',
),
),
'locked' => 0,
'module' => 'field_collection',
'settings' => array(
'hide_blank_items' => 1,
'path' => '',
),
'translatable' => 0,
'type' => 'field_collection',
);
return $field_bases;
}

View file

@ -10,6 +10,136 @@
function farm_log_movement_field_default_field_instances() {
$field_instances = array();
// Exported field_instance:
// 'field_collection_item-field_farm_movement-field_farm_geofield'.
$field_instances['field_collection_item-field_farm_movement-field_farm_geofield'] = array(
'bundle' => 'field_farm_movement',
'default_value' => NULL,
'deleted' => 0,
'description' => 'This field allows you to optionally specify a more precise geometry for the new location of assets. If you leave it blank, the geometry will be copied from the areas that assets are moving to (if available).',
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'openlayers_geofield',
'settings' => array(
'data' => 'full',
'map_layer_preset' => 'farm_map_geofield_formatter:openlayers_geofield_layer_formatter',
),
'type' => 'openlayers_geofield',
'weight' => 2,
),
),
'entity_type' => 'field_collection_item',
'field_name' => 'field_farm_geofield',
'label' => 'Movement geometry',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'openlayers_geofield',
'settings' => array(
'allow_edit' => 1,
'data_storage' => 'collection',
'delta_handling' => 'default',
'feature_types' => array(
'path' => 'path',
'point' => 'point',
'polygon' => 'polygon',
),
'geocoder_field' => 'field_farm_animal_tag_location',
'geocoder_handler' => 'bing',
'handler_settings' => array(
'google' => array(
'all_results' => 0,
'biasing' => array(
'bounds' => '',
'components' => '',
'region' => '',
),
'geometry_type' => 'point',
'reject_results' => array(
'APPROXIMATE' => 0,
'GEOMETRIC_CENTER' => 0,
'RANGE_INTERPOLATED' => 0,
'ROOFTOP' => 0,
),
),
),
'openlayers_map' => 'farm_map_geofield',
'showInputField' => 1,
'use_geocoder' => 0,
),
'type' => 'openlayers_geofield',
'weight' => 6,
),
);
// Exported field_instance:
// 'field_collection_item-field_farm_movement-field_farm_move_from'.
$field_instances['field_collection_item-field_farm_movement-field_farm_move_from'] = array(
'bundle' => 'field_farm_movement',
'default_value' => NULL,
'deleted' => 0,
'description' => 'Specify the area(s) that assets are being moved from. This field is optional, and is only used for reference. You may leave this blank as a way of setting initial location.',
'display' => array(
'default' => array(
'label' => 'inline',
'module' => 'taxonomy',
'settings' => array(),
'type' => 'taxonomy_term_reference_link',
'weight' => 1,
),
),
'entity_type' => 'field_collection_item',
'field_name' => 'field_farm_move_from',
'label' => 'Movement from',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'weight' => 4,
),
);
// Exported field_instance:
// 'field_collection_item-field_farm_movement-field_farm_move_to'.
$field_instances['field_collection_item-field_farm_movement-field_farm_move_to'] = array(
'bundle' => 'field_farm_movement',
'default_value' => NULL,
'deleted' => 0,
'description' => 'Specify the area(s) that assets are being moved to. If you need to specify more precise locations (in addition to these areas), use the Geometry field below.',
'display' => array(
'default' => array(
'label' => 'inline',
'module' => 'taxonomy',
'settings' => array(),
'type' => 'taxonomy_term_reference_link',
'weight' => 0,
),
),
'entity_type' => 'field_collection_item',
'field_name' => 'field_farm_move_to',
'label' => 'Movement to',
'required' => 1,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_select',
'weight' => 2,
),
);
// Exported field_instance: 'log-farm_movement-field_farm_asset'.
$field_instances['log-farm_movement-field_farm_asset'] = array(
'bundle' => 'farm_movement',
@ -83,7 +213,7 @@ function farm_log_movement_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'file_generic',
'weight' => 7,
'weight' => 9,
),
);
@ -143,7 +273,7 @@ function farm_log_movement_field_default_field_instances() {
'use_geocoder' => 1,
),
'type' => 'openlayers_geofield',
'weight' => 5,
'weight' => 7,
),
);
@ -193,7 +323,7 @@ function farm_log_movement_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'image_image',
'weight' => 6,
'weight' => 8,
),
);
@ -227,7 +357,7 @@ function farm_log_movement_field_default_field_instances() {
'size' => 60,
),
'type' => 'options_select',
'weight' => 2,
'weight' => 4,
),
);
@ -261,6 +391,39 @@ function farm_log_movement_field_default_field_instances() {
'size' => 60,
),
'type' => 'options_select',
'weight' => 5,
),
);
// Exported field_instance: 'log-farm_movement-field_farm_movement'.
$field_instances['log-farm_movement-field_farm_movement'] = array(
'bundle' => 'farm_movement',
'default_value' => NULL,
'deleted' => 0,
'description' => 'Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.',
'display' => array(
'default' => array(
'label' => 'hidden',
'module' => 'field_collection',
'settings' => array(
'view_mode' => 'full',
),
'type' => 'field_collection_fields',
'weight' => 8,
),
),
'entity_type' => 'log',
'field_name' => 'field_farm_movement',
'label' => 'Movement',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 0,
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 3,
),
);
@ -295,7 +458,7 @@ function farm_log_movement_field_default_field_instances() {
'rows' => 5,
),
'type' => 'text_textarea',
'weight' => 4,
'weight' => 6,
),
);
@ -303,13 +466,19 @@ function farm_log_movement_field_default_field_instances() {
// Included for use with string extractors like potx.
t('Assets');
t('Files');
t('From');
t('Geometry');
t('Movement');
t('Movement from');
t('Movement geometry');
t('Movement to');
t('Notes');
t('Photo(s)');
t('Specify the area(s) that assets are being moved from. This field is optional, and is only used for reference. You may leave this blank as a way of setting initial location.');
t('Specify the area(s) that assets are being moved to. If you need to specify more precise locations (in addition to these areas), use the Geometry field below.');
t('Specify the area(s) that assets are being moved to. If you need to specify more precise locations, use the Geometry field below.');
t('This field allows you to optionally specify a more precise geometry for the new location of assets. If you leave it blank, the geometry will be copied from the areas that assets are moving to (if available).');
t('This field is optional. It allows you to specify a more precise geometry for assets referenced by this particular movement. If you leave it blank, the geometry will be copied from the area that assets are moving to (if available).');
t('To');
t('Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.');
t('What assets are being moved?');
t('Where is it moving from? This field is optional. You may leave this blank as a way of setting the initial location of an object.');

View file

@ -15,6 +15,7 @@ dependencies[] = farm_asset
dependencies[] = farm_fields
dependencies[] = farm_map
dependencies[] = features
dependencies[] = field_collection
dependencies[] = file
dependencies[] = geofield
dependencies[] = geophp
@ -31,12 +32,17 @@ features[ctools][] = views:views_default:3.0
features[features_api][] = api:2
features[field_base][] = field_farm_move_from
features[field_base][] = field_farm_move_to
features[field_base][] = field_farm_movement
features[field_instance][] = field_collection_item-field_farm_movement-field_farm_geofield
features[field_instance][] = field_collection_item-field_farm_movement-field_farm_move_from
features[field_instance][] = field_collection_item-field_farm_movement-field_farm_move_to
features[field_instance][] = log-farm_movement-field_farm_asset
features[field_instance][] = log-farm_movement-field_farm_files
features[field_instance][] = log-farm_movement-field_farm_geofield
features[field_instance][] = log-farm_movement-field_farm_images
features[field_instance][] = log-farm_movement-field_farm_move_from
features[field_instance][] = log-farm_movement-field_farm_move_to
features[field_instance][] = log-farm_movement-field_farm_movement
features[field_instance][] = log-farm_movement-field_farm_notes
features[log_type][] = farm_movement
features[views_view][] = farm_area_assets

View file

@ -0,0 +1,12 @@
<?php
/**
* @file
* Code for Farm Log: Movement installation/updates.
*/
/**
* Create new movement field collection.
*/
function farm_log_movement_update_7000(&$sandbox) {
features_revert(array('farm_log_movement' => array('field_base', 'field_instance')));
}

View file

@ -34,25 +34,23 @@ function farm_log_movement_asset_location_markup($asset) {
// Otherwise, none.
else {
$options = array(
'query' => array(
'destination' => 'farm/asset/' . $asset->id,
'farm_asset' => $asset->id,
),
);
$link = l(t('add a movement'), 'log/add/farm_movement', $options);
$output .= 'N/A (' . $link . ')';
$output .= 'N/A';
}
// Get the asset's most recent movement.
$movement = farm_log_movement_asset_latest_movement($asset);
$log = farm_log_movement_asset_latest_movement($asset);
// Load the log's movement field, if it exists.
if (!empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) {
$movement = field_collection_item_load($log->field_farm_movement[LANGUAGE_NONE][0]['value']);
}
// If a geofield exists on the movement, display it.
if (!empty($movement->field_farm_geofield[LANGUAGE_NONE][0]['geom'])) {
// Build the geofield map and add it to the page content.
$field_instance = field_info_instance('log', 'field_farm_geofield', 'farm_movement');
$geofield = field_view_field('log', $movement, 'field_farm_geofield', $field_instance['display']['default']);
$field_instance = field_info_instance('field_collection_item', 'field_farm_geofield', 'field_farm_movement');
$geofield = field_view_field('field_collection_item', $movement, 'field_farm_geofield', $field_instance['display']['default']);
$output .= drupal_render($geofield);
}
@ -96,7 +94,7 @@ function farm_log_movement_form_farm_asset_form_alter(&$form, &$form_state, $for
$form['farm_log_movement_asset_location'] = array(
'#type' => 'textfield',
'#title' => t('Current location'),
'#description' => t('Set the current areas(s) that this asset is in. Separate multiple areas with commas. Asset location is determined by movement logs, so a movement log will automatically be generated if you change this field.'),
'#description' => t('Set the current areas(s) that this asset is in. Separate multiple areas with commas. A movement observation log will be created automatically if you change this field.'),
'#autocomplete_path' => 'taxonomy/autocomplete/field_farm_area',
'#default_value' => $location,
);
@ -161,8 +159,8 @@ function farm_log_movement_asset_location_submit(array $form, array &$form_state
$areas[] = $area;
}
// Create a movement log.
farm_log_movement_move_assets($asset, $areas, REQUEST_TIME, TRUE);
// Create an observation log to record the movement.
farm_log_movement_observation($asset, $areas, REQUEST_TIME);
}
/**
@ -171,10 +169,10 @@ function farm_log_movement_asset_location_submit(array $form, array &$form_state
* @param FarmAsset $asset
* The farm_asset object to look for.
* @param int $time
* Unix timestamp limiter. Only movement logs before this time will be
* included. Defaults to the current time. Set to 0 to load the absolute last.
* Unix timestamp limiter. Only logs before this time will be included.
* Defaults to the current time. Set to 0 to load the absolute last.
* @param bool $done
* Whether or not to only show movement logs that are marked as "done".
* Whether or not to only show logs that are marked as "done".
* Defaults to TRUE.
*
* @return array
@ -182,29 +180,24 @@ function farm_log_movement_asset_location_submit(array $form, array &$form_state
*/
function farm_log_movement_asset_location(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {
$areas = array();
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'log')
->entityCondition('bundle', 'farm_movement')
->fieldCondition('field_farm_asset', 'target_id', $asset->id)
->propertyOrderBy('timestamp', 'DESC')
->propertyOrderBy('id', 'DESC')
->range(0, 1);
if (!empty($time)) {
$query->propertyCondition('timestamp', $time, '<=');
// Load the log using our helper function.
$log = farm_log_movement_asset_latest_movement($asset, $time, $done);
// If a movement field doesn't exist, bail.
if (empty($log->field_farm_movement[LANGUAGE_NONE][0]['value'])) {
return $areas;
}
if (!empty($done)) {
$query->propertyCondition('done', TRUE);
}
$result = $query->execute();
if (!empty($result['log'])) {
foreach ($result['log'] as $id => $entity) {
$log = log_load($id);
foreach ($log->field_farm_move_to[LANGUAGE_NONE] as $area_reference) {
if (!empty($area_reference['tid'])) {
$term = taxonomy_term_load($area_reference['tid']);
if (!empty($term)) {
$areas[] = $term;
}
// Load the log's movement field
$movement = field_collection_item_load($log->field_farm_movement[LANGUAGE_NONE][0]['value']);
if (!empty($movement->field_farm_move_to[LANGUAGE_NONE])) {
foreach ($movement->field_farm_move_to[LANGUAGE_NONE] as $area_reference) {
if (!empty($area_reference['tid'])) {
$term = taxonomy_term_load($area_reference['tid']);
if (!empty($term)) {
$areas[] = $term;
}
}
}
@ -213,22 +206,28 @@ function farm_log_movement_asset_location(FarmAsset $asset, $time = REQUEST_TIME
}
/**
* Find the latest movement of an asset.
* Load an asset's latest log that defines a movement.
*
* @param FarmAsset $asset
* The farm_asset object to look for.
* @param int $time
* Unix timestamp limiter. Only movement logs before this time will be
* included. Defaults to the current time. Set to 0 to load the absolute last.
* Unix timestamp limiter. Only logs before this time will be included.
* Defaults to the current time. Set to 0 to load the absolute last.
* @param bool $done
* Whether or not to only show movement logs that are marked as "done".
* Defaults to TRUE.
* Whether or not to only show logs that are marked as "done". Defaults to
* TRUE.
*
* @return Log|bool
* Returns a movement log entity. FALSE if something goes wrong.
* Returns a log entity. FALSE if something goes wrong.
*/
function farm_log_movement_asset_latest_movement(FarmAsset $asset, $time = REQUEST_TIME, $done = TRUE) {
// If the asset doesn't have an ID (for instance if it is new and hasn't been
// saved yet), bail.
if (empty($asset->id)) {
return FALSE;
}
// Make a query for loading the latest movement log.
$query = farm_log_movement_asset_movement_query($asset->id, $time, $done);
@ -244,7 +243,7 @@ function farm_log_movement_asset_latest_movement(FarmAsset $asset, $time = REQUE
}
/**
* Build a query to find the latest movement log of an asset.
* Build a query to find the latest log of an asset that define a movement.
*
* @param int|string $asset_id
* The asset id to search for. This can either be a specific id, or a field
@ -252,28 +251,45 @@ function farm_log_movement_asset_latest_movement(FarmAsset $asset, $time = REQUE
* of field alias string usage, see the Views field handler code in
* farm_log_handler_relationship_location::query().
* @param int $time
* Unix timestamp limiter. Only movement logs before this time will be
* included. Defaults to the current time. Set to 0 to load the absolute last.
* Unix timestamp limiter. Onlylogs before this time will be included.
* Defaults to the current time. Set to 0 to load the absolute last.
* @param bool $done
* Whether or not to only show movement logs that are marked as "done".
* Defaults to TRUE.
* Whether or not to only show logs that are marked as "done". Defaults to
* TRUE.
* @param string $field
* If the log id is desired, use "log_id. If the movement field_collection id
* is desired, use "movement_id".
*
* @return \SelectQuery
* Returns a SelectQuery for finding the latest log.
* Returns a SelectQuery object.
*/
function farm_log_movement_asset_movement_query($asset_id, $time = REQUEST_TIME, $done = TRUE) {
function farm_log_movement_asset_movement_query($asset_id, $time = REQUEST_TIME, $done = TRUE, $field = 'log_id') {
// Build a sub-query that will be used in the join to load the latest
// movement log of a given asset.
// Build a query to find an asset's latest log that defines a movement.
// We use the "ss_" prefix throughout to indicate that this is generally going
// to be used as a sub-select, and to avoid potential name conflicts when this
// is used elsewhere (ie: farm_log_handler_relationship_location::query()).
$query = db_select('log', 'ss_log');
$query->join('field_data_field_farm_asset', 'ss_fdffa', 'ss_log.id = ss_fdffa.entity_id');
$query->where("ss_log.type = 'farm_movement'");
// Join in asset references and filter to only include logs that reference the
// specified asset.
$query->join('field_data_field_farm_asset', 'ss_fdffa', "ss_fdffa.entity_type = 'log' AND ss_fdffa.entity_id = ss_log.id");
$query->where('ss_fdffa.field_farm_asset_target_id = ' . $asset_id);
$query->where('ss_fdffa.deleted = 0');
// Join in movement field collections and the "move to" field data.
// Filter to only include logs that have a movement with a "to" value.
$query->join('field_data_field_farm_movement', 'ss_fdffm', "ss_fdffm.entity_type = 'log' AND ss_fdffm.entity_id = ss_log.id");
$query->where('ss_fdffm.deleted = 0');
$query->join('field_data_field_farm_move_to', 'ss_fdffmt', "ss_fdffmt.entity_type = 'field_collection_item' AND ss_fdffmt.bundle = 'field_farm_movement' AND ss_fdffmt.entity_id = ss_fdffm.field_farm_movement_value");
$query->where('ss_fdffmt.field_farm_move_to_tid IS NOT NULL');
// Order by timestamp and then log id, descending.
$query->orderBy('ss_log.timestamp', 'DESC');
$query->orderBy('ss_log.id', 'DESC');
// We only want the first result.
$query->range(0, 1);
$query->addField('ss_log', 'id');
// If only "done" movement logs should be included, add a filter.
if ($done) {
@ -291,6 +307,14 @@ function farm_log_movement_asset_movement_query($asset_id, $time = REQUEST_TIME,
$query->where('ss_log.timestamp <= ' . $time);
}
// Add a field to the query based on the function argument.
if ($field == 'log_id') {
$query->addField('ss_log', 'id');
}
elseif ($field == 'movement_id') {
$query->addField('ss_fdffm', 'field_farm_movement_value');
}
// Return the query object.
return $query;
}
@ -313,7 +337,7 @@ function farm_log_movement_action_info() {
/**
* Action function for farm_log_asset_move_action.
*
* Creates a new movement record for the specified assets.
* Creates a new movement activity log for the specified assets.
*
* @param array $assets
* An array of asset entities to move.
@ -333,7 +357,7 @@ function farm_log_movement_asset_move_action(array $assets, $context = array())
}
/**
* Move farm asset(s) to an area. Creates a movement log.
* Create an observation log for moving assets to areas.
*
* @param array|FarmAsset $assets
* Array of assets to include in the move.
@ -341,105 +365,65 @@ function farm_log_movement_asset_move_action(array $assets, $context = array())
* An array of areas to move to.
* @param int $timestamp
* The timestamp of the move. Defaults to the current time.
* @param bool $done
* Whether or not to mark the movement done. Default to FALSE.
*/
function farm_log_movement_move_assets($assets, $areas, $timestamp = REQUEST_TIME, $done = FALSE) {
function farm_log_movement_observation($assets, $areas, $timestamp = REQUEST_TIME) {
// If $assets isn't an array, wrap it.
if (!is_array($assets)) {
$assets = array($assets);
}
// If there are no areas to move to, bail.
if (empty($areas)) {
return;
}
// Create a new movement log entity.
$log = entity_create('log', array('type' => 'farm_movement'));
$log = entity_create('log', array('type' => 'farm_observation'));
// Create an entity wrapper for the log.
$log_wrapper = entity_metadata_wrapper('log', $log);
// Set the name of the observation: "Current location: [area(s)]". If there
// are more than 3 areas, just list the first, and add "(+ X more)".
$log_name = t('Current location') . ': ';
$area_names = array();
foreach ($areas as $area) {
$area_names[] = $area->name;
}
$count_areas = count($area_names);
if (count($area_names) <= 3) {
$log_name .= implode($area_names, ', ');
}
else {
$log_name .= $area_names[0] . ' (+' . ($count_areas - 1) . ' ' . t('more') . ')';
}
$log_wrapper->name->set($log_name);
// Iterate through the assets.
foreach ($assets as $asset) {
// Add the asset to the asset reference field.
$log->field_farm_asset[LANGUAGE_NONE][] = array(
'target_id' => $asset->id,
);
$log_wrapper->field_farm_asset[] = $asset;
}
// Populate the movement's "From" field based on the current asset location(s).
farm_log_movement_prepopulate_movement_from($log->field_farm_move_from, $assets);
// Set the date.
$log->timestamp = $timestamp;
$log_wrapper->timestamp->set($timestamp);
// Create a new movement field_collection entity.
$movement = entity_create('field_collection_item', array('field_name' => 'field_farm_movement'));
// Attach the movement to the log.
$movement->setHostEntity('log', $log);
// Set the "to" area(s).
foreach ($areas as $area) {
if (!empty($area->tid)) {
$log->field_farm_move_to[LANGUAGE_NONE][] = array(
'tid' => $area->tid,
);
}
$log_wrapper->field_farm_movement->field_farm_move_to[] = $area;
}
// Set the log's done status.
$log->done = $done;
// Set the log's done status to TRUE.
$log_wrapper->done->set(TRUE);
// Save the movement.
log_save($log);
}
/**
* Populate a movement's "from" field based on current asset location(s).
*
* @param array $from_field
* A reference to the field on the movement log. The values in this array
* will be populated.
* @param array $assets
* An array of FarmAsset entities.
* @param bool $log_form
* By default, this function assumes that it is working with a $log entity.
* By setting $log_form to TRUE, it can also be used to alter the default
* value of the "from" field in a log edit form.
*/
function farm_log_movement_prepopulate_movement_from(&$from_field, $assets = array(), $log_form = FALSE) {
// If assets are empty, bail.
if (empty($assets)) {
return;
}
// Keep track of what areas these assets are coming from.
$from_areas = array();
// Iterate through the assets.
foreach ($assets as $asset) {
// Load the asset's current location.
$areas = farm_log_movement_asset_location($asset);
// If the asset has a current location, add the location area names to the
// "from" field.
if (!empty($areas)) {
foreach ($areas as $area) {
// Avoid adding the same area more than once.
if (in_array($area->tid, $from_areas)) {
continue;
}
// Assuming that this is an entity object, and not a log form, add area
// term ids to the array in the expected format.
if (!$log_form) {
$from_field[LANGUAGE_NONE][] = array(
'tid' => $area->tid,
);
}
// If this is a log form, add areas to the #default_value array.
else {
$from_field[LANGUAGE_NONE]['#default_value'][] = $area->tid;
}
// Remember the areas that have already been added.
$from_areas[] = $area->tid;
}
}
}
// Save the log.
$log_wrapper->save();
}

View file

@ -86,6 +86,126 @@ function farm_log_movement_farm_taxonomy_term_view_views($term) {
);
}
/**
* Implements hook_entity_presave().
*/
function farm_log_movement_entity_presave($entity, $type) {
// When a movement field collection entity is being saved, populate the
// geometry field from the "move to" area reference field.
if ($type == 'field_collection_item' && $entity->field_name == 'field_farm_movement') {
farm_log_movement_populate_geometry($entity);
}
// When a log is being saved, populate the "move from" field with current
// asset location(s).
if ($type == 'log') {
farm_log_movement_populate_move_from($entity);
}
}
/**
* Helper function for populating a movement field collection geometry from the
* "move to" area reference field.
*
* @param Entity $entity
* The entity to act upon.
*
* @see farm_log_entity_presave().
*/
function farm_log_movement_populate_geometry($entity) {
// Define the area field name.
$area_field = 'field_farm_move_to';
// If the log doesn't have an area reference field, bail.
if (!isset($entity->{$area_field})) {
return;
}
// If a geometry is already defined, bail.
if (!empty($entity->field_farm_geofield[LANGUAGE_NONE][0]['geom'])) {
return;
}
// Load the area(s) referenced by the area reference field.
$area_ids = array();
if (!empty($entity->{$area_field}[LANGUAGE_NONE])) {
foreach ($entity->{$area_field}[LANGUAGE_NONE] as $area_reference) {
if (!empty($area_reference['tid'])) {
$area_ids[] = $area_reference['tid'];
}
}
}
// Extract geometries from the areas.
$geoms = farm_area_extract_geoms($area_ids);
// Populate the geofield.
farm_map_geofield_populate($entity, $geoms);
}
/**
* Helper function for populating a movement field collection's "from" field
* based on current asset location(s).
*
* @param Entity $log
* The log entity.
*/
function farm_log_movement_populate_move_from($log) {
// Create an entity wrapper for the log.
$log_wrapper = entity_metadata_wrapper('log', $log);
// If the "move to" field is empty, then this isn't a movement, so bail.
if (empty($log_wrapper->field_farm_movement->field_farm_move_to->value())) {
return;
}
// If the "move from" field is already populated, bail.
if (!empty($log_wrapper->field_farm_movement->field_farm_move_from->value())) {
return;
}
// If there are no assets referenced, bail.
if (empty($log_wrapper->field_farm_asset->value())) {
return;
}
// Load assets.
$assets = array();
foreach ($log_wrapper->field_farm_asset->value() as $asset) {
$assets[] = $asset;
}
// Keep track of what areas these assets are coming from.
$from_areas = array();
// Iterate through the assets.
foreach ($assets as $asset) {
// Load the asset's current location.
$areas = farm_log_movement_asset_location($asset);
// Build a list of areas.
if (!empty($areas)) {
foreach ($areas as $area) {
// Avoid adding the same area more than once.
if (in_array($area->tid, $from_areas)) {
continue;
}
// Remember the areas that have already been added.
$from_areas[] = $area->tid;
}
}
}
// Add the areas to the "move from" field.
$log_wrapper->field_farm_movement->field_farm_move_from->set($from_areas);
}
/**
* Implements hook_entity_view_alter().
*/
@ -105,30 +225,3 @@ function farm_log_movement_entity_view_alter(&$build, $type) {
'#weight' => -100,
);
}
/**
* Implements hook_form_alter().
*/
function farm_log_movement_form_alter(&$form, &$form_state, $form_id) {
// If this is a movement log form...
if ($form_id == 'log_form' && $form['#bundle'] == 'farm_movement') {
// If the "to" field is empty...
if (empty($form['field_farm_move_to'][LANGUAGE_NONE][0]['#default_value'])) {
// Alter the form with the farm_log helper function.
farm_log_form_prepopulate_area($form, 'field_farm_move_to');
}
// Load assets from URL query string.
$assets = farm_asset_load_assets_from_url();
// If the "from" field is empty, and assets are available...
if (empty($form['field_farm_move_from'][LANGUAGE_NONE][0]['#default_value']) && !empty($assets)) {
// Look up the asset's last location and prepopulate the "from" field.
farm_log_movement_prepopulate_movement_from($form['field_farm_move_from'], $assets, TRUE);
}
}
}

View file

@ -12,13 +12,13 @@ function farm_log_movement_views_data_alter(&$data) {
$data['farm_asset']['latest_movement'] = array(
'title' => t('Latest movement'),
'help' => t('The latest movement record for this farm asset.'),
'help' => t('The latest movement for this farm asset.'),
'relationship' => array(
'title' => t('Latest movement'),
'help' => t('Relate the farm asset to its latest movement log.'),
'help' => t('Relate the farm asset to its latest movement.'),
'handler' => 'farm_log_movement_handler_relationship_location',
'base' => 'log',
'base field' => 'id',
'base' => 'field_collection_item',
'base field' => 'item_id',
'label' => t('Latest movement'),
),
);

View file

@ -133,7 +133,7 @@ function farm_log_movement_views_default_views() {
$handler->display->display_options['fields']['timestamp']['date_format'] = 'custom';
$handler->display->display_options['fields']['timestamp']['custom_date_format'] = 'M j Y';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'long';
/* Field: Log: From */
/* Field: Field collection item: Movement from */
$handler->display->display_options['fields']['field_farm_move_from']['id'] = 'field_farm_move_from';
$handler->display->display_options['fields']['field_farm_move_from']['table'] = 'field_data_field_farm_move_from';
$handler->display->display_options['fields']['field_farm_move_from']['field'] = 'field_farm_move_from';
@ -147,7 +147,7 @@ function farm_log_movement_views_default_views() {
$handler->display->display_options['sorts']['id']['table'] = 'log';
$handler->display->display_options['sorts']['id']['field'] = 'id';
$handler->display->display_options['sorts']['id']['order'] = 'DESC';
/* Contextual filter: Log: To (field_farm_move_to) */
/* Contextual filter: Field collection item: Movement to (field_farm_move_to) */
$handler->display->display_options['arguments']['field_farm_move_to_tid']['id'] = 'field_farm_move_to_tid';
$handler->display->display_options['arguments']['field_farm_move_to_tid']['table'] = 'field_data_field_farm_move_to';
$handler->display->display_options['arguments']['field_farm_move_to_tid']['field'] = 'field_farm_move_to_tid';
@ -393,17 +393,17 @@ function farm_log_movement_views_default_views() {
$view->description = '';
$view->tag = 'farm_log';
$view->base_table = 'log';
$view->human_name = 'Farm Log: Movement';
$view->human_name = 'Farm Log: Logs with movements';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Movements';
$handler->display->display_options['title'] = 'Logs with movements';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'view any farm_movement log entities';
$handler->display->display_options['access']['perm'] = 'view all logs';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
@ -416,12 +416,13 @@ function farm_log_movement_views_default_views() {
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'views_bulk_operations' => 'views_bulk_operations',
'id' => 'id',
'done' => 'done',
'id' => 'id',
'timestamp' => 'timestamp',
'field_farm_asset' => 'field_farm_asset',
'field_farm_move_to' => 'field_farm_move_to',
'field_farm_move_from' => 'field_farm_move_from',
'name' => 'name',
'field_farm_asset' => 'field_farm_asset',
'type' => 'type',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
@ -430,14 +431,14 @@ function farm_log_movement_views_default_views() {
'separator' => '',
'empty_column' => 0,
),
'id' => array(
'done' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'done' => array(
'id' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
@ -451,29 +452,50 @@ function farm_log_movement_views_default_views() {
'separator' => '',
'empty_column' => 0,
),
'field_farm_asset' => array(
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'field_farm_move_to' => array(
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'field_farm_move_from' => array(
'name' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'field_farm_asset' => array(
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'type' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
);
$handler->display->display_options['style_options']['empty_table'] = TRUE;
/* Header: Global: Unfiltered text */
$handler->display->display_options['header']['area_text_custom']['id'] = 'area_text_custom';
$handler->display->display_options['header']['area_text_custom']['table'] = 'views';
$handler->display->display_options['header']['area_text_custom']['field'] = 'area_text_custom';
$handler->display->display_options['header']['area_text_custom']['empty'] = TRUE;
$handler->display->display_options['header']['area_text_custom']['content'] = 'This lists all logs that define movements of assets. Multiple log types are included in this list, and are specified in the "Log type" column.';
/* No results behavior: Global: Unfiltered text */
$handler->display->display_options['empty']['area_text_custom']['id'] = 'area_text_custom';
$handler->display->display_options['empty']['area_text_custom']['table'] = 'views';
$handler->display->display_options['empty']['area_text_custom']['field'] = 'area_text_custom';
$handler->display->display_options['empty']['area_text_custom']['empty'] = TRUE;
$handler->display->display_options['empty']['area_text_custom']['content'] = 'No movements found.';
$handler->display->display_options['empty']['area_text_custom']['content'] = 'No logs with movements found.';
/* Relationship: Log: Movement (field_farm_movement) */
$handler->display->display_options['relationships']['field_farm_movement_value']['id'] = 'field_farm_movement_value';
$handler->display->display_options['relationships']['field_farm_movement_value']['table'] = 'field_data_field_farm_movement';
$handler->display->display_options['relationships']['field_farm_movement_value']['field'] = 'field_farm_movement_value';
$handler->display->display_options['relationships']['field_farm_movement_value']['required'] = TRUE;
$handler->display->display_options['relationships']['field_farm_movement_value']['delta'] = '0';
/* Field: Bulk operations: Log */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'log';
@ -542,14 +564,23 @@ function farm_log_movement_views_default_views() {
$handler->display->display_options['fields']['field_farm_asset']['settings'] = array(
'link' => 1,
);
/* Field: Log: To */
/* Field: Field collection item: Movement to */
$handler->display->display_options['fields']['field_farm_move_to']['id'] = 'field_farm_move_to';
$handler->display->display_options['fields']['field_farm_move_to']['table'] = 'field_data_field_farm_move_to';
$handler->display->display_options['fields']['field_farm_move_to']['field'] = 'field_farm_move_to';
/* Field: Log: From */
$handler->display->display_options['fields']['field_farm_move_from']['id'] = 'field_farm_move_from';
$handler->display->display_options['fields']['field_farm_move_from']['table'] = 'field_data_field_farm_move_from';
$handler->display->display_options['fields']['field_farm_move_from']['field'] = 'field_farm_move_from';
$handler->display->display_options['fields']['field_farm_move_to']['relationship'] = 'field_farm_movement_value';
$handler->display->display_options['fields']['field_farm_move_to']['delta_offset'] = '0';
/* Field: Log: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'log';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = 'Log';
$handler->display->display_options['fields']['name']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['name']['alter']['path'] = 'log/[id]';
/* Field: Log: Log type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'log';
$handler->display->display_options['fields']['type']['field'] = 'type';
/* Sort criterion: Log: Timestamp */
$handler->display->display_options['sorts']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['table'] = 'log';
@ -574,18 +605,11 @@ function farm_log_movement_views_default_views() {
$handler->display->display_options['arguments']['field_farm_asset_target_id']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['field_farm_asset_target_id']['specify_validation'] = TRUE;
$handler->display->display_options['arguments']['field_farm_asset_target_id']['validate']['type'] = 'farm_asset';
/* Filter criterion: Log: Log type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'log';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
'farm_movement' => 'farm_movement',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Log: To (field_farm_move_to) */
/* Filter criterion: Field collection item: Movement to (field_farm_move_to) */
$handler->display->display_options['filters']['field_farm_move_to_tid']['id'] = 'field_farm_move_to_tid';
$handler->display->display_options['filters']['field_farm_move_to_tid']['table'] = 'field_data_field_farm_move_to';
$handler->display->display_options['filters']['field_farm_move_to_tid']['field'] = 'field_farm_move_to_tid';
$handler->display->display_options['filters']['field_farm_move_to_tid']['relationship'] = 'field_farm_movement_value';
$handler->display->display_options['filters']['field_farm_move_to_tid']['value'] = '';
$handler->display->display_options['filters']['field_farm_move_to_tid']['group'] = 1;
$handler->display->display_options['filters']['field_farm_move_to_tid']['exposed'] = TRUE;
@ -594,6 +618,16 @@ function farm_log_movement_views_default_views() {
$handler->display->display_options['filters']['field_farm_move_to_tid']['expose']['operator'] = 'field_farm_move_to_tid_op';
$handler->display->display_options['filters']['field_farm_move_to_tid']['expose']['identifier'] = 'field_farm_move_to_tid';
$handler->display->display_options['filters']['field_farm_move_to_tid']['vocabulary'] = 'farm_areas';
/* Filter criterion: Log: Log type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'log';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['group'] = 1;
$handler->display->display_options['filters']['type']['exposed'] = TRUE;
$handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op';
$handler->display->display_options['filters']['type']['expose']['label'] = 'Log type';
$handler->display->display_options['filters']['type']['expose']['operator'] = 'type_op';
$handler->display->display_options['filters']['type']['expose']['identifier'] = 'type';
/* Filter criterion: Date: Date (log) */
$handler->display->display_options['filters']['date_filter']['id'] = 'date_filter';
$handler->display->display_options['filters']['date_filter']['table'] = 'log';
@ -640,8 +674,8 @@ function farm_log_movement_views_default_views() {
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'farm/logs/movements';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'Movements';
$handler->display->display_options['menu']['weight'] = '';
$handler->display->display_options['menu']['title'] = 'Logs with movements';
$handler->display->display_options['menu']['weight'] = '100';
$handler->display->display_options['menu']['name'] = 'farm';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;
@ -680,7 +714,8 @@ function farm_log_movement_views_default_views() {
t(' previous'),
t('next '),
t('last »'),
t('No movements found.'),
t('No logs with movements found.'),
t('field collection item from field_farm_movement'),
t('Log'),
t('- Choose an operation -'),
t('Done'),
@ -689,9 +724,9 @@ function farm_log_movement_views_default_views() {
t('Log ID'),
t('.'),
t('Date'),
t('Assets'),
t('To'),
t('From'),
t('Assets'),
t('Log type'),
t('All'),
t('%1\'s movements'),
t('Area'),

View file

@ -8,8 +8,8 @@
/**
* Farm log movement location relationship handler.
*
* Create a relationship between a farm_asset, and it's most recent movement
* log entity, in order to determine its current location.
* Create a relationship between a farm_asset, and it's most recent log entity's
* movement field collection, in order to determine its current location.
*
* The following Views handlers were used as examples to develop this:
* views_handler_relationship_entity_reverse
@ -50,7 +50,7 @@ class farm_log_movement_handler_relationship_location extends views_handler_rela
$form['future'] = array(
'#type' => 'checkbox',
'#title' => t('Include future logs'),
'#description' => t('Finds the latest log, even if it is in the future.'),
'#description' => t('Finds the last log, even if it is in the future.'),
'#default_value' => !empty($this->options['future']),
);
}
@ -77,7 +77,7 @@ class farm_log_movement_handler_relationship_location extends views_handler_rela
else {
$time = REQUEST_TIME;
}
$query = farm_log_movement_asset_movement_query($asset_id_field, $time, $done);
$query = farm_log_movement_asset_movement_query($asset_id_field, $time, $done, 'movement_id');
// Build the join definition.
$def = $this->definition;

View file

@ -13,7 +13,7 @@ function farm_log_observation_field_default_field_instances() {
// Exported field_instance: 'log-farm_observation-field_farm_area'.
$field_instances['log-farm_observation-field_farm_area'] = array(
'bundle' => 'farm_observation',
'default_value' => NULL,
'default_value' => array(),
'deleted' => 0,
'description' => 'What areas did this observation take place in?',
'display' => array(
@ -114,7 +114,7 @@ function farm_log_observation_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'file_generic',
'weight' => 8,
'weight' => 10,
),
);
@ -224,7 +224,40 @@ function farm_log_observation_field_default_field_instances() {
'progress_indicator' => 'bar',
),
'type' => 'image_image',
'weight' => 7,
'weight' => 9,
),
);
// Exported field_instance: 'log-farm_observation-field_farm_movement'.
$field_instances['log-farm_observation-field_farm_movement'] = array(
'bundle' => 'farm_observation',
'default_value' => NULL,
'deleted' => 0,
'description' => 'Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.',
'display' => array(
'default' => array(
'label' => 'hidden',
'module' => 'field_collection',
'settings' => array(
'view_mode' => 'full',
),
'type' => 'field_collection_fields',
'weight' => 9,
),
),
'entity_type' => 'log',
'field_name' => 'field_farm_movement',
'label' => 'Movement',
'required' => 0,
'settings' => array(
'user_register_form' => FALSE,
),
'widget' => array(
'active' => 0,
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 8,
),
);
@ -323,7 +356,7 @@ function farm_log_observation_field_default_field_instances() {
'module' => 'field_collection',
'settings' => array(),
'type' => 'field_collection_embed',
'weight' => 9,
'weight' => 11,
),
);
@ -333,12 +366,14 @@ function farm_log_observation_field_default_field_instances() {
t('Assets');
t('Files');
t('Geometry');
t('Movement');
t('Notes');
t('Optionally, use this quantity field to record an observed quantity.');
t('Photo(s)');
t('Quantity');
t('This field is optional. It allows you to store geospatial data along with this observation.');
t('Type');
t('Use these fields to record a movement with this log entry. This will be used to define the location of any referenced assets. The current location of any asset is determined by the most recently completed movement log. Only the "to" field is required.');
t('What areas did this observation take place in?');
t('What assets do this observation log pertain to?');
t('What type of observation is this? Use this to organize your observations into categories for easy viewing later. Some default types are provided, and new observation types can be added to the ' . l('Observation Types', 'admin/structure/taxonomy/farm_observation_types') . ' vocabulary.');

View file

@ -13,6 +13,7 @@ dependencies[] = entityreference_view_widget
dependencies[] = farm_area
dependencies[] = farm_asset
dependencies[] = farm_fields
dependencies[] = farm_log_movement
dependencies[] = farm_map
dependencies[] = farm_quantity
dependencies[] = features
@ -38,6 +39,7 @@ features[field_instance][] = log-farm_observation-field_farm_asset
features[field_instance][] = log-farm_observation-field_farm_files
features[field_instance][] = log-farm_observation-field_farm_geofield
features[field_instance][] = log-farm_observation-field_farm_images
features[field_instance][] = log-farm_observation-field_farm_movement
features[field_instance][] = log-farm_observation-field_farm_notes
features[field_instance][] = log-farm_observation-field_farm_observation_type
features[field_instance][] = log-farm_observation-field_farm_quantity