function nodereference_count_references_update in Nodereference Count 7
Identify counted node references on a node and trigger an update of the referenced nodes.
Parameters
$node: The node object.
$delay: Whether the actual count update should be delayed. See the hook_node_delete implementation above for more info.
3 calls to nodereference_count_references_update()
- nodereference_count_node_delete in ./
nodereference_count.module - Implements hook_node_delete().
- nodereference_count_node_insert in ./
nodereference_count.module - Implements hook_node_insert().
- nodereference_count_node_update in ./
nodereference_count.module - Implements hook_node_update().
File
- ./
nodereference_count.module, line 361 - Defines a field type for counting the references to a node.
Code
function nodereference_count_references_update($node, $delay = FALSE) {
// Get all the node reference fields for this content type.
$nodereference_fields = nodereference_count_get_nodereference_fields($node->type);
// If there are no node references for this content type then there is nothing to count.
if (empty($nodereference_fields)) {
return;
}
// Get all the node reference fields for this content type that are counted by a nodereference count field.
$counted_fields = nodereference_count_get_counted_nodereference_fields($nodereference_fields);
// If there are no node references being counted for this content type then there is nothing to count.
if (empty($counted_fields)) {
return;
}
// Get all the nids that need to be updated.
$nids = nodereference_count_get_referenced_nids($node, $counted_fields);
// Update the counts on the referenced nodes.
foreach ($nids as $nid) {
// Wait to update the count for this nid.
if ($delay) {
nodereference_count_delayed_nids($nid);
}
else {
nodereference_count_update_count($nid);
}
}
}