function get_nodes in Module Grants 6
Retrieve a list of nodes or revisions accessible to the logged-in user via the supplied operation.
@todo Allow paging, improve performance
Parameters
$op: Operation, one of 'view', 'edit' or 'delete'
$pending: Boolean indicating whether only pending or all nodes should be returned; a pending node is defined as a node that has a revision newer than the current.
Return value
An array of node objects each containing nid, content type, published flag, user id title+vid+user_id+timestamp of the current revision, plus taxonomy term(s) and workflow state, if these modules are installed and enabled.
2 calls to get_nodes()
- theme_module_grants_editable_nodes in ./
module_grants.module - Display in a table a summary of all content editable to the logged-in user.
- theme_module_grants_viewable_nodes in ./
module_grants.module - Display in a table a summary of all content viewable to the logged-in user.
File
- ./
module_grants.module, line 332 - Module to enable access control for unpublished content. Also makes sure that modules that operate on access grants behave in the expected way when enabled together.
Code
function get_nodes($op, $pending = FALSE) {
$sql_select = 'SELECT n.nid, n.type, n.status, r.title, r.uid, r.timestamp';
$sql_from = ' FROM {node} n INNER JOIN {node_revisions} r ' . ($pending ? 'ON n.nid=r.nid' : 'ON n.vid=r.vid');
$sql_where = $pending ? ' WHERE r.vid>n.vid OR (r.vid=n.vid AND n.status=0)' : '';
$sql_order = ' ORDER BY r.timestamp DESC';
$include_taxonomy_terms = module_exists('taxonomy');
$include_workflow_state = module_exists('workflow');
if ($include_taxonomy_terms) {
$sql_select .= ', td.name AS term';
$sql_from .= ' LEFT JOIN {term_node} tn ON n.vid=tn.vid LEFT JOIN {term_data} td ON tn.tid=td.tid';
}
if ($include_workflow_state) {
$sql_select .= ', ws.state';
$sql_from .= ' LEFT JOIN {workflow_node} wn ON wn.nid=n.nid LEFT JOIN {workflow_states} ws ON wn.sid=ws.sid';
}
$sql = $sql_select . $sql_from . $sql_where . $sql_order;
$node_query_result = db_query_range($sql, 0, 1000);
$nodes = array();
while ($node = db_fetch_object($node_query_result)) {
if (module_grants_node_access($op, $node)) {
// @todo rework into a single query from hell?
if (empty($nodes[$node->nid])) {
$nodes[$node->nid] = $node;
}
elseif ($include_taxonomy_terms && !empty($node->term)) {
// If a node has more than one taxonomy term, these will be returned by
// the query as seperate objects differing only in their term.
$existing_node = $nodes[$node->nid];
$existing_node->term .= '/' . $node->term;
}
}
}
return $nodes;
}