You are here

function activity_views_handler_field_serial::render in Activity 6

File

views/activity_views_handler_field_serial.inc, line 42

Class

activity_views_handler_field_serial

Code

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;
}