You are here

class OgHeartbeat in Heartbeat 6.4

Class OgHeartbeat Concrete class to prepare messages for the current user and all of his/her relations.

Hierarchy

Expanded class hierarchy of OgHeartbeat

1 string reference to 'OgHeartbeat'
og_activity_heartbeat_register_access_types in modules/og_activity/og_activity.module
Implementation of hook_heartbeat_register_access_types()

File

modules/og_activity/ogheartbeat.inc, line 17

View source
class OgHeartbeat extends HeartbeatAccess {
  protected $_gid = 0;
  protected $_group_access = FALSE;
  protected $group = NULL;
  public function construct() {

    // Where the user id is a member of the group
    // and where the nid target is the group nid
    $this
      ->setGroup();
  }

  /**
   * Skip active user.
   * We never want to skip the active user.
   */
  public function skipActiveUser() {
    return FALSE;
  }

  /**
   * hasAccess
   *
   * Checks access for this stream.
   */
  protected function hasAccess() {

    // If the user has access to this node (member or public group).
    if (isset($this->group) && (og_is_group_member($this->group) || $this->group->og_private == 0)) {
      $this->_group_access = TRUE;
    }
    if (!isset($this->group)) {
      $this
        ->setError('We are not in a group context.');
    }
    return $this->_group_access;
  }

  /**
   * getGroup
   */
  public function getGroup() {
    return $this->group;
  }

  /**
   * setGroup
   *
   * Sets the group for a given node ID.
   * @param Integer $nid
   *   The group node ID.
   */
  private function setGroup($nid = 0) {

    // Set the group by nid argument.
    if ($nid != 0) {
      $this->_gid = $nid;
      $this->group = node_load($nid);
      return;
    }
    elseif (!empty($_REQUEST['group_nid'])) {
      $this->_gid = $_REQUEST['group_nid'];
      $this->group = node_load($this->_gid);
    }

    // Set the group from the space.
    if (module_exists('spaces_og')) {
      if ($space = spaces_get_space()) {
        if ($space->type == 'og') {
          $this->_gid = $space->id;
          $this->group = $space->group;
          return;
        }
      }
    }

    // Set the group via current group context.
    if ($group = og_get_group_context()) {
      $this->_gid = $group->nid;
      $this->group = $group;
      return;
    }

    // Try to set the group from the node ID.
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      if ($node = node_load(arg(1))) {
        if (og_is_group_type($node->type)) {
          $this->_gid = $node->nid;
          $this->group = $node;
          return;
        }
        elseif (og_is_group_post_type($node->type)) {
          $this->_gid = current($node->og_groups);
          $this->group = node_load($this->_gid);
          return;
        }
      }
    }
  }

  /**
   * dressUpMessages
   *
   * @param HeartbeatParser $heartbeat
   *   The parser for the messages in this stream.
   */
  public function dressUpMessages(HeartbeatParser $heartbeat) {
    $sql = " AND ua.nid <> 0 AND (ua.nid = %d OR ua.nid_target = %d) ";
    $heartbeat->raw_messages = $this
      ->resultSql($sql, array(
      $this->_gid,
      $this->_gid,
    ));
    return $heartbeat;
  }

  /**
   * Function to add a part of a sql to a query built by views UI
   *
   * @param object $view The view handler object by reference to add our part to the query
   */
  public function addViewQuery(&$view) {

    // Make the sql limited to the access
    $field = "{$view->table_alias}.{$view->real_field}";
    $view->query
      ->set_where_group('AND', 'extra');
    $sql = "{$view->table_alias}.nid <> 0 AND ( {$view->table_alias}.nid = %d OR {$view->table_alias}.nid_target = %d ) ";
    $view->query
      ->add_where('extra', $sql, $this->_gid, $this->_gid);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HeartbeatAccess::$stream public property
HeartbeatAccess::$_actor protected property
HeartbeatAccess::$_errors protected property
HeartbeatAccess::$_has_errors protected property
HeartbeatAccess::$_offset_sql protected property
HeartbeatAccess::$_page protected property
HeartbeatAccess::$_uid protected property
HeartbeatAccess::$_whoisuser_type protected property
HeartbeatAccess::$_whoisuser_types protected property
HeartbeatAccess::checkDeniedMessages protected function Check denied messages
HeartbeatAccess::configurationForm public function ConfigurationForm Basic configuration form for streams.
HeartbeatAccess::createHeartbeatParser protected function createHeartbeatParser
HeartbeatAccess::fetchMessages public function
HeartbeatAccess::finishMessages protected function finishMessages
HeartbeatAccess::getAccess final public function getAccess
HeartbeatAccess::getActiveUser public function Function to retrieve the active user.
HeartbeatAccess::getErrors public function
HeartbeatAccess::getOffsetSql final public function getOffsetSql
HeartbeatAccess::getStream public function Get HeartbeatStream object with all configurations
HeartbeatAccess::hasErrors public function hasErrors
HeartbeatAccess::isPage public function Getter function for heartbeat page/blocks
HeartbeatAccess::prepareStream protected function prepareStream 2
HeartbeatAccess::resultSql protected function resultSql 1
HeartbeatAccess::setError protected function setError
HeartbeatAccess::setOffsetSql final public function setOffsetSql
HeartbeatAccess::TYPE_ACTOR constant
HeartbeatAccess::TYPE_USER_PROFILE constant
HeartbeatAccess::whoIsActor protected function proctected fuinction whoIsActor Calculate the user of whom we want to see activity for. Set the actor of the stream. 1
HeartbeatAccess::__construct public function Constructor
OgHeartbeat::$group protected property
OgHeartbeat::$_gid protected property
OgHeartbeat::$_group_access protected property
OgHeartbeat::addViewQuery public function Function to add a part of a sql to a query built by views UI Overrides HeartbeatAccess::addViewQuery
OgHeartbeat::construct public function Fake constructor to hook this method instead of the constructor. Overrides HeartbeatAccess::construct
OgHeartbeat::dressUpMessages public function dressUpMessages Overrides HeartbeatAccess::dressUpMessages
OgHeartbeat::getGroup public function getGroup
OgHeartbeat::hasAccess protected function hasAccess Overrides HeartbeatAccess::hasAccess
OgHeartbeat::setGroup private function setGroup
OgHeartbeat::skipActiveUser public function Skip active user. We never want to skip the active user. Overrides HeartbeatAccess::skipActiveUser