2014-11-12 20:27:59 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Code for the Farm Livestock feature.
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once 'farm_livestock.features.inc';
|
2014-12-01 20:22:38 +01:00
|
|
|
|
2017-06-23 01:26:08 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_ui_entities().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_ui_entities() {
|
|
|
|
return array(
|
|
|
|
'farm_asset' => array(
|
|
|
|
'animal' => array(
|
|
|
|
'label' => t('Animal'),
|
|
|
|
'label_plural' => t('Animals'),
|
|
|
|
'view' => 'farm_animals',
|
|
|
|
),
|
|
|
|
),
|
2017-06-25 15:46:36 +02:00
|
|
|
'taxonomy_term' => array(
|
|
|
|
'farm_animal_groups' => array(
|
|
|
|
'label' => t('Group'),
|
|
|
|
'label_plural' => t('Groups'),
|
|
|
|
'view' => 'farm_animal_groups',
|
|
|
|
'farm_asset' => 'animal',
|
|
|
|
),
|
|
|
|
'farm_animal_types' => array(
|
|
|
|
'label' => t('Type'),
|
|
|
|
'label_plural' => t('Types'),
|
|
|
|
'view' => 'farm_animal_types',
|
|
|
|
'farm_asset' => 'animal',
|
|
|
|
),
|
|
|
|
),
|
2017-06-23 01:26:08 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-06-20 18:00:17 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_area_type_info().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_area_type_info() {
|
|
|
|
return array(
|
|
|
|
'paddock' => array(
|
|
|
|
'label' => t('Paddock'),
|
2015-11-02 05:23:41 +01:00
|
|
|
'style' => 'farm_map_style_dark_green',
|
2015-07-31 03:01:08 +02:00
|
|
|
'weight' => 5,
|
2015-06-20 18:00:17 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-12-01 20:22:38 +01:00
|
|
|
/**
|
2017-06-21 20:46:31 +02:00
|
|
|
* Implements hook_farm_ui_actions().
|
2014-12-01 20:22:38 +01:00
|
|
|
*/
|
2017-06-21 20:46:31 +02:00
|
|
|
function farm_livestock_farm_ui_actions() {
|
2014-12-01 20:22:38 +01:00
|
|
|
|
2015-03-13 01:07:56 +01:00
|
|
|
// Define farm area actions.
|
2014-12-01 20:22:38 +01:00
|
|
|
$actions = array(
|
2016-06-08 19:17:48 +02:00
|
|
|
'medical' => array(
|
|
|
|
'title' => t('Add a medical record'),
|
|
|
|
'href' => 'log/add/farm_medical',
|
|
|
|
'assets' => array(
|
|
|
|
'animal',
|
|
|
|
),
|
|
|
|
'views' => array(
|
|
|
|
'farm_log_medical',
|
|
|
|
),
|
|
|
|
),
|
2014-12-01 20:22:38 +01:00
|
|
|
);
|
2015-03-13 01:07:56 +01:00
|
|
|
return $actions;
|
2014-12-01 20:22:38 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 22:29:51 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_asset_view_views().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_asset_view_views($farm_asset) {
|
|
|
|
|
|
|
|
// If the entity is not an animal, bail.
|
|
|
|
if ($farm_asset->type != 'animal') {
|
2015-04-13 22:47:46 +02:00
|
|
|
return array();
|
2015-03-19 22:29:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of Views to include on Animals.
|
|
|
|
return array(
|
2016-05-05 17:10:01 +02:00
|
|
|
array(
|
|
|
|
'name' => 'farm_log_activity',
|
|
|
|
'weight' => 0,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'farm_log_observation',
|
|
|
|
'weight' => 10,
|
|
|
|
),
|
2016-06-08 19:17:48 +02:00
|
|
|
array(
|
|
|
|
'name' => 'farm_log_medical',
|
|
|
|
'weight' => 20,
|
|
|
|
),
|
2016-05-05 17:10:01 +02:00
|
|
|
array(
|
|
|
|
'name' => 'farm_log_input',
|
|
|
|
'weight' => 50,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'farm_log_harvest',
|
|
|
|
'weight' => 60,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'farm_log_movement',
|
|
|
|
'weight' => 100,
|
|
|
|
),
|
2016-05-05 17:15:55 +02:00
|
|
|
array(
|
2016-10-26 22:41:01 +02:00
|
|
|
'name' => 'farm_asset_children',
|
|
|
|
'display' => 'page',
|
|
|
|
'title' => t('Children'),
|
2016-05-05 17:15:55 +02:00
|
|
|
'weight' => 110,
|
|
|
|
),
|
2015-03-19 22:29:51 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:11:44 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_taxonomy_term_view_views().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_taxonomy_term_view_views($term) {
|
|
|
|
|
2015-03-21 18:40:38 +01:00
|
|
|
// Start a list of View names.
|
|
|
|
$views = array();
|
|
|
|
|
|
|
|
// Switch logic depending on the vocabulary.
|
|
|
|
switch ($term->vocabulary_machine_name) {
|
|
|
|
|
|
|
|
// Farm areas:
|
|
|
|
case 'farm_areas':
|
2015-04-10 17:12:30 +02:00
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_animals',
|
|
|
|
'weight' => -10,
|
|
|
|
);
|
2015-03-21 18:40:38 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Farm animal groups:
|
|
|
|
case 'farm_animal_groups':
|
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_animals',
|
|
|
|
'arg' => 2,
|
2017-05-20 16:41:23 +02:00
|
|
|
'always' => TRUE,
|
2015-03-21 18:40:38 +01:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Farm animal types:
|
|
|
|
case 'farm_animal_types':
|
|
|
|
$views[] = array(
|
|
|
|
'name' => 'farm_animals',
|
|
|
|
'arg' => 3,
|
2017-05-20 16:41:23 +02:00
|
|
|
'always' => TRUE,
|
2015-03-21 18:40:38 +01:00
|
|
|
);
|
|
|
|
break;
|
2015-03-21 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2015-03-21 18:40:38 +01:00
|
|
|
return $views;
|
2015-03-21 16:11:44 +01:00
|
|
|
}
|
|
|
|
|
2014-12-01 20:22:38 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_farm_area_links().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_area_links($id) {
|
2016-03-08 00:02:44 +01:00
|
|
|
$links = array();
|
|
|
|
|
|
|
|
// Add link to livestock.
|
|
|
|
$view = views_get_view('farm_animals');
|
|
|
|
$view->preview('default', array($id));
|
|
|
|
if ($view->total_rows > 0) {
|
|
|
|
$links[] = array(
|
|
|
|
'title' => t('Animals') . ': ' . $view->total_rows,
|
2016-03-07 22:07:24 +01:00
|
|
|
'href' => 'farm/assets/animals/' . $id,
|
2016-03-08 00:02:44 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $links;
|
2015-04-13 22:47:46 +02:00
|
|
|
}
|
2015-12-01 15:12:28 +01:00
|
|
|
|
|
|
|
/**
|
2015-12-04 16:51:53 +01:00
|
|
|
* Implements hook_views_post_render().
|
2015-12-01 15:12:28 +01:00
|
|
|
*/
|
2015-12-04 16:51:53 +01:00
|
|
|
function farm_livestock_views_post_render(&$view, &$output, &$cache) {
|
2015-12-01 15:12:28 +01:00
|
|
|
|
2015-12-04 16:51:53 +01:00
|
|
|
// If this is the Farm Animals page...
|
|
|
|
if ($view->name == 'farm_animals' && $view->current_display == 'page') {
|
2015-12-01 15:12:28 +01:00
|
|
|
|
2016-10-26 17:25:01 +02:00
|
|
|
// If dashboard maps are disabled in the farm_map module settings, bail.
|
|
|
|
if (!variable_get('farm_map_show', TRUE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-07 21:10:46 +01:00
|
|
|
// If there are any arguments, bail.
|
|
|
|
/**
|
|
|
|
* @todo
|
|
|
|
* Display a map that is filtered by the same arguments.
|
|
|
|
*/
|
|
|
|
if (!empty($view->args)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-04 16:51:53 +01:00
|
|
|
// If the View result is not empty...
|
|
|
|
if (!empty($view->result)) {
|
2015-12-01 15:12:28 +01:00
|
|
|
|
2015-12-04 16:51:53 +01:00
|
|
|
// Add the Animals asset map to the top of the View.
|
|
|
|
$map = \Drupal\openlayers\Openlayers::load('Map', 'farm_assets_animal');
|
2017-04-12 17:09:42 +02:00
|
|
|
if (!empty($map)) {
|
|
|
|
$map_build = $map->build();
|
|
|
|
$output = drupal_render($map_build) . $output;
|
|
|
|
}
|
2015-12-04 16:51:53 +01:00
|
|
|
}
|
2015-12-01 15:12:28 +01:00
|
|
|
}
|
|
|
|
}
|
2017-04-27 20:11:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_farm_log_allowed_asset_reference_type().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_log_allowed_asset_reference_type($log_type) {
|
|
|
|
|
|
|
|
// On medical logs, only animals can be referenced.
|
|
|
|
if ($log_type == 'farm_medical') {
|
|
|
|
return 'animal';
|
|
|
|
}
|
|
|
|
}
|
2017-05-30 20:53:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_farm_log_categories().
|
|
|
|
*/
|
|
|
|
function farm_livestock_farm_log_categories() {
|
|
|
|
|
|
|
|
// Provide an "Animals" log category.
|
|
|
|
return array('Animals');
|
|
|
|
}
|