You are here

function content_lock_warn_pending_locks in Content locking (anti-concurrent editing) 7.2

Same name and namespace in other branches
  1. 6.2 content_lock.module \content_lock_warn_pending_locks()
  2. 6 content_lock.module \content_lock_warn_pending_locks()
  3. 7 content_lock.module \content_lock_warn_pending_locks()

Warn pending locks.

For every lock a user current have on any nodes, print a warning message with an link to release this node.

Parameters

int $uid: User ID.

1 call to content_lock_warn_pending_locks()
content_lock_node_view in ./content_lock.module
Implements hook_node_view().

File

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

Code

function content_lock_warn_pending_locks($uid) {

  // Cache.
  static $warned_nodes = array();
  static $content_lock_messages_printed = FALSE;
  if ($content_lock_messages_printed) {
    return;
  }
  if (array_key_exists($uid, $warned_nodes)) {

    // Placeholder.
  }
  else {

    // Load form db.
    $warned_nodes[$uid] = array();
    $query = db_select('content_lock', 'c')
      ->fields('c', array(
      'nid',
    ))
      ->condition('c.uid', $uid);
    $n = $query
      ->leftJoin('node', 'n', '%alias.nid = c.nid');
    $query
      ->fields($n, array(
      'title',
    ));
    foreach ($query
      ->execute() as $lock) {
      $warned_nodes[$uid][] = $lock;
    }
  }
  foreach ($warned_nodes[$uid] as $lock) {
    $nodetitle_link = l($lock->title, "node/{$lock->nid}");
    $token = content_lock_get_release_token($lock->nid);
    $releasethelock_link = l(t('release the lock'), "admin/content/{$lock->nid}/content_lock/releaseown", array(
      'query' => array(
        'token' => $token,
      ),
    ));
    _content_lock_save_lock_warning(t("The node '!nodetitle_link' is locked by you. You may want to '!releasethelock_link' in order to allow others to edit.", array(
      '!nodetitle_link' => $nodetitle_link,
      '!releasethelock_link' => $releasethelock_link,
    )), $lock->nid);
  }
  $content_lock_messages_printed = TRUE;
}