function book_copy_can_copy in Book Copy 6
Given a book id and an optional subtree (nid) this function determines if the user can copy the given book.
Parameters
$bid the book nid in question:
$subtree optional if non-zero then the subtree pertainind to the nid supplied: will be checked
$data an optional array where results will be saved. This will track why a user: may not be able to copy a book or book sub-tree.
Return value
TRUE if the user can copy the book FALSE otherwise
2 calls to book_copy_can_copy()
- book_copy_explain in ./
book_copy.module - book_copy_link in ./
book_copy.module - Implementatin of hook_link()
1 string reference to 'book_copy_can_copy'
- book_copy_menu in ./
book_copy.module - implementation of hook_menu
File
- ./
book_copy.module, line 432
Code
function book_copy_can_copy($bid, $subtree = 0, &$data = array()) {
if (is_object($bid)) {
$bid = $bid->book['bid'];
}
if (is_object($subtree)) {
$subtree = $subtree->nid;
}
$nodes = book_copy_find_subtree($bid, $subtree);
$data = array();
$data['headers'] = array(
'node' => t('Book page'),
'filter' => t('Input format'),
'create' => t('Create node type'),
);
$can_copy = TRUE;
if (user_access('copy books')) {
if (!empty($nodes)) {
foreach ($nodes as $nid) {
$node = node_load(array(
'nid' => $nid,
));
$data[$nid]['node'] = l($node->title, 'node/' . $nid);
if (!filter_access($node->format)) {
$can_copy = FALSE;
$data[$nid]['filter']['status'] = FALSE;
$data[$nid]['filter']['message'] = $node->format;
}
else {
$data[$nid]['filter']['status'] = TRUE;
}
if (!node_access('create', $node->type)) {
$can_copy = FALSE;
$data[$nid]['create']['status'] = FALSE;
$data[$nid]['create']['message'] = $node->type;
}
else {
$data[$nid]['create']['status'] = TRUE;
}
}
return $can_copy;
}
}
else {
return FALSE;
}
}