mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Page callback for considerations list, filtered for a plan.
This commit is contained in:
parent
e8e439587a
commit
8d95345fcd
|
@ -10,6 +10,17 @@
|
||||||
*/
|
*/
|
||||||
function farm_plan_consideration_menu() {
|
function farm_plan_consideration_menu() {
|
||||||
|
|
||||||
|
// List planning considerations.
|
||||||
|
$items['farm/plan/%farm_plan/considerations'] = array(
|
||||||
|
'title' => 'Considerations',
|
||||||
|
'description' => 'Identify considerations that will affect the planning process.',
|
||||||
|
'page callback' => 'farm_plan_consideration_list',
|
||||||
|
'page arguments' => array(2),
|
||||||
|
'access callback' => 'farm_plan_access',
|
||||||
|
'access arguments' => array('update', 2),
|
||||||
|
'type' => MENU_LOCAL_TASK,
|
||||||
|
);
|
||||||
|
|
||||||
// Add a new consideration.
|
// Add a new consideration.
|
||||||
$items['farm/plan/%farm_plan/considerations/add'] = array(
|
$items['farm/plan/%farm_plan/considerations/add'] = array(
|
||||||
'title' => 'Add a consideration',
|
'title' => 'Add a consideration',
|
||||||
|
@ -192,6 +203,121 @@ function farm_plan_consideration_delete($id) {
|
||||||
db_query('DELETE FROM {farm_plan_consideration_entity} WHERE consideration_id = :id', array(':id' => $id));
|
db_query('DELETE FROM {farm_plan_consideration_entity} WHERE consideration_id = :id', array(':id' => $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page callback for considerations list, filtered for a plan.
|
||||||
|
*
|
||||||
|
* @param $plan
|
||||||
|
* The plan object to filter considerations for..
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* Return the content of the page.
|
||||||
|
*/
|
||||||
|
function farm_plan_consideration_list($plan) {
|
||||||
|
|
||||||
|
// Set the page title.
|
||||||
|
drupal_set_title(t('Considerations'));
|
||||||
|
|
||||||
|
// Create a fieldset for the considerations.
|
||||||
|
$build['considerations'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Planning considerations'),
|
||||||
|
'#description' => t('Use this to define any planning considerations you want to remember. Considerations can be specific to a single plan, or they can apply to all plans.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Define the considerations table header.
|
||||||
|
$header = array(
|
||||||
|
t('Consideration'),
|
||||||
|
t('Type'),
|
||||||
|
t('Start'),
|
||||||
|
t('End'),
|
||||||
|
t('Associations'),
|
||||||
|
t('Actions'),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Load information about all consideration types.
|
||||||
|
$consideration_types = farm_plan_consideration_types();
|
||||||
|
|
||||||
|
// Query all considerations from the database that either apply to all plans,
|
||||||
|
// or are associated with this plan specifically, and build a set of rows for
|
||||||
|
// the table.
|
||||||
|
$rows = array();
|
||||||
|
$result = db_query('SELECT id FROM {farm_plan_consideration} WHERE plan_id IS NULL OR plan_id = :plan_id', array(':plan_id' => $plan->id));
|
||||||
|
foreach ($result as $record) {
|
||||||
|
|
||||||
|
// Load the consideration.
|
||||||
|
$consideration = farm_plan_consideration_load($record->id);
|
||||||
|
|
||||||
|
// If the consideration didn't load, skip it.
|
||||||
|
if (empty($consideration)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanitize the name.
|
||||||
|
$name = check_plain($consideration->name);
|
||||||
|
|
||||||
|
// Get the consideration type label.
|
||||||
|
$type = $consideration->type;
|
||||||
|
if (!empty($consideration_types[$type]['label'])) {
|
||||||
|
$type = $consideration_types[$type]['label'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format the start and end dates.
|
||||||
|
$date_format = 'M j Y';
|
||||||
|
$start = date($date_format, $consideration->start);
|
||||||
|
$end = date($date_format, $consideration->end);
|
||||||
|
|
||||||
|
// If there are entity associations, build a list.
|
||||||
|
$associations = '';
|
||||||
|
$entity_links = array();
|
||||||
|
if (!empty($consideration->entities)) {
|
||||||
|
foreach ($consideration->entities as $type => $ids) {
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$entities = entity_load($type, array($id));
|
||||||
|
if (empty($entities)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$entity = reset($entities);
|
||||||
|
$label = entity_label($type, $entity);
|
||||||
|
$uri = entity_uri($type, $entity);
|
||||||
|
$entity_links[] = l($label, $uri['path']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($entity_links)) {
|
||||||
|
$associations = theme('item_list', array('items' => $entity_links));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the actions.
|
||||||
|
$actions = array();
|
||||||
|
$actions[] = l(t('Edit'), 'farm/plan/' . $plan->id . '/considerations/' . $consideration->id . '/edit');
|
||||||
|
$actions[] = l(t('Delete'), 'farm/plan/' . $plan->id . '/considerations/' . $consideration->id . '/delete');
|
||||||
|
$actions = implode(' | ', $actions);
|
||||||
|
|
||||||
|
// Assemble the row.
|
||||||
|
$row = array(
|
||||||
|
$name,
|
||||||
|
$type,
|
||||||
|
$start,
|
||||||
|
$end,
|
||||||
|
$associations,
|
||||||
|
$actions,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add it to the rows array.
|
||||||
|
$rows[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the table render array.
|
||||||
|
$build['considerations']['table'] = array(
|
||||||
|
'#theme' => 'table',
|
||||||
|
'#header' => $header,
|
||||||
|
'#rows' => $rows,
|
||||||
|
'#empty' => t('No considerations found.'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $build;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the farm plan considerations form.
|
* Build the farm plan considerations form.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue