mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
163 lines
3.4 KiB
Text
163 lines
3.4 KiB
Text
<?php
|
|
/**
|
|
* @file
|
|
* Code for the Farm Livestock feature.
|
|
*/
|
|
|
|
include_once 'farm_livestock.features.inc';
|
|
|
|
/**
|
|
* 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' => 30,
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_admin_actions().
|
|
*/
|
|
function farm_livestock_farm_admin_actions() {
|
|
|
|
// Define farm area actions.
|
|
$actions = array(
|
|
'animal' => array(
|
|
'title' => t('Add an animal'),
|
|
'href' => 'farm/asset/add/animal',
|
|
'views' => array(
|
|
'farm_animals',
|
|
),
|
|
),
|
|
'animal_group' => array(
|
|
'title' => t('Add a group'),
|
|
'href' => 'admin/structure/taxonomy/farm_animal_groups/add',
|
|
'views' => array(
|
|
'farm_animal_groups',
|
|
),
|
|
),
|
|
'animal_type' => array(
|
|
'title' => t('Add a type'),
|
|
'href' => 'admin/structure/taxonomy/farm_animal_types/add',
|
|
'views' => array(
|
|
'farm_animal_types',
|
|
),
|
|
),
|
|
);
|
|
return $actions;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_asset_breadcrumb().
|
|
*/
|
|
function farm_livestock_farm_asset_breadcrumb($farm_asset) {
|
|
|
|
// If the asset is an animal, add a link to the animals list.
|
|
$breadcrumb = array();
|
|
if ($farm_asset->type == 'animal') {
|
|
$breadcrumb[] = l(t('Animals'), 'farm/animals');
|
|
}
|
|
return $breadcrumb;
|
|
}
|
|
|
|
/**
|
|
* 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(
|
|
'farm_log_activity',
|
|
'farm_log_observation',
|
|
'farm_log_movement',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_taxonomy_breadcrumb().
|
|
*/
|
|
function farm_livestock_farm_taxonomy_breadcrumb($term) {
|
|
$breadcrumb = array();
|
|
|
|
// Switch through available vocabularies.
|
|
switch ($term->vocabulary_machine_name) {
|
|
|
|
// If the term is in farm_animal_groups...
|
|
case 'farm_animal_groups':
|
|
$breadcrumb[] = l(t('Animals'), 'farm/animals');
|
|
$breadcrumb[] = l(t('Animal Groups'), 'farm/animals/groups');
|
|
break;
|
|
|
|
// If the term is in farm_animal_types...
|
|
case 'farm_animal_types':
|
|
$breadcrumb[] = l(t('Animals'), 'farm/animals');
|
|
$breadcrumb[] = l(t('Animal Types'), 'farm/animals/types');
|
|
break;
|
|
|
|
}
|
|
|
|
return $breadcrumb;
|
|
}
|
|
|
|
/**
|
|
* 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,
|
|
);
|
|
break;
|
|
|
|
// Farm animal types:
|
|
case 'farm_animal_types':
|
|
$views[] = array(
|
|
'name' => 'farm_animals',
|
|
'arg' => 3,
|
|
);
|
|
break;
|
|
}
|
|
|
|
return $views;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_area_links().
|
|
*/
|
|
function farm_livestock_farm_area_links($id) {
|
|
return array(
|
|
array(
|
|
'title' => t('Animals'),
|
|
'href' => 'taxonomy/term/' . $id,
|
|
'options' => array(
|
|
'fragment' => 'Animals',
|
|
),
|
|
),
|
|
);
|
|
}
|