You are here

class activity_views_handler_field_serial in Activity 6

Hierarchy

Expanded class hierarchy of activity_views_handler_field_serial

1 string reference to 'activity_views_handler_field_serial'
activity_views_data in ./activity.views.inc
Implementation of hook_views_data().

File

views/activity_views_handler_field_serial.inc, line 3

View source
class activity_views_handler_field_serial extends views_handler_field {
  function options_form(&$form, &$form_state) {
    $form['label'] = array(
      '#type' => 'textfield',
      '#title' => t('Label'),
      '#default_value' => isset($this->options['label']) ? $this->options['label'] : '',
      '#description' => t('The label for this field that will be displayed to end users if the style requires it.'),
    );
    $form['exclude'] = array(
      '#type' => 'checkbox',
      '#title' => t('Exclude from display'),
      '#default_value' => $this->options['exclude'],
      '#description' => t('Check this box to not display this field, but still load it in the view.  Use this option to not show a grouping field in each record, or when doing advanced theming.'),
    );
    $form['link_object'] = array(
      '#type' => 'radios',
      '#title' => t('Link to object'),
      '#description' => t('Link to the user id or node id'),
      '#default_value' => $form_state['values']['link_object'] ? $form_state['values']['link_object'] : 1,
      '#options' => array(
        0 => t('No'),
        1 => t('Yes'),
      ),
    );
    $form['target_role'] = array(
      '#type' => 'radios',
      '#title' => t('Target Role'),
      '#description' => t('The target role that the message is visible to.'),
      '#default_value' => $form_state['values']['target_role'] ? $form_state['values']['target_role'] : 'all',
      '#options' => array(
        'all' => t('All'),
        'author' => t('Author'),
      ),
      '#multiple' => TRUE,
    );
    return $form;
  }
  function options_submit(&$form, &$form_state) {
  }
  function render($values) {
    $value = $values->{$this->field_alias};
    $row = array();
    $row = unserialize($value);
    if (isset($values->aid) && isset($values->users_activity_uid) && isset($values->activity_module) && isset($values->activity_created) && isset($values->activity_operation) && isset($values->activity_type)) {
      $row['aid'] = $values->aid;
      $row['uid'] = $values->users_activity_uid;
      $row['module'] = $values->activity_module;
      $row['created'] = $values->activity_created;
      $row['operation'] = $values->activity_operation;
      $row['type'] = $values->activity_type;
      $row['target_role'] = $this->options['target_role'];
      $row['target_uid'] = $values->users_activity_uid;
      $activity[] = $row;
      activity_invoke_activityapi($activity, 'load');
      $var = "{$values->activity_module}_{$values->activity_type}_{$values->activity_operation}_{$this->options['target_role']}";
      activity_invoke_activityapi($activity, 'render');
      $message = token_replace(variable_get($var, FALSE), $values->activity_module, $row);
      return token_replace($message, 'activity', $row);
    }
    $ret = $value;

    //FIXME: if there are no matches, then it displays the entire serialized object.

    /* FIXME: This is a basic outline for displaying the serialized data field.
       At the moment it only displays a link to the node, user, etc... Unless
       the object is deleted, in which case it just displays the id number. */
    if (isset($data['content-id']) && $this->options['link_object'] == 1) {
      $node = node_load($data['content-id']);
      if ($node->nid) {
        $ret = l($node->title, 'node/' . $node->nid);
      }
      else {
        $ret = $data['content-id'];
      }
    }
    else {
      if (isset($data['target-uid']) && $this->options['link_object'] == 1) {
        $usr = user_load($data['target-uid']);
        if ($usr->uid) {
          $ret = l($usr->name, 'user/' . $usr->uid);
        }
        else {
          $ret = $data['target-uid'];
        }
      }
      else {
        if (isset($data['node-id']) && $this->options['link_object'] == 1) {
          $node = node_load($data['node-id']);
          if ($node->nid) {
            $ret = l($data['node-title'], 'node/' . $data['node-id']);
          }
          else {
            $ret = $data['node-id'];
          }
        }
        else {
          if (isset($data['comment-cid']) && $this->options['link_object'] == 1) {
            $node = node_load($data['parent-node-id']);
            $c = _comment_load($data['comment-cid']);

            // FIXME: we shouldn't be using this function
            if ($node->nid && $c->cid) {
              $ret = l($data['comment-subject'], 'node/' . $data['parent-node-id'] . '/comment-' . $data['comment-cid']);
            }
            else {
              if ($node->id && !$c->cid) {
                $ret = l($data['comment-subject'], 'node/' . $data['parent-node-id']);
              }
              else {
                $ret = $data['parent-node-id'] . ' comment #' . $data['comment-cid'];
              }
            }
          }
        }
      }
    }
    return $ret;
  }

}

Members