You are here

function content_lock_overview in Content locking (anti-concurrent editing) 7

Same name and namespace in other branches
  1. 6.2 content_lock.module \content_lock_overview()
  2. 6 content_lock.module \content_lock_overview()
  3. 7.3 includes/content_lock.pages.inc \content_lock_overview()
  4. 7.2 content_lock.module \content_lock_overview()

Build an overview of locked documents.

Parameters

$account: A user object.

1 string reference to 'content_lock_overview'
content_lock_menu in ./content_lock.module
Implementation of hook_menu().

File

./content_lock.module, line 572
Allows users to lock documents for modification.

Code

function content_lock_overview($account = NULL) {
  global $user;

  // TODO: old checkout code, review
  $header = array(
    array(
      'data' => t('Title'),
      'field' => 'n.title',
      'sort' => 'asc',
    ),
  );

  // in the case of an admin, we dont have uid, as he sees all locks
  if (!$account) {
    $header[] = array(
      'data' => t('Username'),
      'field' => 'u.name',
    );
    $uid = NULL;
  }
  else {
    $uid = $account->uid;
  }
  $header[] = array(
    'data' => t('Locked since'),
    'field' => 'c.timestamp',
  );
  if ($uid == $user->uid || user_access('administer checked out documents')) {
    $header[] = t('Operations');
  }
  $query = db_select('content_lock', 'c')
    ->extend('TableSort')
    ->fields('c');
  $n = $query
    ->join('node', 'n', '%alias.nid = c.nid');
  $query
    ->fields($n, array(
    'title',
  ));
  $u = $query
    ->join('users', 'u', '%alias.uid = c.uid');
  $query
    ->fields($u, array(
    'name',
  ));
  if ($uid) {
    $query
      ->condition('c.uid', $uid);
  }
  $query
    ->orderByHeader($header);
  $rows = array();
  foreach ($query
    ->execute() as $data) {
    $url = $uid ? "admin/content/" . $data->nid . "/content_lock/releaseown" : 'admin/content/content_lock/release/' . $data->nid;
    $row = array();
    $row[] = l($data->title, "node/{$data->nid}");
    if (!$uid) {
      $row[] = theme('username', array(
        'account' => user_load($data->uid),
      ));
    }
    $row[] = format_date($data->timestamp, 'small');
    if ($uid == $user->uid || user_access('administer checked out documents')) {
      $row[] = l(t('release lock'), $url, array(
        'query' => array(
          'token' => content_lock_get_release_token($data->nid),
        ),
      ));
    }
    $rows[] = $row;
  }
  $output = theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'content_lock',
    ),
    'empty' => t('No locked documents.'),
  ));
  $output .= theme('pager', array(
    'quantity' => 50,
  ));
  return $output;
}