You are here

function workspace_build_rows in Workspace 6

Same name and namespace in other branches
  1. 7 workspace.module \workspace_build_rows()

Build the query result into a table, respecting access.

Parameters

$result: A result object as returned from pager_query().

$account: User object representing user whose workspace is being listed.

2 calls to workspace_build_rows()
workspace_list_comments in ./workspace.module
Menu callback. Display list of comments.
workspace_list_content in ./workspace.module
Menu callback. Display list of content.

File

./workspace.module, line 315
Presents a user-centric view of content.

Code

function workspace_build_rows($result, $account) {
  global $user;
  $yes = t('yes');
  $no = t('no');
  $rows = array();
  while ($row = db_fetch_object($result)) {

    // It's a node.
    if ($row->node == 1) {

      // Edit and delete permissions are set by the node type's access hook.
      // If no access hook is found, node-level permissions are then used.
      // This approach is part of Drupal's core design.
      $may_edit = FALSE;
      $may_delete = FALSE;

      //Check the node type's access hook.
      $function = $row->type . '_access';
      if ($cck_enabled && strstr($function, 'content_')) {
        $function = 'content_access';
      }
      else {
        $function = 'node_access';
      }
      if (function_exists($function)) {
        if (!$function('view', $row, $user)) {

          // No view permission means it is not shown in the workspace.
          continue;
        }
        $may_edit = $function('update', $row, $user) ? TRUE : FALSE;
        $may_delete = $function('delete', $row, $user) ? TRUE : FALSE;
      }
      else {

        // If we can't find an access function, deny by default.
        continue;
      }

      // The name of the owner of this node.
      $name = $user->uid == $row->uid ? $user->name : db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $row->uid));
      $rows[] = array(
        node_get_types('name', $row->type),
        l($row->title, "node/{$row->nid}"),
        $name,
        $row->status ? $yes : $no,
        format_date($row->changed, 'small'),
        module_exists('comment') ? array(
          'data' => $row->comment_count ? $row->comment_count : 0,
          'align' => 'right',
        ) : array(
          'data' => '',
        ),
        $may_edit ? l(t('edit'), "node/{$row->nid}/edit") : '',
        $may_delete ? l(t('delete'), "workspace/delete/{$row->nid}") : '',
      );
    }
    else {

      // It's a comment.
      $num_replies = comment_num_replies($row->cid);
      $comment->cid = $row->cid;
      $comment->nid = $row->nid;

      // Delegate access permission checks and link generation to comment.module.
      $comment_links = comment_links($comment, 0);
      $link = l(t('edit'), "comment/edit/{$comment->cid}");
      $edit_link = $comment_links['comment_edit'] ? $link : '';
      $link = l(t('delete'), "comment/delete/{$comment->cid}");
      $delete_link = $comment_links['comment_delete'] ? $link : '';
      $rows[] = array(
        l($row->subject, "node/{$row->nid}", array(), NULL, "comment-{$row->cid}", FALSE, TRUE),
        $row->status ? $no : $yes,
        format_date($row->timestamp, 'small'),
        array(
          'data' => $num_replies,
          'align' => 'right',
        ),
        $edit_link,
        $delete_link,
      );
    }
  }
  return $rows;
}