You are here

function workspace_build_rows in Workspace 7

Same name and namespace in other branches
  1. 6 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 432
Presents a user-centric view of content.

Code

function workspace_build_rows($records, $account) {
  global $user;
  $yes = t('yes');
  $no = t('no');
  $use_icons = variable_get('workspace_use_icons', 1);
  $rows = array();
  foreach ($records as $row) {

    // 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;
      }
      $editlink = $use_icons ? _workspace_get_icon('edit', "node/" . $row->nid . "/edit", array(
        'title' => t('Edit'),
      )) : l(t('Edit'), "node/" . $row->nid . "/edit");
      $deletelink = $use_icons ? _workspace_get_icon('delete', "workspace/delete/" . $row->nid, array(
        'title' => t('Delete'),
      )) : l(t('Delete'), "workspace/delete/" . $row->nid);
      $viewlink = $use_icons ? _workspace_get_icon('view', "node/{$row->nid}", array(
        'title' => t('View'),
      )) : l($row->title, "node/{$row->nid}");
      $printstatus = $row->status ? t('Yes') : t('No');
      $iconstatus = $row->status ? 'active' : 'inactive';
      if (user_access('administer nodes', $account) || user_access('administer nodes', $user)) {
        $statuslink = $use_icons ? _workspace_get_icon($iconstatus, '', array(
          'title' => $printstatus,
          'onClick' => "Drupal.workspace_json_status_switch({$row->nid}, 'workspace/node/switch')",
          'class' => 'workspace_trig',
          'id' => "workspace_switch_{$row->nid}",
        )) : "<span onClick='Drupal.workspace_json_status_switch({$row->nid}, \"workspace/node/switch\")' class='workspace_trig' id='workspace_switch_{$row->nid}'>{$printstatus}</span>";
      }
      else {
        $statuslink = $use_icons ? _workspace_get_icon($iconstatus, '', array(
          'title' => $printstatus,
        )) : $printstatus;
      }
      if (module_exists('comment')) {
        $rows[] = array(
          node_type_get_name($row->type),
          l($row->title, "node/" . $row->nid),
          $statuslink,
          format_date($row->changed, variable_get('workspace_dateformat_default', 'medium')),
          array(
            'data' => $row->comment ? $row->comment_count ? $row->comment_count : 0 : t('N/A'),
            'align' => 'right',
          ),
          $viewlink,
          $may_edit ? $editlink : '',
          $may_delete ? $deletelink : '',
        );
      }
      else {
        $rows[] = array(
          node_type_get_name($row->type),
          l($row->title, "node/{$row->nid}"),
          $statuslink,
          format_date($row->changed, variable_get('workspace_dateformat_default', 'medium')),
          $viewlink,
          $may_edit ? $editlink : '',
          $may_delete ? $deletelink : '',
        );
      }
    }
    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 = $use_icons ? _workspace_get_icon('edit', "comment/edit/" . $comment->cid, array(
        'title' => t('Edit'),
      )) : l(t('Edit'), "comment/edit/" . $comment->cid);
      $edit_link = $comment_links['comment_edit'] ? $link : '';
      $link = $use_icons ? _workspace_get_icon('delete', "comment/delete/" . $comment->cid, array(
        'title' => t('Delete'),
      )) : l(t('Delete'), "comment/delete/" . $comment->cid);
      $delete_link = $comment_links['comment_delete'] ? $link : '';
      $printstatus = $row->status ? t('Yes') : t('No');
      $iconstatus = $row->status ? 'active' : 'inactive';
      $statuslink = $use_icons ? _workspace_get_icon($iconstatus, '', array(
        'title' => $printstatus,
      )) : $printstatus;
      $row_options = array(
        'attributes' => array(),
        'query' => NULL,
        'fragment' => "comment-{$row->cid}",
        'absolute' => FALSE,
        'html' => TRUE,
      );
      $node = node_load($row->nid);

      //Need to load node to get the content type
      if (module_exists('talk') and variable_get("comment_talk_{$node->type}", FALSE)) {
        $row_link = l($row->subject, "node/{$row->nid}/talk", $row_options);
      }
      else {
        $row_link = l($row->subject, "node/{$row->nid}", $row_options);
      }
      $rows[] = array(
        $row_link,
        $statuslink,
        format_date($row->timestamp, variable_get('workspace_dateformat_default', 'medium')),
        array(
          'data' => $num_replies,
          'align' => 'right',
        ),
        $edit_link,
        $delete_link,
      );
    }
  }
  return $rows;
}