You are here

class CommentActivityActionHandler in Activity 7

Activity handler for the comment module. Extends the node handler has it presents a lot of the same things, just more.

Hierarchy

Expanded class hierarchy of CommentActivityActionHandler

1 string reference to 'CommentActivityActionHandler'
comment_activity_api in ./activity.module
Implements hook_activity_api().

File

./activity_action_handlers.inc, line 588

View source
class CommentActivityActionHandler extends NodeActivityActionHandler {

  /**
   * Load objects for tokenization.
   *
   * @param int $eid
   *   The entity identifier for this Activity.
   *
   * @return array
   */
  public function loadObjects($eid) {
    $objects = array();
    $objects['comment'] = comment_load($eid);
    $objects['node'] = node_load($objects['comment']->nid);
    return $objects;
  }

  /**
   * Return the eid field for this Activity.
   *
   * @param array $context
   *  The context arguments passed into the action callback.
   *
   * @return int
   */
  public function determineEid($context) {
    return $context['comment']->cid;
  }

  /**
   * Return the uid that is responsible for this action.
   *
   * @param array $objects
   *  The objects used in tokenization
   *
   * @return int
   */
  public function determineActor($objects) {
    return $objects['comment']->uid;
  }

  /**
   * Return the timestamp that this Activity happened at.
   *
   * @param array $objects
   *   The objects used in tokenization.
   *
   * @return int
   */
  public function determineTimestamp($objects) {
    return $objects['comment']->created;
  }

  /**
   * Return whether or not the Activity is published.
   *
   * @param array $objects
   *   The objects used in tokenization.
   * @param int $actor
   *   The actor for the activity.
   */
  public function isPublished($objects, $actor) {
    return parent::isPublished($objects, $actor) && $objects['comment']->status;
  }

  /**
   * Return an array of message types.
   */
  protected function messages() {
    $messages = parent::messages();
    $messages['comment'] = array(
      'title' => 'Comment Author',
      'description' => 'The author of the comment',
    );
    $messages['node_comment'] = array(
      'title' => 'Comment and Node Author',
      'description' => 'When both the comment and the node author are the same display this message',
    );
    return $messages;
  }

  /**
   * Return the user id that matches the provided key in the templates.
   *
   * @param string $key
   *   The message key.
   * @param array $objects
   *   All the objects for the Activity.
   *
   * @return int
   */
  protected function getUid($key, $objects) {
    if ($key == 'public') {
      return 0;
    }
    elseif ($key == 'current_user') {
      return $GLOBALS['user']->uid;
    }
    elseif ($key == 'node_comment' && $objects['node']->uid == $objects['comment']->uid) {
      return $objects['comment']->uid;
    }
    if (isset($objects[$key]) && isset($objects[$key]->uid)) {
      return $objects[$key]->uid;
    }
    return FALSE;
  }

  /**
   * List all eids for this handler, used for batch regeneration and backfilling.
   *
   * @param int $offset
   *   The offset for the query.
   * @param int $limit
   *   The limit for the query.
   */
  public function listEids($offset, $limit) {
    $types = array_filter($this->options['types']);
    $query = db_select('comment', 'c')
      ->fields('c', array(
      'cid',
    ), 'eid');
    if (!empty($types)) {
      $node_alias = $query
        ->join('node', 'n', 'n.nid = c.nid');
      $query
        ->condition($node_alias . '.type', $types, 'IN');
    }
    $count_query = clone $query;
    $total = $count_query
      ->countQuery()
      ->execute()
      ->fetchField();
    $query
      ->range($offset, $limit);
    $arguments = array();
    foreach ($query
      ->execute()
      ->fetchCol() as $eid) {
      $arguments[$eid] = array(
        'argument1' => NULL,
        'argument2' => NULL,
      );
    }
    return array(
      'total' => $total,
      'arguments' => $arguments,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActivityActionHandler::$actions_id public property {actions}.aid for the template.
ActivityActionHandler::$batch public property Boolean indicating if this handler can do batch operations.
ActivityActionHandler::$label public property {actions}.label for the template.
ActivityActionHandler::$options public property Options provided via the optionsFrom and optionsDefinition methods.
ActivityActionHandler::$templates public property Templates created by the administrator.
ActivityActionHandler::$type public property Type of activity.
ActivityActionHandler::defaultOptions public static function Generates the default options from the provided option definition.
ActivityActionHandler::determineNid public function Return the nid of this Activity.
ActivityActionHandler::messagesForm public function Display the token message form.
ActivityActionHandler::tokenize public function Tokenize based on the provided objects
CommentActivityActionHandler::determineActor public function Return the uid that is responsible for this action. Overrides NodeActivityActionHandler::determineActor
CommentActivityActionHandler::determineEid public function Return the eid field for this Activity. Overrides NodeActivityActionHandler::determineEid
CommentActivityActionHandler::determineTimestamp public function Return the timestamp that this Activity happened at. Overrides NodeActivityActionHandler::determineTimestamp
CommentActivityActionHandler::getUid protected function Return the user id that matches the provided key in the templates. Overrides ActivityActionHandler::getUid
CommentActivityActionHandler::isPublished public function Return whether or not the Activity is published. Overrides NodeActivityActionHandler::isPublished
CommentActivityActionHandler::listEids public function List all eids for this handler, used for batch regeneration and backfilling. Overrides NodeActivityActionHandler::listEids
CommentActivityActionHandler::loadObjects public function Load objects for tokenization. Overrides NodeActivityActionHandler::loadObjects
CommentActivityActionHandler::messages protected function Return an array of message types. Overrides NodeActivityActionHandler::messages
NodeActivityActionHandler::optionDefinition public function Return option defaults and structure. Overrides ActivityActionHandler::optionDefinition
NodeActivityActionHandler::optionForm public function Display an FAPI form. Overrides ActivityActionHandler::optionForm
NodeActivityActionHandler::valid public function Determine if the current Action is valid for this object. Overrides ActivityActionHandler::valid