class UserActivityActionHandler in Activity 7
Activity Action Handler for the user triggers.
Hierarchy
- class \ActivityActionHandler
- class \UserActivityActionHandler
 
 
Expanded class hierarchy of UserActivityActionHandler
1 string reference to 'UserActivityActionHandler'
- user_activity_api in ./
activity.module  - Implements hook_activity_api().
 
File
- ./
activity_action_handlers.inc, line 733  
View source
class UserActivityActionHandler extends ActivityActionHandler {
  /**
   * Return an array of message types.
   */
  protected function messages() {
    $messages = parent::messages();
    if ($this->type == 'user_update') {
      $messages['current_user'] = array(
        'title' => 'Updating User',
        'description' => 'The user doing the updating',
      );
    }
    $messages['user'] = array(
      'title' => 'User Account',
      'description' => 'User account that the action is applied to',
    );
    return $messages;
  }
  /**
   * Load objects for tokenization.
   *
   * @param int $eid
   *   The entity identifier for this Activity.
   *
   * @return array
   */
  public function loadObjects($eid) {
    return array(
      'user' => user_load($eid),
    );
  }
  /**
   * Return the eid field for this Activity. The user involved with hook_user_*
   *
   * @param array $context
   *  The context argument passed into the action callback.
   *
   * @return int
   */
  public function determineEid($context) {
    return $context['user']->uid;
  }
  /**
   * Return the uid that is responsible for this action.
   *
   * @param array $objects
   *  The objects used in tokenization
   *
   * @return int
   */
  public function determineActor($objects) {
    if ($this->type == 'user_update') {
      return $GLOBALS['user']->uid;
    }
    return $objects['user']->uid;
  }
  /**
   * Return the timestamp that this Activity happened at.
   *
   * @param array $objects
   *   The objects used in tokenization.
   *
   * @return int
   */
  public function determineTimestamp($objects) {
    if ($this->type == 'user_insert') {
      return $objects['user']->created;
    }
    return REQUEST_TIME;
  }
  /**
   * Return whether or not the Activity is published.
   *
   * @param array $objects
   *   The objects used in tokenization.
   * @param int $actor
   *   The actor for this activity.
   */
  public function isPublished($objects, $actor) {
    $user_active = $objects['user']->status == 1;
    if ($this->type != 'user_insert') {
      return $user_active && parent::isPublished($objects, $actor);
    }
    return $user_active;
  }
  /**
   * Return option defaults and structure.
   *
   * @return array.
   */
  public function optionDefinition() {
    $options = parent::optionDefinition();
    $options['roles'] = array(
      '#default_value' => array(),
    );
    return $options;
  }
  /**
   * Display an FAPI form.
   *
   * @param &$form
   *   An FAPI form array.
   * @param $form_state
   *   The form_state from FAPI.
   */
  public function optionForm(&$form, $form_state) {
    parent::optionForm($form, $form_state);
    $roles = user_roles();
    $form['roles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Roles'),
      '#options' => $roles,
      '#default_value' => $this->options['roles'],
    );
  }
  /**
   * Determine if the current Action is valid for this object.
   *
   * @param $eid
   *   The entity id for the activity.
   * @param $actor
   *   The uid of the actor for this activity.
   * @param $timestamp
   *   Unix timestamp when this activity occurred.
   * @param array $objects
   *   The collection of objects for this action.
   * @param mixed $argument1
   *   The first argument passed to the action callback.
   * @param mixed $argument2
   *   The second argument passed to the action callback.
   *
   * @return boolean
   */
  public function valid($eid, $actor, $timestamp, $objects, $argument1, $argument2) {
    $roles = array_filter($this->options['roles']);
    if (!empty($roles)) {
      $user_roles = array_keys($objects['user']->roles);
      $intersect = array_intersect($user_roles, $roles);
      return parent::valid($eid, $actor, $timestamp, $objects, $argument1, $argument2) && !empty($intersect);
    }
    return parent::valid($eid, $actor, $timestamp, $objects, $argument1, $argument2);
  }
  /**
   * 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) {
    $roles = array_filter($this->options['roles']);
    $query = db_select('users', 'u')
      ->fields('u', array(
      'uid',
    ), 'eid')
      ->condition('u.uid', 0, '<>')
      ->range($offset, $limit);
    if (!empty($roles)) {
      $roles_alias = $query
        ->join('users_roles', 'r', 'r.uid = u.uid');
      $query
        ->condition($roles_alias . '.rid', $roles, 'IN');
    }
    $count_query = clone $query;
    $total = $count_query
      ->countQuery()
      ->execute()
      ->fetchField();
    $arguments = array();
    foreach ($query
      ->execute()
      ->fetchCol() as $eid) {
      $arguments[$eid] = array(
        'argument1' => NULL,
        'argument2' => NULL,
      );
    }
    return array(
      'total' => $total,
      'arguments' => $arguments,
    );
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            ActivityActionHandler:: | 
                  public | property | {actions}.aid for the template. | |
| 
            ActivityActionHandler:: | 
                  public | property | Boolean indicating if this handler can do batch operations. | |
| 
            ActivityActionHandler:: | 
                  public | property | {actions}.label for the template. | |
| 
            ActivityActionHandler:: | 
                  public | property | Options provided via the optionsFrom and optionsDefinition methods. | |
| 
            ActivityActionHandler:: | 
                  public | property | Templates created by the administrator. | |
| 
            ActivityActionHandler:: | 
                  public | property | Type of activity. | |
| 
            ActivityActionHandler:: | 
                  public static | function | Generates the default options from the provided option definition. | |
| 
            ActivityActionHandler:: | 
                  public | function | Return the nid of this Activity. | |
| 
            ActivityActionHandler:: | 
                  protected | function | Return the user id that matches the provided key in the templates. | 1 | 
| 
            ActivityActionHandler:: | 
                  public | function | Display the token message form. | |
| 
            ActivityActionHandler:: | 
                  public | function | Tokenize based on the provided objects | |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Return the uid that is responsible for this action. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Return the eid field for this Activity. The user involved with hook_user_* Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Return the timestamp that this Activity happened at. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Return whether or not the Activity is published. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            List all eids for this handler, used for batch regeneration and backfilling. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Load objects for tokenization. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  protected | function | 
            Return an array of message types. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Return option defaults and structure. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Display an FAPI form. Overrides ActivityActionHandler:: | 
                  |
| 
            UserActivityActionHandler:: | 
                  public | function | 
            Determine if the current Action is valid for this object. Overrides ActivityActionHandler:: |