235 lines
4.9 KiB
Plaintext
235 lines
4.9 KiB
Plaintext
<?php
|
|
/**
|
|
* @file
|
|
* Code for the Farm Livestock feature.
|
|
*/
|
|
|
|
include_once 'farm_livestock.features.inc';
|
|
|
|
/**
|
|
* 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',
|
|
),
|
|
),
|
|
'log' => array(
|
|
'farm_medical' => array(
|
|
'label' => t('Medical record'),
|
|
'label_plural' => t('Medical records'),
|
|
'view' => 'farm_log_medical',
|
|
),
|
|
),
|
|
'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',
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_area_type_info().
|
|
*/
|
|
function farm_livestock_farm_area_type_info() {
|
|
return array(
|
|
'paddock' => array(
|
|
'label' => t('Paddock'),
|
|
'style' => 'farm_map_style_dark_green',
|
|
'weight' => 5,
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_ui_actions().
|
|
*/
|
|
function farm_livestock_farm_ui_actions() {
|
|
|
|
// Define farm area actions.
|
|
$actions = array(
|
|
'medical' => array(
|
|
'title' => t('Add a medical record'),
|
|
'href' => 'log/add/farm_medical',
|
|
'assets' => array(
|
|
'animal',
|
|
),
|
|
),
|
|
);
|
|
return $actions;
|
|
}
|
|
|
|
/**
|
|
* 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') {
|
|
return array();
|
|
}
|
|
|
|
// Return a list of Views to include on Animals.
|
|
return array(
|
|
array(
|
|
'name' => 'farm_log_activity',
|
|
'weight' => 0,
|
|
),
|
|
array(
|
|
'name' => 'farm_log_observation',
|
|
'weight' => 10,
|
|
),
|
|
array(
|
|
'name' => 'farm_log_medical',
|
|
'weight' => 20,
|
|
),
|
|
array(
|
|
'name' => 'farm_log_input',
|
|
'weight' => 50,
|
|
),
|
|
array(
|
|
'name' => 'farm_log_harvest',
|
|
'weight' => 60,
|
|
),
|
|
array(
|
|
'name' => 'farm_log_movement',
|
|
'weight' => 100,
|
|
),
|
|
array(
|
|
'name' => 'farm_asset_children',
|
|
'display' => 'page',
|
|
'title' => t('Children'),
|
|
'weight' => 110,
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_taxonomy_term_view_views().
|
|
*/
|
|
function farm_livestock_farm_taxonomy_term_view_views($term) {
|
|
|
|
// Start a list of View names.
|
|
$views = array();
|
|
|
|
// Switch logic depending on the vocabulary.
|
|
switch ($term->vocabulary_machine_name) {
|
|
|
|
// Farm areas:
|
|
case 'farm_areas':
|
|
$views[] = array(
|
|
'name' => 'farm_animals',
|
|
'weight' => -10,
|
|
);
|
|
break;
|
|
|
|
// Farm animal groups:
|
|
case 'farm_animal_groups':
|
|
$views[] = array(
|
|
'name' => 'farm_animals',
|
|
'arg' => 2,
|
|
'always' => TRUE,
|
|
);
|
|
break;
|
|
|
|
// Farm animal types:
|
|
case 'farm_animal_types':
|
|
$views[] = array(
|
|
'name' => 'farm_animals',
|
|
'arg' => 3,
|
|
'always' => TRUE,
|
|
);
|
|
break;
|
|
}
|
|
|
|
return $views;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_area_links().
|
|
*/
|
|
function farm_livestock_farm_area_links($id) {
|
|
$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,
|
|
'href' => 'farm/assets/animals/' . $id,
|
|
);
|
|
}
|
|
|
|
return $links;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_views_post_render().
|
|
*/
|
|
function farm_livestock_views_post_render(&$view, &$output, &$cache) {
|
|
|
|
// If this is the Farm Animals page...
|
|
if ($view->name == 'farm_animals' && $view->current_display == 'page') {
|
|
|
|
// If dashboard maps are disabled in the farm_map module settings, bail.
|
|
if (!variable_get('farm_map_show', TRUE)) {
|
|
return;
|
|
}
|
|
|
|
// If there are any arguments, bail.
|
|
/**
|
|
* @todo
|
|
* Display a map that is filtered by the same arguments.
|
|
*/
|
|
if (!empty($view->args)) {
|
|
return;
|
|
}
|
|
|
|
// If the View result is not empty...
|
|
if (!empty($view->result)) {
|
|
|
|
// Add the Animals asset map to the top of the View.
|
|
$map = \Drupal\openlayers\Openlayers::load('Map', 'farm_assets_animal');
|
|
if (!empty($map)) {
|
|
$map_build = $map->build();
|
|
$output = drupal_render($map_build) . $output;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_log_categories().
|
|
*/
|
|
function farm_livestock_farm_log_categories() {
|
|
|
|
// Provide an "Animals" log category.
|
|
return array('Animals');
|
|
}
|