You are here

protected function HeartbeatStream::checkAccess in Heartbeat 7

Function to check access on messages This behaviour is set by a heartbeat message configuration to overrule the chosen display access type

1 call to HeartbeatStream::checkAccess()
HeartbeatStream::execute in includes/heartbeatstream.inc
Function that reorganizes a query result of messages into a stream of heartbeat activity objects.

File

includes/heartbeatstream.inc, line 738
HeartbeatStream object is the object that takes stream configuration to create a stream of activity objects. It is the controlling organ at the pre-query, query and post-query phases.

Class

HeartbeatStream
Abstract class HeartbeatStream This base class has final template methods which are used by the derived concretes. The HeartbeatStream is a state object that is given to the HeartbeatStreamBuilder to set the access to the current request.

Code

protected function checkAccess(&$messages) {

  // This hook is invoked BEFORE calculating the maximum
  // number of messages to show,
  // giving other modules the opportunity to remove messages
  // based on their own parameters and custom reasons.
  $hook = 'heartbeat_messages_alter';
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    $result = $function($messages, $this);
  }
  foreach ($messages as $key => $message) {

    // Check node access if information is available.
    if (!empty($message->nid) && !empty($message->variables['node_type'])) {
      $dummy_node = new stdClass();
      $dummy_node->nid = $message->nid;
      $dummy_node->uid = $message->variables['node_uid'];
      $dummy_node->status = $message->variables['node_status'];
      $dummy_node->type = $message->variables['node_type'];
      if (!node_access('view', $dummy_node)) {
        unset($messages[$key]);
        continue;
      }
    }

    // Check node target access if information is available.
    if (!empty($message->nid_target) && !empty($message->variables['node_target_type'])) {
      $dummy_node = new stdClass();
      $dummy_node->nid = $message->nid_target;
      $dummy_node->uid = $message->variables['node_target_uid'];
      $dummy_node->status = $message->variables['node_target_status'];
      $dummy_node->type = $message->variables['node_target_type'];
      if (!node_access('view', $dummy_node)) {
        unset($messages[$key]);
      }
    }
  }
}