You are here

class flag_user in Flag 5

Same name and namespace in other branches
  1. 6.2 flag.inc \flag_user
  2. 6 flag.inc \flag_user
  3. 7.3 includes/flag/flag_user.inc \flag_user
  4. 7.2 flag.inc \flag_user

Implements a user flag.

Hierarchy

Expanded class hierarchy of flag_user

1 string reference to 'flag_user'
flag_flag_definitions in ./flag.inc
Implementation of hook_flag_definitions().

File

./flag.inc, line 1094
Implements various flags. Uses object oriented style inspired by that of Views 2.

View source
class flag_user extends flag_flag {
  function default_options() {
    $options = parent::default_options();
    $options += array(
      'show_on_profile' => TRUE,
    );
    return $options;
  }
  function options_form(&$form) {
    parent::options_form($form);
    $form['types'] = array(
      // A user flag doesn't support node types. (Maybe will support roles instead, in the future.)
      '#type' => 'value',
      '#value' => array(
        0 => 0,
      ),
    );
    $form['display']['show_on_profile'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display link on user profile page'),
      '#default_value' => $this->show_on_profile,
      '#access' => empty($this->locked['show_on_profile']),
    );
  }
  function _load_content($content_id) {
    return user_load(array(
      'uid' => $content_id,
    ));
  }
  function applies_to_content_object($user) {

    // This user flag doesn't currently support subtypes so we return TRUE for
    // any user.
    if ($user) {
      return TRUE;
    }
    return FALSE;
  }
  function get_content_id($user) {
    return $user->uid;
  }
  function uses_hook_link($teaser) {
    if ($this->show_on_profile) {
      return TRUE;
    }
    return FALSE;
  }
  function get_labels_token_types() {
    return array(
      'user',
    );
  }
  function replace_tokens($label, $contexts, $content_id) {
    if ($content_id && ($user = $this
      ->fetch_content($content_id))) {
      $contexts['user'] = $user;
    }
    return parent::replace_tokens($label, $contexts, $content_id);
  }
  function get_flag_action($content_id) {
    $flag_action = parent::get_flag_action($content_id);
    $user = $this
      ->fetch_content($content_id);
    $flag_action->content_title = $user->name;
    $flag_action->content_url = _flag_url('user/' . $user->uid);
    return $flag_action;
  }
  function get_relevant_action_objects($content_id) {
    return array(
      'user' => $this
        ->fetch_content($content_id),
    );
  }
  function rules_get_event_arguments_definition() {
    return array(
      'account' => array(
        'type' => 'user',
        'label' => t('flagged user'),
        'handler' => 'flag_rules_get_event_argument',
      ),
    );
  }
  function rules_get_element_argument_definition() {
    return array(
      'type' => 'user',
      'label' => t('Flagged user'),
    );
  }
  function get_views_info() {
    return array(
      'views table' => 'users',
      'join field' => 'uid',
      'title field' => 'name',
      'title' => t('User flag'),
      'help' => t('Limit results to only those users flagged by a certain flag; Or display information about the flag set on a user.'),
      'counter title' => t('User flag counter'),
      'counter help' => t('Include this to gain access to the flag counter field.'),
    );
  }
  function applies_to_content_id_array($content_ids) {

    // This user flag doesn't currently support subtypes so all users are
    // applicable for flagging.
    $passed = array();
    foreach ($content_ids as $uid) {
      if ($uid) {

        // Exclude anonymous.
        $passed[$uid] = TRUE;
      }
    }
    return $passed;
  }

}

Members