You are here

function node_limit_role_node_limit_sql in Node Limit 8

Same name and namespace in other branches
  1. 6 node_limit_role/node_limit_role.module \node_limit_role_node_limit_sql()
  2. 7 node_limit_role/node_limit_role.module \node_limit_role_node_limit_sql()

Implements hook_node_limit_sql().

File

old/node_limit_role/node_limit_role.module, line 47
Module to restrict the number of nodes by role.

Code

function node_limit_role_node_limit_sql($lid, SelectQuery $select) {
  $limit = node_limit_role_node_limit_load($lid);
  if (empty($limit)) {
    return;
  }
  if ($limit['node_limit_role']['rid'] == DRUPAL_ANONYMOUS_RID) {
    $select
      ->condition('uid', 0);
  }
  elseif ($limit['node_limit_role']['rid'] == DRUPAL_AUTHENTICATED_RID) {
    $select
      ->condition('uid', 0, '!=');
  }
  else {
    $subselect = \Drupal::database()
      ->select('users_roles', 'ur')
      ->fields('ur', array(
      'uid',
    ))
      ->condition('rid', $limit['node_limit_role']['rid']);
    $select
      ->condition('uid', $subselect, 'IN');
  }
}