function merci_build_reservation_table_form in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6
Same name and namespace in other branches
- 6.2 merci.module \merci_build_reservation_table_form()
- 7.2 merci.module \merci_build_reservation_table_form()
Builds the table of existing reserved items.
Parameters
$form_state: Current form state.
$node: The reservation node.
$edit_page: TRUE if the table is on the edit page for the reservation, FALSE otherwise.
Return value
The form array.
1 call to merci_build_reservation_table_form()
- merci_form in ./
merci.module - Implementation of hook_form().
1 string reference to 'merci_build_reservation_table_form'
- merci_view in ./
merci.module - Implementation of hook_view().
File
- ./
merci.module, line 1919 - MERCI - Managed Equipment Reservation Checkout and Inventory
Code
function merci_build_reservation_table_form(&$form_state, $node, $edit_page = FALSE) {
$form = array();
$form['#theme'] = 'merci_build_reservation_table_form';
$form['#node'] = $node;
$form['#tree'] = TRUE;
$form['#table'] = array();
$form['#header'] = array(
t('Item'),
t('Type'),
t('Operations'),
);
$reservation_items = array();
$items = $node->merci['reservation_items'];
foreach ($items as $did => $item) {
// Use item title, fall back to bucket/resource content type name.
$title = isset($item->ttitle) ? $item->ttitle : $item->name;
$nid = isset($item->tnid) ? $item->tnid : $item->pnid;
$operations = '';
$placeholder_node = node_load($item->pnid);
if (node_access('update', $placeholder_node)) {
if (merci_has_accessories($item->type)) {
$operations .= '<span class="edit-details" id="merci-id-' . $item->pnid . '">' . l(t('Add accessories'), "node/{$item->pnid}/edit", array(
'query' => drupal_get_destination(),
)) . '</span>';
}
}
if ($edit_page && node_access('delete', $placeholder_node)) {
$operations .= ' ' . l(t('delete'), "node/{$item->pnid}/delete", array(
'query' => drupal_get_destination(),
));
}
$merci_settings = merci_load_content_type_settings($item->type);
// Only MERCI admins can change the bucket item assignment.
if ($edit_page && user_access('administer MERCI') && $merci_settings->type_setting == 'bucket') {
$options = array(
0 => t('<Select>'),
);
$default = isset($item->tnid) ? $item->tnid : 0;
$options += merci_get_available_bucket_items($node, $item->type);
$form['items'][$did] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $default,
);
}
else {
$form['items'][$did] = array(
'#type' => 'value',
'#value' => $item->tnid,
);
$form['#table'][$did]['display_item'] = l($title, "node/{$item->pnid}");
}
$form['placeholders'][$did] = array(
'#type' => 'value',
'#value' => $item->pnid,
);
$bucket_resource = $merci_settings->type_setting == 'bucket' ? $item->type : $item->tnid;
$form['bucket_resource'][$did] = array(
'#type' => 'value',
'#value' => $bucket_resource,
);
$form['#table'][$did]['type'] = check_plain($item->name);
$form['#table'][$did]['ops'] = $operations;
}
return $form;
}